Changeset 548 for branches/PublicaMundi_David-devel/thirds
- Timestamp:
- Feb 2, 2015, 9:55:48 AM (10 years ago)
- Location:
- branches/PublicaMundi_David-devel/thirds/cgic206
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PublicaMundi_David-devel/thirds/cgic206/Makefile
r346 r548 16 16 RANLIB=ranlib 17 17 18 all: libcgic.a cgictest.cgi capture18 all: libcgic.a 19 19 20 20 install: libcgic.a … … 31 31 #mingw32 and cygwin users: replace .cgi with .exe 32 32 33 cgictest.cgi: cgictest.o libcgic.a34 gcc cgictest.o -o cgictest.cgi ${LIBS}33 #cgictest.cgi: cgictest.o libcgic.a 34 # gcc cgictest.o -o cgictest.cgi ${LIBS} 35 35 36 capture: capture.o libcgic.a37 gcc capture.o -o capture ${LIBS}36 #capture: capture.o libcgic.a 37 # gcc capture.o -o capture ${LIBS} 38 38 39 39 clean: 40 rm -f *.o *.a cgictest.cgi capture40 rm -f *.o *.a #cgictest.cgi capture 41 41 -
branches/PublicaMundi_David-devel/thirds/cgic206/cgic.c
r511 r548 10 10 11 11 #include <fcgi_stdio.h> 12 12 13 #if CGICDEBUG 13 14 #define CGICDEBUGSTART \ … … 48 49 49 50 #define cgiStrEq(a, b) (!strcmp((a), (b))) 50 51 /** 51 52 char *cgiServerSoftware; 52 53 char *cgiServerName; … … 77 78 FILE *cgiOut; 78 79 80 **/ 81 79 82 /* True if CGI environment was restored from a file. */ 80 static int cgiRestored = 0;81 static int cgiTreatUrlEncoding;82 83 static void cgiGetenv(char **s, char *var);83 //static int cgiRestored = 0; 84 //static int cgiTreatUrlEncoding; 85 86 //static void cgiGetenv(char **s, char *var); 84 87 85 88 typedef enum { … … 97 100 VALUES. Make local copies if modifications are desired. */ 98 101 99 typedef struct cgiFormEntryStruct {100 char *attr;101 /* value is populated for regular form fields only.102 For file uploads, it points to an empty string, and file103 upload data should be read from the file tfileName. */104 char *value;105 /* When fileName is not an empty string, tfileName is not null,106 and 'value' points to an empty string. */107 /* Valid for both files and regular fields; does not include108 terminating null of regular fields. */109 int valueLength;110 char *fileName;111 char *contentType;112 /* Temporary file name for working storage of file uploads. */113 char *tfileName;114 struct cgiFormEntryStruct *next;115 } cgiFormEntry;116 102 117 103 /* The first form entry. */ 118 static cgiFormEntry *cgiFormEntryFirst;119 120 static cgiParseResultType cgiParseGetFormInput( );121 static cgiParseResultType cgiParsePostFormInput( );122 static cgiParseResultType cgiParsePostMultipartInput( );123 static cgiParseResultType cgiParseFormInput(char *data, int length );104 //static cgiFormEntry *cgiFormEntryFirst; 105 106 static cgiParseResultType cgiParseGetFormInput(struct cgi_env ** ce); 107 static cgiParseResultType cgiParsePostFormInput(struct cgi_env ** ce, FCGX_Stream *in); 108 static cgiParseResultType cgiParsePostMultipartInput(struct cgi_env **cet, FCGX_Stream *in); 109 static cgiParseResultType cgiParseFormInput(char *data, int length,struct cgi_env ** ce); 124 110 static void cgiSetupConstants(); 125 111 void cgiFreeResources(); … … 130 116 131 117 132 int cgiMain_init(int argc, char *argv[]) { 133 int result; 118 int cgiMain_init(int argc, char *argv[],struct cgi_env ** c,FCGX_Request *request) { 119 struct cgi_env * cgi = * c; 120 cgi->cgiFindTarget = 0; 121 cgi->cgiFindPos = 0; 122 123 cgi->cgiContentType = cgi->cgiContentTypeData; 124 cgi->cgiRestored = 0; 125 int result = 0; 134 126 char *cgiContentLengthString; 135 127 char *e; 136 128 cgiSetupConstants(); 137 cgiGetenv(&cgiServerSoftware, "SERVER_SOFTWARE");138 cgi Getenv(&cgiServerName, "SERVER_NAME");139 cgiGetenv(&cgiGatewayInterface, "GATEWAY_INTERFACE");140 cgiGetenv(&cgiServerProtocol, "SERVER_PROTOCOL");141 cgiGetenv(&cgiServerPort, "SERVER_PORT");142 cgiGetenv(&cgiRequestMethod, "REQUEST_METHOD");143 if(strcmp(cgi RequestMethod,"")==0 && argc>=1)144 cgi RequestMethod="GET";145 cgiGetenv(&cgiPathInfo, "PATH_INFO");146 cgi Getenv(&cgiPathTranslated, "PATH_TRANSLATED");147 cgi Getenv(&cgiScriptName, "SCRIPT_NAME");148 cgi Getenv(&cgiQueryString, "QUERY_STRING");149 cgi Sid=NULL;150 if(cgi QueryString!=NULL && argc>=2){151 cgi QueryString=argv[1];129 cgi->cgiServerSoftware = FCGX_GetParam("SERVER_SOFTWARE",request->envp); 130 cgi->cgiServerName = FCGX_GetParam("SERVER_NAME",request->envp); 131 cgi->cgiGatewayInterface = FCGX_GetParam("GATEWAY_INTERFACE",request->envp); 132 cgi->cgiServerProtocol = FCGX_GetParam("SERVER_PROTOCOL",request->envp); 133 cgi->cgiServerPort = FCGX_GetParam("SERVER_PORT",request->envp); 134 cgi->cgiRequestMethod = FCGX_GetParam("REQUEST_METHOD",request->envp); 135 if(strcmp(cgi->cgiRequestMethod,"")==0 && argc>=1) 136 cgi->cgiRequestMethod="GET"; 137 cgi->cgiPathInfo = FCGX_GetParam("PATH_INFO",request->envp); 138 cgi->cgiPathTranslated = FCGX_GetParam("PATH_TRANSLATED",request->envp); 139 cgi->cgiScriptName = FCGX_GetParam("SCRIPT_NAME",request->envp); 140 cgi->cgiQueryString = FCGX_GetParam("QUERY_STRING",request->envp); 141 cgi->cgiSid=NULL; 142 if(cgi->cgiQueryString!=NULL && argc>=2){ 143 cgi->cgiQueryString=argv[1]; 152 144 if(argc>2){ 153 cgiSid=argv[2]; 154 } 155 } 156 cgiGetenv(&cgiRemoteHost, "REMOTE_HOST"); 157 cgiGetenv(&cgiRemoteAddr, "REMOTE_ADDR"); 158 cgiGetenv(&cgiAuthType, "AUTH_TYPE"); 159 cgiGetenv(&cgiRemoteUser, "REMOTE_USER"); 160 cgiGetenv(&cgiRemoteIdent, "REMOTE_IDENT"); 145 cgi->cgiSid=argv[2]; 146 } 147 } 148 cgi->cgiRemoteHost = FCGX_GetParam("REMOTE_HOST",request->envp); 149 cgi->cgiRemoteAddr = FCGX_GetParam("REMOTE_ADDR",request->envp); 150 cgi->cgiAuthType = FCGX_GetParam("AUTH_TYPE",request->envp); 151 cgi->cgiRemoteUser = FCGX_GetParam("REMOTE_USER",request->envp); 152 cgi->cgiRemoteIdent = FCGX_GetParam("REMOTE_IDENT",request->envp); 153 //cgiGetenv(&cgiRemoteIdent, "REMOTE_IDENT"); 161 154 /* 2.0: the content type string needs to be parsed and modified, so 162 155 copy it to a buffer. */ 163 e = getenv("CONTENT_TYPE"); 164 if (e) { 165 if (strlen(e) < sizeof(cgiContentTypeData)) { 166 strcpy(cgiContentType, e); 156 //e = getenv("CONTENT_TYPE"); 157 e = FCGX_GetParam("CONTENT_TYPE",request->envp); 158 if (e) { 159 if (strlen(e) < sizeof(cgi->cgiContentTypeData)) { 160 strcpy(cgi->cgiContentType, e); 167 161 } else { 168 162 /* Truncate safely in the event of what is almost certainly 169 163 a hack attempt */ 170 strncpy(cgi ContentType, e, sizeof(cgiContentTypeData));171 cgi ContentType[sizeof(cgiContentTypeData) - 1] = '\0';164 strncpy(cgi->cgiContentType, e, sizeof(cgi->cgiContentTypeData)); 165 cgi->cgiContentType[sizeof(cgi->cgiContentTypeData) - 1] = '\0'; 172 166 } 173 167 } else { 174 cgi ContentType[0] = '\0';168 cgi->cgiContentType[0] = '\0'; 175 169 } 176 170 /* Never null */ 177 cgi MultipartBoundary = "";171 cgi->cgiMultipartBoundary = ""; 178 172 /* 2.0: parse semicolon-separated additional parameters of the 179 173 content type. The one we're interested in is 'boundary'. 180 174 We discard the rest to make cgiContentType more useful 181 175 to the typical programmer. */ 182 if (strchr(cgi ContentType, ';')) {183 char *sat = strchr(cgi ContentType, ';');176 if (strchr(cgi->cgiContentType, ';')) { 177 char *sat = strchr(cgi->cgiContentType, ';'); 184 178 while (sat) { 185 179 *sat = '\0'; … … 190 184 if (cgiStrBeginsNc(sat, "boundary=")) { 191 185 char *s; 192 cgi MultipartBoundary = sat + strlen("boundary=");193 s = cgi MultipartBoundary;186 cgi->cgiMultipartBoundary = sat + strlen("boundary="); 187 s = cgi->cgiMultipartBoundary; 194 188 while ((*s) && (!isspace(*s))) { 195 189 s++; … … 202 196 } 203 197 } 204 cgiGetenv(&cgiContentLengthString, "CONTENT_LENGTH"); 205 cgiContentLength = atoi(cgiContentLengthString); 206 if(cgiContentLength==0 && argc>=2){ 207 cgiContentLength=strlen(argv[1]); 208 } 209 cgiGetenv(&cgiAccept, "HTTP_ACCEPT"); 210 cgiGetenv(&cgiUserAgent, "HTTP_USER_AGENT"); 211 cgiGetenv(&cgiReferrer, "HTTP_REFERER"); 212 cgiGetenv(&cgiCookie, "HTTP_COOKIE"); 213 #ifdef CGICDEBUG 214 CGICDEBUGSTART 215 fprintf(dout, "%d\n", cgiContentLength); 216 fprintf(dout, "%s\n", cgiRequestMethod); 217 fprintf(dout, "%s\n", cgiContentType); 218 CGICDEBUGEND 219 #endif /* CGICDEBUG */ 198 199 cgiContentLengthString = FCGX_GetParam("CONTENT_LENGTH",request->envp); 200 if (cgiContentLengthString != NULL) 201 cgi->cgiContentLength = strtol(cgiContentLengthString,NULL,10); 202 else 203 cgi->cgiContentLength = 0; 204 if(cgi->cgiContentLength==0 && argc>=2){ 205 cgi->cgiContentLength=strlen(argv[1]); 206 } 207 cgi->cgiAccept = FCGX_GetParam("HTTP_ACCEPT",request->envp); 208 cgi->cgiUserAgent = FCGX_GetParam("HTTP_USER_AGENT",request->envp); 209 cgi->cgiReferrer = FCGX_GetParam("HTTP_REFERER",request->envp); 210 cgi->cgiCookie = FCGX_GetParam("HTTP_COOKIE",request->envp); 220 211 #ifdef WIN32 221 212 /* 1.07: Must set stdin and stdout to binary mode */ … … 224 215 _setmode( FCGI_fileno( stdout ), _O_BINARY ); 225 216 #endif /* WIN32 */ 226 cgi FormEntryFirst = 0;227 cgiIn = FCGI_stdin;228 cgiOut = FCGI_stdout;229 cgiRestored = 0;217 cgi->cgiFormEntryFirst = 0; 218 //cgiIn = FCGI_stdin; 219 //cgiOut = FCGI_stdout; 220 //cgiRestored = 0; 230 221 231 222 … … 235 226 if (argc) { 236 227 if (argv[0]) { 237 cgi Restored = 0;228 cgi->cgiRestored = 0; 238 229 } 239 230 } 240 231 241 232 242 cgi TreatUrlEncoding=0;243 if (cgiStrEqNc(cgi RequestMethod, "post")) {244 cgi TreatUrlEncoding=0;233 cgi->cgiTreatUrlEncoding=0; 234 if (cgiStrEqNc(cgi->cgiRequestMethod, "post")) { 235 cgi->cgiTreatUrlEncoding=0; 245 236 #ifdef CGICDEBUG 246 237 CGICDEBUGSTART … … 248 239 CGICDEBUGEND 249 240 #endif /* CGICDEBUG */ 250 if (cgiStrEqNc(cgi ContentType, "application/x-www-form-urlencoded")) {241 if (cgiStrEqNc(cgi->cgiContentType, "application/x-www-form-urlencoded")) { 251 242 #ifdef CGICDEBUG 252 243 CGICDEBUGSTART … … 254 245 CGICDEBUGEND 255 246 #endif /* CGICDEBUG */ 256 if (cgiParsePostFormInput( ) != cgiParseSuccess) {247 if (cgiParsePostFormInput(&cgi,request->in) != cgiParseSuccess) { 257 248 #ifdef CGICDEBUG 258 249 CGICDEBUGSTART … … 260 251 CGICDEBUGEND 261 252 #endif /* CGICDEBUG */ 262 cgiFreeResources( );253 cgiFreeResources(&cgi); 263 254 return -1; 264 255 } … … 268 259 CGICDEBUGEND 269 260 #endif /* CGICDEBUG */ 270 } else if (cgiStrEqNc(cgi ContentType, "multipart/form-data")) {261 } else if (cgiStrEqNc(cgi->cgiContentType, "multipart/form-data")) { 271 262 #ifdef CGICDEBUG 272 263 CGICDEBUGSTART … … 274 265 CGICDEBUGEND 275 266 #endif /* CGICDEBUG */ 276 if (cgiParsePostMultipartInput( ) != cgiParseSuccess) {267 if (cgiParsePostMultipartInput(&cgi,request->in) != cgiParseSuccess) { 277 268 #ifdef CGICDEBUG 278 269 CGICDEBUGSTART … … 280 271 CGICDEBUGEND 281 272 #endif /* CGICDEBUG */ 282 cgiFreeResources( );273 cgiFreeResources(&cgi); 283 274 return -1; 284 275 } … … 289 280 #endif /* CGICDEBUG */ 290 281 } 291 } else if (cgiStrEqNc(cgi RequestMethod, "get")) {282 } else if (cgiStrEqNc(cgi->cgiRequestMethod, "get")) { 292 283 /* The spec says this should be taken care of by 293 284 the server, but... it isn't */ 294 cgi ContentLength = strlen(cgiQueryString);295 if (cgiParseGetFormInput( ) != cgiParseSuccess) {285 cgi->cgiContentLength = strlen(cgi->cgiQueryString); 286 if (cgiParseGetFormInput(&cgi) != cgiParseSuccess) { 296 287 #ifdef CGICDEBUG 297 288 CGICDEBUGSTART … … 299 290 CGICDEBUGEND 300 291 #endif /* CGICDEBUG */ 301 cgiFreeResources( );292 cgiFreeResources(&cgi); 302 293 return -1; 303 294 } else { … … 311 302 return result; 312 303 } 313 304 /** 314 305 static void cgiGetenv(char **s, char *var){ 315 306 *s = getenv(var); … … 318 309 } 319 310 } 320 321 static cgiParseResultType cgiParsePostFormInput() { 311 **/ 312 static cgiParseResultType cgiParsePostFormInput(struct cgi_env **ce, FCGX_Stream *in) { 313 struct cgi_env * cgi = *ce; 322 314 char *input; 323 315 cgiParseResultType result; 324 if (!cgi ContentLength) {316 if (!cgi->cgiContentLength) { 325 317 return cgiParseSuccess; 326 318 } 327 input = (char *) malloc(cgi ContentLength);319 input = (char *) malloc(cgi->cgiContentLength); 328 320 if (!input) { 329 321 return cgiParseMemory; 330 322 } 331 if (((int) fread(input, 1, cgiContentLength, cgiIn))332 != cgiContentLength)323 //if (((int) fread(input, 1, cgiContentLength, cgiIn)) != cgiContentLength) 324 if (((int) FCGX_GetStr (input, cgi->cgiContentLength, in)) != cgi->cgiContentLength) 333 325 { 334 326 return cgiParseIO; 335 327 } 336 result = cgiParseFormInput(input, cgiContentLength);328 result = cgiParseFormInput(input,cgi->cgiContentLength,&cgi); 337 329 free(input); 338 330 return result; … … 361 353 } mpStream, *mpStreamPtr; 362 354 363 int mpRead(mpStreamPtr mpp, char *buffer, int len )355 int mpRead(mpStreamPtr mpp, char *buffer, int len, int cgiContentLength,FCGX_Stream *in) 364 356 { 365 357 int ilen = len; … … 381 373 } 382 374 if (len) { 383 int fgot = fread(buffer, 1, len, cgiIn); 375 int fgot = FCGX_GetStr(buffer,len,in); 376 //int fgot = fread(buffer, 1, len, cgiIn); 384 377 if (fgot >= 0) { 385 378 mpp->offset += (got + fgot); … … 430 423 char **outP, 431 424 int *bodyLengthP, 432 int first 425 int first, 426 int cgiContentLength, 427 FCGX_Stream *in, 428 char * cgiMultipartBoundary 433 429 ); 434 430 … … 438 434 int attrSpace, 439 435 char *value, 440 int valueSpace); 436 int valueSpace, 437 int cgiContentLength, 438 FCGX_Stream *in); 441 439 442 440 static void decomposeValue(char *value, … … 454 452 static cgiParseResultType getTempFileName(char *tfileName); 455 453 456 static cgiParseResultType cgiParsePostMultipartInput() { 457 cgiParseResultType result; 454 static cgiParseResultType cgiParsePostMultipartInput(struct cgi_env ** ce,FCGX_Stream * in) { 455 struct cgi_env * cgi = *ce; 456 cgiParseResultType result; 458 457 cgiFormEntry *n = 0, *l = 0; 459 458 int got; … … 464 463 mpStreamPtr mpp = ∓ 465 464 memset(&mp, 0, sizeof(mp)); 466 if (!cgi ContentLength) {465 if (!cgi->cgiContentLength) { 467 466 return cgiParseSuccess; 468 467 } 469 468 /* Read first boundary, including trailing newline */ 470 result = afterNextBoundary(mpp, 0, 0, 0, 1 );469 result = afterNextBoundary(mpp, 0, 0, 0, 1,cgi->cgiContentLength,in,cgi->cgiMultipartBoundary); 471 470 if (result == cgiParseIO) { 472 471 /* An empty submission is not necessarily an error */ … … 491 490 outf = 0; 492 491 /* Check for EOF */ 493 got = mpRead(mpp, d, 2 );492 got = mpRead(mpp, d, 2,cgi->cgiContentLength,in); 494 493 if (got < 2) { 495 494 /* Crude EOF */ … … 503 502 /* Read header lines until end of header */ 504 503 while (readHeaderLine( 505 mpp, attr, sizeof(attr), value, sizeof(value) ))504 mpp, attr, sizeof(attr), value, sizeof(value),cgi->cgiContentLength,in)) 506 505 { 507 506 char *argNames[3]; … … 548 547 tfileName[0] = '\0'; 549 548 } 550 result = afterNextBoundary(mpp, outf, &out, &bodyLength, 0 );549 result = afterNextBoundary(mpp, outf, &out, &bodyLength, 0,cgi->cgiContentLength,in,cgi->cgiMultipartBoundary); 551 550 if (result != cgiParseSuccess) { 552 551 /* Lack of a boundary here is an error. */ … … 587 586 n->next = 0; 588 587 if (!l) { 589 cgi FormEntryFirst = n;588 cgi->cgiFormEntryFirst = n; 590 589 } else { 591 590 l->next = n; … … 704 703 705 704 cgiParseResultType afterNextBoundary(mpStreamPtr mpp, FILE *outf, char **outP, 706 int *bodyLengthP, int first )705 int *bodyLengthP, int first,int cgiContentLength,FCGX_Stream *in,char *cgiMultipartBoundary) 707 706 { 708 707 int outLen = 0; … … 733 732 workingBoundaryLength = strlen(workingBoundary); 734 733 while (1) { 735 got = mpRead(mpp, d, 1 );734 got = mpRead(mpp, d, 1,cgiContentLength,in); 736 735 if (got != 1) { 737 736 /* 2.01: cgiParseIO, not cgiFormIO */ … … 768 767 /* Read trailing newline or -- EOF marker. A literal EOF here 769 768 would be an error in the input stream. */ 770 got = mpRead(mpp, d, 2 );769 got = mpRead(mpp, d, 2,cgiContentLength,in); 771 770 if (got != 2) { 772 771 result = cgiParseIO; … … 929 928 int attrSpace, 930 929 char *value, 931 int valueSpace) 930 int valueSpace, 931 int cgiContentLength, 932 FCGX_Stream *in) 932 933 { 933 934 int attrLen = 0; … … 936 937 while (1) { 937 938 char d[1]; 938 int got = mpRead(mpp, d, 1 );939 int got = mpRead(mpp, d, 1,cgiContentLength,in); 939 940 if (got != 1) { 940 941 return 0; 941 942 } 942 943 if (d[0] == '\r') { 943 got = mpRead(mpp, d, 1 );944 got = mpRead(mpp, d, 1,cgiContentLength,in); 944 945 if (got == 1) { 945 946 if (d[0] == '\n') { … … 954 955 } else if ((d[0] == ':') && attrLen) { 955 956 valueFound = 1; 956 while (mpRead(mpp, d, 1 ) == 1) {957 while (mpRead(mpp, d, 1,cgiContentLength,in) == 1) { 957 958 if (!isspace(d[0])) { 958 959 mpPutBack(mpp, d, 1); … … 985 986 } 986 987 987 static cgiParseResultType cgiParseGetFormInput() { 988 return cgiParseFormInput(cgiQueryString, cgiContentLength); 988 static cgiParseResultType cgiParseGetFormInput(struct cgi_env ** ce) { 989 struct cgi_env * cgi = *ce; 990 return cgiParseFormInput(cgi->cgiQueryString, cgi->cgiContentLength,ce); 989 991 } 990 992 … … 1000 1002 } cgiUnescapeResultType; 1001 1003 1002 static cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len );1003 1004 static cgiParseResultType cgiParseFormInput(char *data, int length ) {1004 static cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len,int cgiTreatUrlEncoding); 1005 1006 static cgiParseResultType cgiParseFormInput(char *data, int length,struct cgi_env ** ce) { 1005 1007 /* Scan for pairs, unescaping and storing them as they are found. */ 1008 struct cgi_env * cgi = *ce; 1006 1009 int pos = 0; 1007 1010 cgiFormEntry *n; … … 1026 1029 break; 1027 1030 } 1028 if (cgiUnescapeChars(&attr, data+start, len )1031 if (cgiUnescapeChars(&attr, data+start, len,cgi->cgiTreatUrlEncoding) 1029 1032 != cgiUnescapeSuccess) { 1030 1033 return cgiParseMemory; … … 1043 1046 /* The last pair probably won't be followed by a &, but 1044 1047 that's fine, so check for that after accepting it */ 1045 if (cgiUnescapeChars(&value, data+start, len )1048 if (cgiUnescapeChars(&value, data+start, len, cgi->cgiTreatUrlEncoding) 1046 1049 != cgiUnescapeSuccess) { 1047 1050 free(attr); … … 1087 1090 n->next = 0; 1088 1091 if (!l) { 1089 cgi FormEntryFirst = n;1092 cgi->cgiFormEntryFirst = n; 1090 1093 } else { 1091 1094 l->next = n; … … 1101 1104 static int cgiHexValue[256]; 1102 1105 1103 cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len ) {1106 cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len,int cgiTreatUrlEncoding ) { 1104 1107 char *s; 1105 1108 cgiEscapeState escapeState = cgiEscapeRest; … … 1172 1175 } 1173 1176 1174 void cgiFreeResources() { 1175 cgiFormEntry *c = cgiFormEntryFirst; 1177 void cgiFreeResources(struct cgi_env **cgi) { 1178 struct cgi_env * cc = *cgi; 1179 cgiFormEntry *c = cc->cgiFormEntryFirst; 1176 1180 cgiFormEntry *n; 1177 1181 while (c) { … … 1190 1194 /* If the cgi environment was restored from a saved environment, 1191 1195 then these are in allocated space and must also be freed */ 1192 if (cgiRestored) { 1193 free(cgiServerSoftware); 1194 free(cgiServerName); 1195 free(cgiGatewayInterface); 1196 free(cgiServerProtocol); 1197 free(cgiServerPort); 1198 free(cgiRequestMethod); 1199 free(cgiPathInfo); 1200 free(cgiPathTranslated); 1201 free(cgiScriptName); 1202 free(cgiQueryString); 1203 free(cgiRemoteHost); 1204 free(cgiRemoteAddr); 1205 free(cgiAuthType); 1206 free(cgiRemoteUser); 1207 free(cgiRemoteIdent); 1208 free(cgiContentType); 1209 free(cgiAccept); 1210 free(cgiUserAgent); 1211 free(cgiReferrer); 1212 } 1196 /** 1197 if (cc->cgiRestored) { 1198 free(cc->cgiServerSoftware); 1199 free(cc->cgiServerName); 1200 free(cc->cgiGatewayInterface); 1201 free(cc->cgiServerProtocol); 1202 free(cc->cgiServerPort); 1203 free(cc->cgiRequestMethod); 1204 free(cc->cgiPathInfo); 1205 free(cc->cgiPathTranslated); 1206 free(cc->cgiScriptName); 1207 free(cc->cgiQueryString); 1208 free(cc->cgiRemoteHost); 1209 free(cc->cgiRemoteAddr); 1210 free(cc->cgiAuthType); 1211 free(cc->cgiRemoteUser); 1212 free(cc->cgiRemoteIdent); 1213 free(cc->cgiContentType); 1214 free(cc->cgiAccept); 1215 free(cc->cgiUserAgent); 1216 free(cc->cgiReferrer); 1217 } 1218 **/ 1213 1219 /* 2.0: to clean up the environment for cgiReadEnvironment, 1214 1220 we must set these correctly */ 1215 c giFormEntryFirst = 0;1216 c giRestored = 0;1221 cc->cgiFormEntryFirst = 0; 1222 cc->cgiRestored = 0; 1217 1223 } 1218 1224 … … 1220 1226 cgiFormEntry *e, char *result, int max, int newlines); 1221 1227 1222 static cgiFormEntry *cgiFormEntryFindFirst(char *name );1223 static cgiFormEntry *cgiFormEntryFindNext( );1228 static cgiFormEntry *cgiFormEntryFindFirst(char *name, struct cgi_env ** ce); 1229 static cgiFormEntry *cgiFormEntryFindNext(struct cgi_env ** ce); 1224 1230 1225 1231 cgiFormResultType cgiFormString( 1226 char *name, char *result, int max ) {1232 char *name, char *result, int max,struct cgi_env ** ce) { 1227 1233 cgiFormEntry *e; 1228 e = cgiFormEntryFindFirst(name );1234 e = cgiFormEntryFindFirst(name,ce); 1229 1235 if (!e) { 1230 1236 strcpy(result, ""); … … 1235 1241 1236 1242 cgiFormResultType cgiFormFileName( 1237 char *name, char *result, int resultSpace )1243 char *name, char *result, int resultSpace,struct cgi_env ** ce) 1238 1244 { 1239 1245 cgiFormEntry *e; 1240 1246 int resultLen = 0; 1241 1247 char *s; 1242 e = cgiFormEntryFindFirst(name );1248 e = cgiFormEntryFindFirst(name,ce); 1243 1249 if (!e) { 1244 1250 strcpy(result, ""); … … 1263 1269 1264 1270 cgiFormResultType cgiFormFileContentType( 1265 char *name, char *result, int resultSpace )1271 char *name, char *result, int resultSpace,struct cgi_env ** ce) 1266 1272 { 1267 1273 cgiFormEntry *e; 1268 1274 int resultLen = 0; 1269 1275 char *s; 1270 e = cgiFormEntryFindFirst(name );1276 e = cgiFormEntryFindFirst(name,ce); 1271 1277 if (!e) { 1272 1278 if (resultSpace) { … … 1293 1299 1294 1300 cgiFormResultType cgiFormFileSize( 1295 char *name, int *sizeP )1301 char *name, int *sizeP,struct cgi_env ** ce) 1296 1302 { 1297 1303 cgiFormEntry *e; 1298 e = cgiFormEntryFindFirst(name );1304 e = cgiFormEntryFindFirst(name,ce); 1299 1305 if (!e) { 1300 1306 if (sizeP) { … … 1320 1326 1321 1327 cgiFormResultType cgiFormFileOpen( 1322 char *name, cgiFilePtr *cfpp )1328 char *name, cgiFilePtr *cfpp,struct cgi_env ** ce) 1323 1329 { 1324 1330 cgiFormEntry *e; 1325 1331 cgiFilePtr cfp; 1326 e = cgiFormEntryFindFirst(name );1332 e = cgiFormEntryFindFirst(name,ce); 1327 1333 if (!e) { 1328 1334 *cfpp = 0; … … 1374 1380 1375 1381 cgiFormResultType cgiFormStringNoNewlines( 1376 char *name, char *result, int max ) {1382 char *name, char *result, int max,struct cgi_env ** ce) { 1377 1383 cgiFormEntry *e; 1378 e = cgiFormEntryFindFirst(name );1384 e = cgiFormEntryFindFirst(name,ce); 1379 1385 if (!e) { 1380 1386 strcpy(result, ""); … … 1385 1391 1386 1392 cgiFormResultType cgiFormStringMultiple( 1387 char *name, char ***result ) {1393 char *name, char ***result,struct cgi_env ** ce) { 1388 1394 char **stringArray; 1389 1395 cgiFormEntry *e; … … 1393 1399 function is not commonly used. The select menu and 1394 1400 radio box functions are faster. */ 1395 e = cgiFormEntryFindFirst(name );1401 e = cgiFormEntryFindFirst(name,ce); 1396 1402 if (e != 0) { 1397 1403 do { 1398 1404 total++; 1399 } while ((e = cgiFormEntryFindNext( )) != 0);1405 } while ((e = cgiFormEntryFindNext(ce)) != 0); 1400 1406 } 1401 1407 stringArray = (char **) malloc(sizeof(char *) * (total + 1)); … … 1409 1415 } 1410 1416 /* Now go get the entries */ 1411 e = cgiFormEntryFindFirst(name );1417 e = cgiFormEntryFindFirst(name,ce); 1412 1418 #ifdef CGICDEBUG 1413 1419 CGICDEBUGSTART … … 1429 1435 cgiFormEntryString(e, stringArray[i], max, 1); 1430 1436 i++; 1431 } while ((e = cgiFormEntryFindNext( )) != 0);1437 } while ((e = cgiFormEntryFindNext(ce)) != 0); 1432 1438 *result = stringArray; 1433 1439 #ifdef CGICDEBUG … … 1449 1455 1450 1456 cgiFormResultType cgiFormStringSpaceNeeded( 1451 char *name, int *result ) {1457 char *name, int *result,struct cgi_env ** ce) { 1452 1458 cgiFormEntry *e; 1453 e = cgiFormEntryFindFirst(name );1459 e = cgiFormEntryFindFirst(name,ce); 1454 1460 if (!e) { 1455 1461 *result = 1; … … 1543 1549 1544 1550 cgiFormResultType cgiFormInteger( 1545 char *name, int *result, int defaultV ) {1551 char *name, int *result, int defaultV,struct cgi_env ** ce) { 1546 1552 cgiFormEntry *e; 1547 1553 int ch; 1548 e = cgiFormEntryFindFirst(name );1554 e = cgiFormEntryFindFirst(name,ce); 1549 1555 if (!e) { 1550 1556 *result = defaultV; … … 1566 1572 1567 1573 cgiFormResultType cgiFormIntegerBounded( 1568 char *name, int *result, int min, int max, int defaultV ) {1569 cgiFormResultType error = cgiFormInteger(name, result, defaultV );1574 char *name, int *result, int min, int max, int defaultV,struct cgi_env ** ce) { 1575 cgiFormResultType error = cgiFormInteger(name, result, defaultV,ce); 1570 1576 if (error != cgiFormSuccess) { 1571 1577 return error; … … 1583 1589 1584 1590 cgiFormResultType cgiFormDouble( 1585 char *name, double *result, double defaultV ) {1591 char *name, double *result, double defaultV,struct cgi_env ** ce) { 1586 1592 cgiFormEntry *e; 1587 1593 int ch; 1588 e = cgiFormEntryFindFirst(name );1594 e = cgiFormEntryFindFirst(name,ce); 1589 1595 if (!e) { 1590 1596 *result = defaultV; … … 1606 1612 1607 1613 cgiFormResultType cgiFormDoubleBounded( 1608 char *name, double *result, double min, double max, double defaultV ) {1609 cgiFormResultType error = cgiFormDouble(name, result, defaultV );1614 char *name, double *result, double min, double max, double defaultV,struct cgi_env ** ce) { 1615 cgiFormResultType error = cgiFormDouble(name, result, defaultV,ce); 1610 1616 if (error != cgiFormSuccess) { 1611 1617 return error; … … 1624 1630 cgiFormResultType cgiFormSelectSingle( 1625 1631 char *name, char **choicesText, int choicesTotal, 1626 int *result, int defaultV )1632 int *result, int defaultV,struct cgi_env ** ce) 1627 1633 { 1628 1634 cgiFormEntry *e; 1629 1635 int i; 1630 e = cgiFormEntryFindFirst(name );1636 e = cgiFormEntryFindFirst(name,ce); 1631 1637 #ifdef CGICDEBUG 1632 1638 CGICDEBUGSTART … … 1660 1666 cgiFormResultType cgiFormSelectMultiple( 1661 1667 char *name, char **choicesText, int choicesTotal, 1662 int *result, int *invalid )1668 int *result, int *invalid,struct cgi_env ** ce) 1663 1669 { 1664 1670 cgiFormEntry *e; … … 1669 1675 result[i] = 0; 1670 1676 } 1671 e = cgiFormEntryFindFirst(name );1677 e = cgiFormEntryFindFirst(name,ce); 1672 1678 if (!e) { 1673 1679 *invalid = invalidE; … … 1687 1693 invalidE++; 1688 1694 } 1689 } while ((e = cgiFormEntryFindNext( )) != 0);1695 } while ((e = cgiFormEntryFindNext(ce)) != 0); 1690 1696 1691 1697 *invalid = invalidE; … … 1699 1705 1700 1706 cgiFormResultType cgiFormCheckboxSingle( 1701 char *name )1707 char *name,struct cgi_env ** ce) 1702 1708 { 1703 1709 cgiFormEntry *e; 1704 e = cgiFormEntryFindFirst(name );1710 e = cgiFormEntryFindFirst(name,ce); 1705 1711 if (!e) { 1706 1712 return cgiFormNotFound; … … 1711 1717 extern cgiFormResultType cgiFormCheckboxMultiple( 1712 1718 char *name, char **valuesText, int valuesTotal, 1713 int *result, int *invalid )1719 int *result, int *invalid,struct cgi_env ** ce) 1714 1720 { 1715 1721 /* Implementation is identical to cgiFormSelectMultiple. */ 1716 1722 return cgiFormSelectMultiple(name, valuesText, 1717 valuesTotal, result, invalid );1723 valuesTotal, result, invalid,ce); 1718 1724 } 1719 1725 1720 1726 cgiFormResultType cgiFormRadio( 1721 1727 char *name, 1722 char **valuesText, int valuesTotal, int *result, int defaultV )1728 char **valuesText, int valuesTotal, int *result, int defaultV,struct cgi_env **ce) 1723 1729 { 1724 1730 /* Implementation is identical to cgiFormSelectSingle. */ 1725 1731 return cgiFormSelectSingle(name, valuesText, valuesTotal, 1726 result, defaultV );1732 result, defaultV,ce); 1727 1733 } 1728 1734 … … 1730 1736 char *name, 1731 1737 char *value, 1732 int space) 1738 int space, 1739 char * cgiCookie) 1733 1740 { 1734 1741 char *p = cgiCookie; … … 1803 1810 char *name, 1804 1811 int *result, 1805 int defaultV) 1812 int defaultV, 1813 char * cgiCookie) 1806 1814 { 1807 1815 char buffer[256]; 1808 1816 cgiFormResultType r = 1809 cgiCookieString(name, buffer, sizeof(buffer) );1817 cgiCookieString(name, buffer, sizeof(buffer),cgiCookie); 1810 1818 if (r != cgiFormSuccess) { 1811 1819 *result = defaultV; … … 1817 1825 1818 1826 void cgiHeaderCookieSetInteger(char *name, int value, int secondsToLive, 1819 char *path, char *domain )1827 char *path, char *domain,FCGX_Stream * out) 1820 1828 { 1821 1829 char svalue[256]; 1822 1830 sprintf(svalue, "%d", value); 1823 cgiHeaderCookieSetString(name, svalue, secondsToLive, path, domain );1831 cgiHeaderCookieSetString(name, svalue, secondsToLive, path, domain,out); 1824 1832 } 1825 1833 … … 1850 1858 1851 1859 void cgiHeaderCookieSetString(char *name, char *value, int secondsToLive, 1852 char *path, char *domain )1860 char *path, char *domain,FCGX_Stream * out) 1853 1861 { 1854 1862 /* cgic 2.02: simpler and more widely compatible implementation. … … 1868 1876 then = now + secondsToLive; 1869 1877 gt = gmtime(&then); 1870 fprintf(cgiOut,1878 FCGX_FPrintF(out, 1871 1879 "Set-Cookie: %s=%s; domain=%s; expires=%s, %02d-%s-%04d %02d:%02d:%02d GMT; path=%s\r\n", 1872 1880 name, value, domain, … … 1881 1889 } 1882 1890 1883 void cgiHeaderLocation(char *redirectUrl ) {1884 fprintf(cgiOut, "Location: %s\r\n\r\n", redirectUrl);1885 } 1886 1887 void cgiHeaderStatus(int status, char *statusMessage ) {1888 fprintf(cgiOut, "Status: %d %s\r\n\r\n", status, statusMessage);1889 } 1890 1891 void cgiHeaderContentType(char *mimeType ) {1892 fprintf(cgiOut, "Content-type: %s\r\n\r\n", mimeType);1893 } 1894 1895 static int cgiWriteString(FILE *out, char *s);1896 1897 static int cgiWriteInt(FILE *out, int i);1891 void cgiHeaderLocation(char *redirectUrl,FCGX_Stream * out) { 1892 FCGX_FPrintF(out, "Location: %s\r\n\r\n", redirectUrl); 1893 } 1894 1895 void cgiHeaderStatus(int status, char *statusMessage,FCGX_Stream * out) { 1896 FCGX_FPrintF(out, "Status: %d %s\r\n\r\n", status, statusMessage); 1897 } 1898 1899 void cgiHeaderContentType(char *mimeType,FCGX_Stream * out) { 1900 FCGX_FPrintF(out, "Content-type: %s\r\n\r\n", mimeType); 1901 } 1902 1903 //static int cgiWriteString(FILE *out, char *s); 1904 1905 //static int cgiWriteInt(FILE *out, int i); 1898 1906 1899 1907 #define CGIC_VERSION "2.0" 1900 1908 /** 1901 1909 cgiEnvironmentResultType cgiWriteEnvironment(char *filename) { 1902 1910 FILE *out; 1903 1911 cgiFormEntry *e; 1904 / * Be sure to open in binary mode */1912 // Be sure to open in binary mode 1905 1913 out = fopen(filename, "wb"); 1906 1914 if (!out) { 1907 / * Can't create file */1915 // Can't create file 1908 1916 return cgiEnvironmentIO; 1909 1917 } … … 1983 1991 goto error; 1984 1992 } 1985 / * New 2.0 fields and file uploads */1993 // New 2.0 fields and file uploads 1986 1994 if (!cgiWriteString(out, e->fileName)) { 1987 1995 goto error; … … 2022 2030 error: 2023 2031 fclose(out); 2024 / *If this function is not defined in your system,2025 you must substitute the appropriate2026 file-deletion function. */2032 // If this function is not defined in your system, 2033 // you must substitute the appropriate 2034 // file-deletion function. 2027 2035 unlink(filename); 2028 2036 return cgiEnvironmentIO; 2029 2037 } 2030 2038 2039 **/ 2040 2041 /** 2031 2042 static int cgiWriteString(FILE *out, char *s) { 2032 2043 int len = (int) strlen(s); … … 2049 2060 static int cgiReadInt(FILE *out, int *i); 2050 2061 2062 **/ 2063 2064 2065 /** 2051 2066 cgiEnvironmentResultType cgiReadEnvironment(char *filename) { 2052 2067 FILE *in; 2053 2068 cgiFormEntry *e = 0, *p; 2054 2069 char *version; 2055 / * Prevent compiler warnings */2070 // Prevent compiler warnings 2056 2071 cgiEnvironmentResultType result = cgiEnvironmentIO; 2057 / * Free any existing data first */2072 // Free any existing data first 2058 2073 cgiFreeResources(); 2059 / * Be sure to open in binary mode */2074 / Be sure to open in binary mode 2060 2075 in = fopen(filename, "rb"); 2061 2076 if (!in) { 2062 / * Can't access file */2077 // Can't access file 2063 2078 return cgiEnvironmentIO; 2064 2079 } … … 2067 2082 } 2068 2083 if (strcmp(version, "CGIC" CGIC_VERSION)) { 2069 / * 2.02: Merezko Oleg */2084 // 2.02: Merezko Oleg 2070 2085 free(version); 2071 2086 return cgiEnvironmentWrongVersion; 2072 2087 } 2073 / * 2.02: Merezko Oleg */2088 // 2.02: Merezko Oleg 2074 2089 free(version); 2075 2090 if (!cgiReadString(in, &cgiServerSoftware)) { … … 2130 2145 goto error; 2131 2146 } 2132 / * 2.0 */2147 // 2.0 2133 2148 if (!cgiReadString(in, &cgiCookie)) { 2134 2149 goto error; … … 2148 2163 memset(e, 0, sizeof(cgiFormEntry)); 2149 2164 if (!cgiReadString(in, &e->attr)) { 2150 / * This means we've reached the end of the list. */2151 / * 2.02: thanks to Merezko Oleg */2165 // This means we've reached the end of the list. 2166 // 2.02: thanks to Merezko Oleg 2152 2167 free(e); 2153 2168 break; … … 2186 2201 } 2187 2202 while (len > 0) { 2188 / *2.01: try is a bad variable name in2189 C++, and it wasn't being used2190 properly either */2203 // 2.01: try is a bad variable name in 2204 // C++, and it wasn't being used 2205 // properly either 2191 2206 int tryr = len; 2192 2207 if (tryr > ((int) sizeof(buffer))) { … … 2208 2223 len -= got; 2209 2224 } 2210 / * cgic 2.05: should be fclose not rewind */2225 // cgic 2.05: should be fclose not rewind 2211 2226 fclose(out); 2212 2227 e->tfileName = (char *) malloc((int) strlen(tfileName) + 1); … … 2260 2275 return result; 2261 2276 } 2262 2277 **/ 2278 2279 2280 /** 2263 2281 static int cgiReadString(FILE *in, char **s) { 2264 2282 int len; 2265 / * 2.0 fix: test cgiReadInt for failure! */2283 // 2.0 fix: test cgiReadInt for failure! 2266 2284 if (!cgiReadInt(in, &len)) { 2267 2285 return 0; … … 2284 2302 return 1; 2285 2303 } 2286 2304 **/ 2287 2305 static int cgiStrEqNc(char *s1, char *s2) { 2288 2306 while(1) { … … 2327 2345 } 2328 2346 2329 static char *cgiFindTarget = 0; 2330 static cgiFormEntry *cgiFindPos = 0; 2331 2332 static cgiFormEntry *cgiFormEntryFindFirst(char *name) { 2333 cgiFindTarget = name; 2334 cgiFindPos = cgiFormEntryFirst; 2335 return cgiFormEntryFindNext(); 2336 } 2337 2338 static cgiFormEntry *cgiFormEntryFindNext() { 2339 while (cgiFindPos) { 2340 cgiFormEntry *c = cgiFindPos; 2341 cgiFindPos = c->next; 2342 if (!strcmp(c -> attr, cgiFindTarget)) { 2347 //static char *cgiFindTarget = 0; 2348 //static cgiFormEntry *cgiFindPos = 0; 2349 2350 static cgiFormEntry *cgiFormEntryFindFirst(char *name,struct cgi_env ** ce) { 2351 struct cgi_env * cgi = * ce; 2352 cgi->cgiFindTarget = name; 2353 cgi->cgiFindPos = cgi->cgiFormEntryFirst; 2354 return cgiFormEntryFindNext(ce); 2355 } 2356 2357 static cgiFormEntry *cgiFormEntryFindNext(struct cgi_env ** ce) { 2358 struct cgi_env * cgi = * ce; 2359 while (cgi->cgiFindPos) { 2360 cgiFormEntry *c = cgi->cgiFindPos; 2361 cgi->cgiFindPos = c->next; 2362 if (!strcmp(c -> attr, cgi->cgiFindTarget)) { 2343 2363 return c; 2344 2364 } … … 2365 2385 } 2366 2386 2367 cgiFormResultType cgiCookies(char ***result ) {2387 cgiFormResultType cgiCookies(char ***result,char *cgiCookie) { 2368 2388 char **stringArray; 2369 2389 int i; … … 2422 2442 } 2423 2443 2424 cgiFormResultType cgiFormEntries(char ***result) { 2444 cgiFormResultType cgiFormEntries(char ***result,struct cgi_env ** ce) { 2445 struct cgi_env * cgi = *ce; 2425 2446 char **stringArray; 2426 2447 cgiFormEntry *e, *pe; 2427 2448 int i; 2428 2449 int total = 0; 2429 e = cgi FormEntryFirst;2450 e = cgi->cgiFormEntryFirst; 2430 2451 while (e) { 2431 2452 /* Don't count a field name more than once if 2432 2453 multiple values happen to be present for it */ 2433 pe = cgi FormEntryFirst;2454 pe = cgi->cgiFormEntryFirst; 2434 2455 while (pe != e) { 2435 2456 if (!strcmp(e->attr, pe->attr)) { … … 2452 2473 } 2453 2474 /* Now go get the entries */ 2454 e = cgi FormEntryFirst;2475 e = cgi->cgiFormEntryFirst; 2455 2476 i = 0; 2456 2477 while (e) { … … 2458 2479 /* Don't return a field name more than once if 2459 2480 multiple values happen to be present for it */ 2460 pe = cgi FormEntryFirst;2481 pe = cgi->cgiFormEntryFirst; 2461 2482 while (pe != e) { 2462 2483 if (!strcmp(e->attr, pe->attr)) { … … 2482 2503 } 2483 2504 2484 #define TRYPUTC(ch ) \2505 #define TRYPUTC(ch,out) \ 2485 2506 { \ 2486 if ( putc((ch), cgiOut) == EOF) { \2507 if (FCGX_PutChar((int)ch, out) == -1) { \ 2487 2508 return cgiFormIO; \ 2488 2509 } \ 2489 2510 } 2490 2511 2491 cgiFormResultType cgiHtmlEscapeData(char *data, int len )2512 cgiFormResultType cgiHtmlEscapeData(char *data, int len,FCGX_Stream *out) 2492 2513 { 2493 2514 while (len--) { 2494 2515 if (*data == '<') { 2495 TRYPUTC('&' );2496 TRYPUTC('l' );2497 TRYPUTC('t' );2498 TRYPUTC(';' );2516 TRYPUTC('&',out); 2517 TRYPUTC('l',out); 2518 TRYPUTC('t',out); 2519 TRYPUTC(';',out); 2499 2520 } else if (*data == '&') { 2500 TRYPUTC('&' );2501 TRYPUTC('a' );2502 TRYPUTC('m' );2503 TRYPUTC('p' );2504 TRYPUTC(';' );2521 TRYPUTC('&',out); 2522 TRYPUTC('a',out); 2523 TRYPUTC('m',out); 2524 TRYPUTC('p',out); 2525 TRYPUTC(';',out); 2505 2526 } else if (*data == '>') { 2506 TRYPUTC('&' );2507 TRYPUTC('g' );2508 TRYPUTC('t' );2509 TRYPUTC(';' );2527 TRYPUTC('&',out); 2528 TRYPUTC('g',out); 2529 TRYPUTC('t',out); 2530 TRYPUTC(';',out); 2510 2531 } else { 2511 TRYPUTC(*data );2532 TRYPUTC(*data,out); 2512 2533 } 2513 2534 data++; … … 2516 2537 } 2517 2538 2518 cgiFormResultType cgiHtmlEscape(char *s )2539 cgiFormResultType cgiHtmlEscape(char *s, FCGX_Stream *out) 2519 2540 { 2520 return cgiHtmlEscapeData(s, (int) strlen(s) );2541 return cgiHtmlEscapeData(s, (int) strlen(s),out); 2521 2542 } 2522 2543 … … 2527 2548 bytes in 'data'. Returns cgiFormIO in the event 2528 2549 of error, cgiFormSuccess otherwise. */ 2529 cgiFormResultType cgiValueEscapeData(char *data, int len )2550 cgiFormResultType cgiValueEscapeData(char *data, int len,FCGX_Stream *out) 2530 2551 { 2531 2552 while (len--) { 2532 2553 if (*data == '\"') { 2533 TRYPUTC('&' );2534 TRYPUTC('#' );2535 TRYPUTC('3' );2536 TRYPUTC('4' );2537 TRYPUTC(';' );2554 TRYPUTC('&',out); 2555 TRYPUTC('#',out); 2556 TRYPUTC('3',out); 2557 TRYPUTC('4',out); 2558 TRYPUTC(';',out); 2538 2559 } else { 2539 TRYPUTC(*data );2560 TRYPUTC(*data,out); 2540 2561 } 2541 2562 data++; … … 2544 2565 } 2545 2566 2546 cgiFormResultType cgiValueEscape(char *s )2567 cgiFormResultType cgiValueEscape(char *s,FCGX_Stream *out) 2547 2568 { 2548 return cgiValueEscapeData(s, (int) strlen(s) );2549 } 2550 2551 2569 return cgiValueEscapeData(s, (int) strlen(s),out); 2570 } 2571 2572 -
branches/PublicaMundi_David-devel/thirds/cgic206/cgic.h
r511 r548 10 10 types defined by it, such as FILE *. */ 11 11 12 #include "fcgi_stdio.h" 13 //#include <stdio.h> 12 //#include "fcgi_stdio.h" 13 #include <fcgiapp.h> 14 #include <stdio.h> 14 15 15 16 /* The various CGI environment variables. Instead of using getenv(), … … 21 22 for debugging. */ 22 23 23 extern 24 #ifdef __cplusplus 25 "C" 26 #endif 24 25 typedef struct cgiFormEntryStruct { 26 char *attr; 27 /* value is populated for regular form fields only. 28 For file uploads, it points to an empty string, and file 29 upload data should be read from the file tfileName. */ 30 char *value; 31 /* When fileName is not an empty string, tfileName is not null, 32 and 'value' points to an empty string. */ 33 /* Valid for both files and regular fields; does not include 34 terminating null of regular fields. */ 35 int valueLength; 36 char *fileName; 37 char *contentType; 38 /* Temporary file name for working storage of file uploads. */ 39 char *tfileName; 40 struct cgiFormEntryStruct *next; 41 } cgiFormEntry; 42 43 44 45 46 struct cgi_env { 47 int cgiRestored;// = 0; 27 48 char *cgiServerSoftware; 28 extern29 #ifdef __cplusplus30 "C"31 #endif32 49 char *cgiServerName; 33 extern34 #ifdef __cplusplus35 "C"36 #endif37 50 char *cgiGatewayInterface; 38 extern39 #ifdef __cplusplus40 "C"41 #endif42 51 char *cgiServerProtocol; 43 extern44 #ifdef __cplusplus45 "C"46 #endif47 52 char *cgiServerPort; 48 extern49 #ifdef __cplusplus50 "C"51 #endif52 53 char *cgiRequestMethod; 53 extern54 #ifdef __cplusplus55 "C"56 #endif57 54 char *cgiPathInfo; 58 extern59 #ifdef __cplusplus60 "C"61 #endif62 55 char *cgiPathTranslated; 63 extern64 #ifdef __cplusplus65 "C"66 #endif67 56 char *cgiScriptName; 68 extern69 #ifdef __cplusplus70 "C"71 #endif72 57 char *cgiQueryString; 73 extern74 #ifdef __cplusplus75 "C"76 #endif77 58 char *cgiRemoteHost; 78 extern79 #ifdef __cplusplus80 "C"81 #endif82 59 char *cgiRemoteAddr; 83 extern84 #ifdef __cplusplus85 "C"86 #endif87 60 char *cgiAuthType; 88 extern89 #ifdef __cplusplus90 "C"91 #endif92 61 char *cgiRemoteUser; 93 extern94 #ifdef __cplusplus95 "C"96 #endif97 62 char *cgiRemoteIdent; 98 extern 99 #ifdef __cplusplus 100 "C" 101 #endif 102 char *cgiContentType; 103 extern 104 #ifdef __cplusplus 105 "C" 106 #endif 63 char cgiContentTypeData[1024]; 64 char *cgiContentType;// = cgiContentTypeData; 65 66 char * cgiMultipartBoundary; 67 cgiFormEntry *cgiFormEntryFirst; 68 int cgiTreatUrlEncoding; 69 107 70 char *cgiAccept; 108 extern109 #ifdef __cplusplus110 "C"111 #endif112 71 char *cgiUserAgent; 113 extern114 #ifdef __cplusplus115 "C"116 #endif117 72 char *cgiReferrer; 118 73 119 74 /* Cookies as sent to the server. You can also get them 120 75 individually, or as a string array; see the documentation. */ 121 extern122 #ifdef __cplusplus123 "C"124 #endif125 76 char *cgiCookie; 126 127 extern128 #ifdef __cplusplus129 "C"130 #endif131 77 char *cgiSid; 132 78 … … 140 86 directly from cgiIn; the programmer need not do so. */ 141 87 142 extern143 #ifdef __cplusplus144 "C"145 #endif146 88 int cgiContentLength; 147 89 … … 152 94 cgiOut is always equivalent to stdout. */ 153 95 154 extern 155 #ifdef __cplusplus 156 "C" 157 #endif 158 FILE *cgiOut; 159 160 /* Pointer to CGI input. The programmer does not read from this. 161 We have continued to export it for backwards compatibility 162 so that cgic 1.x applications link properly. */ 163 164 extern 165 #ifdef __cplusplus 166 "C" 167 #endif 168 FILE *cgiIn; 169 96 char *cgiFindTarget; 97 cgiFormEntry *cgiFindPos; 98 99 }; 170 100 /* Possible return codes from the cgiForm family of functions (see below). */ 171 101 … … 195 125 #endif 196 126 cgiFormResultType cgiFormString( 197 char *name, char *result, int max );127 char *name, char *result, int max,struct cgi_env **); 198 128 199 129 extern … … 202 132 #endif 203 133 cgiFormResultType cgiFormStringNoNewlines( 204 char *name, char *result, int max );134 char *name, char *result, int max,struct cgi_env ** ce); 205 135 206 136 … … 210 140 #endif 211 141 cgiFormResultType cgiFormStringSpaceNeeded( 212 char *name, int *length );142 char *name, int *length,struct cgi_env ** ce); 213 143 214 144 … … 218 148 #endif 219 149 cgiFormResultType cgiFormStringMultiple( 220 char *name, char ***ptrToStringArray );150 char *name, char ***ptrToStringArray,struct cgi_env ** ce); 221 151 222 152 extern … … 231 161 #endif 232 162 cgiFormResultType cgiFormInteger( 233 char *name, int *result, int defaultV );163 char *name, int *result, int defaultV,struct cgi_env ** ce); 234 164 235 165 extern … … 238 168 #endif 239 169 cgiFormResultType cgiFormIntegerBounded( 240 char *name, int *result, int min, int max, int defaultV );170 char *name, int *result, int min, int max, int defaultV,struct cgi_env **ce); 241 171 242 172 extern … … 245 175 #endif 246 176 cgiFormResultType cgiFormDouble( 247 char *name, double *result, double defaultV );177 char *name, double *result, double defaultV,struct cgi_env **); 248 178 249 179 extern … … 252 182 #endif 253 183 cgiFormResultType cgiFormDoubleBounded( 254 char *name, double *result, double min, double max, double defaultV );184 char *name, double *result, double min, double max, double defaultV, struct cgi_env ** ce); 255 185 256 186 extern … … 260 190 cgiFormResultType cgiFormSelectSingle( 261 191 char *name, char **choicesText, int choicesTotal, 262 int *result, int defaultV );192 int *result, int defaultV,struct cgi_env **ce); 263 193 264 194 … … 269 199 cgiFormResultType cgiFormSelectMultiple( 270 200 char *name, char **choicesText, int choicesTotal, 271 int *result, int *invalid );201 int *result, int *invalid,struct cgi_env **); 272 202 273 203 /* Just an alias; users have asked for this */ … … 279 209 #endif 280 210 cgiFormResultType cgiFormCheckboxSingle( 281 char *name );211 char *name,struct cgi_env ** ce); 282 212 283 213 extern … … 287 217 cgiFormResultType cgiFormCheckboxMultiple( 288 218 char *name, char **valuesText, int valuesTotal, 289 int *result, int *invalid );219 int *result, int *invalid,struct cgi_env ** ce); 290 220 291 221 extern … … 295 225 cgiFormResultType cgiFormRadio( 296 226 char *name, char **valuesText, int valuesTotal, 297 int *result, int defaultV );227 int *result, int defaultV,struct cgi_env **ce); 298 228 299 229 /* The paths returned by this function are the original names of files … … 305 235 #endif 306 236 cgiFormResultType cgiFormFileName( 307 char *name, char *result, int max );237 char *name, char *result, int max,struct cgi_env **); 308 238 309 239 /* The content type of the uploaded file, as reported by the browser. … … 315 245 #endif 316 246 cgiFormResultType cgiFormFileContentType( 317 char *name, char *result, int max );247 char *name, char *result, int max,struct cgi_env ** ce); 318 248 319 249 extern … … 322 252 #endif 323 253 cgiFormResultType cgiFormFileSize( 324 char *name, int *sizeP );254 char *name, int *sizeP,struct cgi_env ** ce); 325 255 326 256 typedef struct cgiFileStruct *cgiFilePtr; … … 331 261 #endif 332 262 cgiFormResultType cgiFormFileOpen( 333 char *name, cgiFilePtr *cfpp );263 char *name, cgiFilePtr *cfpp,struct cgi_env ** ce); 334 264 335 265 extern … … 352 282 #endif 353 283 cgiFormResultType cgiCookieString( 354 char *name, char *result, int max );284 char *name, char *result, int max,char * cgiCookie); 355 285 356 286 extern … … 359 289 #endif 360 290 cgiFormResultType cgiCookieInteger( 361 char *name, int *result, int defaultV );291 char *name, int *result, int defaultV,char * cgiCookie); 362 292 363 293 cgiFormResultType cgiCookies( 364 char ***ptrToStringArray );294 char ***ptrToStringArray,char* cgiCookie); 365 295 366 296 /* path can be null or empty in which case a path of / (entire site) is set. … … 372 302 #endif 373 303 void cgiHeaderCookieSetString(char *name, char *value, 374 int secondsToLive, char *path, char *domain );304 int secondsToLive, char *path, char *domain,FCGX_Stream *out); 375 305 extern 376 306 #ifdef __cplusplus … … 378 308 #endif 379 309 void cgiHeaderCookieSetInteger(char *name, int value, 380 int secondsToLive, char *path, char *domain );381 extern 382 #ifdef __cplusplus 383 "C" 384 #endif 385 void cgiHeaderLocation(char *redirectUrl );386 extern 387 #ifdef __cplusplus 388 "C" 389 #endif 390 void cgiHeaderStatus(int status, char *statusMessage );391 extern 392 #ifdef __cplusplus 393 "C" 394 #endif 395 void cgiHeaderContentType(char *mimeType );310 int secondsToLive, char *path, char *domain,FCGX_Stream *out); 311 extern 312 #ifdef __cplusplus 313 "C" 314 #endif 315 void cgiHeaderLocation(char *redirectUrl,FCGX_Stream * out); 316 extern 317 #ifdef __cplusplus 318 "C" 319 #endif 320 void cgiHeaderStatus(int status, char *statusMessage,FCGX_Stream * out); 321 extern 322 #ifdef __cplusplus 323 "C" 324 #endif 325 void cgiHeaderContentType(char *mimeType,FCGX_Stream * out); 396 326 397 327 typedef enum { … … 421 351 #endif 422 352 cgiFormResultType cgiFormEntries( 423 char ***ptrToStringArray );353 char ***ptrToStringArray,struct cgi_env **ce); 424 354 425 355 /* Output string with the <, &, and > characters HTML-escaped. 426 356 's' is null-terminated. Returns cgiFormIO in the event 427 357 of error, cgiFormSuccess otherwise. */ 428 cgiFormResultType cgiHtmlEscape(char *s );358 cgiFormResultType cgiHtmlEscape(char *s,FCGX_Stream *out); 429 359 430 360 /* Output data with the <, &, and > characters HTML-escaped. … … 432 362 bytes in 'data'. Returns cgiFormIO in the event 433 363 of error, cgiFormSuccess otherwise. */ 434 cgiFormResultType cgiHtmlEscapeData(char *data, int len );364 cgiFormResultType cgiHtmlEscapeData(char *data, int len,FCGX_Stream *out); 435 365 436 366 /* Output string with the " character HTML-escaped, and no … … 439 369 's' is null-terminated. Returns cgiFormIO in the event 440 370 of error, cgiFormSuccess otherwise. */ 441 cgiFormResultType cgiValueEscape(char *s );371 cgiFormResultType cgiValueEscape(char *s,FCGX_Stream *out); 442 372 443 373 /* Output data with the " character HTML-escaped, and no … … 447 377 bytes in 'data'. Returns cgiFormIO in the event 448 378 of error, cgiFormSuccess otherwise. */ 449 cgiFormResultType cgiValueEscapeData(char *data, int len );450 451 int cgiMain_init(int argc, char *argv[] );452 453 void cgiFreeResources( );379 cgiFormResultType cgiValueEscapeData(char *data, int len,FCGX_Stream *out); 380 381 int cgiMain_init(int argc, char *argv[],struct cgi_env ** c,FCGX_Request *); 382 383 void cgiFreeResources(struct cgi_env ** c); 454 384 455 385 #endif /* CGI_C */
Note: See TracChangeset
for help on using the changeset viewer.