Changeset 548


Ignore:
Timestamp:
Feb 2, 2015, 9:55:48 AM (6 years ago)
Author:
david
Message:
  • FCX_Stream integration
Location:
branches/PublicaMundi_David-devel/thirds/cgic206
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/PublicaMundi_David-devel/thirds/cgic206/Makefile

    r346 r548  
    1616RANLIB=ranlib
    1717
    18 all: libcgic.a cgictest.cgi capture
     18all: libcgic.a
    1919
    2020install: libcgic.a
     
    3131#mingw32 and cygwin users: replace .cgi with .exe
    3232
    33 cgictest.cgi: cgictest.o libcgic.a
    34         gcc cgictest.o -o cgictest.cgi ${LIBS}
     33#cgictest.cgi: cgictest.o libcgic.a
     34#       gcc cgictest.o -o cgictest.cgi ${LIBS}
    3535
    36 capture: capture.o libcgic.a
    37         gcc capture.o -o capture ${LIBS}
     36#capture: capture.o libcgic.a
     37#       gcc capture.o -o capture ${LIBS}
    3838
    3939clean:
    40         rm -f *.o *.a cgictest.cgi capture
     40        rm -f *.o *.a #cgictest.cgi capture
    4141
  • branches/PublicaMundi_David-devel/thirds/cgic206/cgic.c

    r511 r548  
    1010
    1111#include <fcgi_stdio.h>
     12
    1213#if CGICDEBUG
    1314#define CGICDEBUGSTART \
     
    4849
    4950#define cgiStrEq(a, b) (!strcmp((a), (b)))
    50 
     51/**
    5152char *cgiServerSoftware;
    5253char *cgiServerName;
     
    7778FILE *cgiOut;
    7879
     80**/
     81
    7982/* 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);
    8487
    8588typedef enum {
     
    97100        VALUES. Make local copies if modifications are desired. */
    98101
    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 file
    103                 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 include
    108                 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;
    116102
    117103/* 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
     106static cgiParseResultType cgiParseGetFormInput(struct cgi_env ** ce);
     107static cgiParseResultType cgiParsePostFormInput(struct cgi_env ** ce, FCGX_Stream *in);
     108static cgiParseResultType cgiParsePostMultipartInput(struct cgi_env **cet, FCGX_Stream *in);
     109static cgiParseResultType cgiParseFormInput(char *data, int length,struct cgi_env ** ce);
    124110static void cgiSetupConstants();
    125111void cgiFreeResources();
     
    130116
    131117
    132 int cgiMain_init(int argc, char *argv[]) {
    133         int result;
     118int 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;
    134126        char *cgiContentLengthString;
    135127        char *e;
    136128        cgiSetupConstants();
    137         cgiGetenv(&cgiServerSoftware, "SERVER_SOFTWARE");
    138         cgiGetenv(&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(cgiRequestMethod,"")==0 && argc>=1)
    144                 cgiRequestMethod="GET";
    145         cgiGetenv(&cgiPathInfo, "PATH_INFO");
    146         cgiGetenv(&cgiPathTranslated, "PATH_TRANSLATED");
    147         cgiGetenv(&cgiScriptName, "SCRIPT_NAME");
    148         cgiGetenv(&cgiQueryString, "QUERY_STRING");
    149         cgiSid=NULL;
    150         if(cgiQueryString!=NULL && argc>=2){
    151                 cgiQueryString=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];
    152144                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");
    161154        /* 2.0: the content type string needs to be parsed and modified, so
    162155                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);
    167161                } else {
    168162                        /* Truncate safely in the event of what is almost certainly
    169163                                a hack attempt */
    170                         strncpy(cgiContentType, e, sizeof(cgiContentTypeData));
    171                         cgiContentType[sizeof(cgiContentTypeData) - 1] = '\0';
     164                        strncpy(cgi->cgiContentType, e, sizeof(cgi->cgiContentTypeData));
     165                        cgi->cgiContentType[sizeof(cgi->cgiContentTypeData) - 1] = '\0';
    172166                }
    173167        } else {
    174                 cgiContentType[0] = '\0';
     168                cgi->cgiContentType[0] = '\0';
    175169        }
    176170        /* Never null */
    177         cgiMultipartBoundary = "";
     171        cgi->cgiMultipartBoundary = "";
    178172        /* 2.0: parse semicolon-separated additional parameters of the
    179173                content type. The one we're interested in is 'boundary'.
    180174                We discard the rest to make cgiContentType more useful
    181175                to the typical programmer. */
    182         if (strchr(cgiContentType, ';')) {
    183                 char *sat = strchr(cgiContentType, ';');
     176        if (strchr(cgi->cgiContentType, ';')) {
     177                char *sat = strchr(cgi->cgiContentType, ';');
    184178                while (sat) {
    185179                        *sat = '\0';
     
    190184                        if (cgiStrBeginsNc(sat, "boundary=")) {
    191185                                char *s;
    192                                 cgiMultipartBoundary = sat + strlen("boundary=");
    193                                 s = cgiMultipartBoundary;
     186                                cgi->cgiMultipartBoundary = sat + strlen("boundary=");
     187                                s = cgi->cgiMultipartBoundary;
    194188                                while ((*s) && (!isspace(*s))) {
    195189                                        s++;
     
    202196                }
    203197        }
    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);
    220211#ifdef WIN32
    221212        /* 1.07: Must set stdin and stdout to binary mode */
     
    224215        _setmode( FCGI_fileno( stdout ), _O_BINARY );
    225216#endif /* WIN32 */
    226         cgiFormEntryFirst = 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;
    230221
    231222
     
    235226        if (argc) {
    236227                if (argv[0]) {
    237                         cgiRestored = 0;
     228                        cgi->cgiRestored = 0;
    238229                }
    239230        }       
    240231
    241232
    242         cgiTreatUrlEncoding=0;
    243         if (cgiStrEqNc(cgiRequestMethod, "post")) {
    244                 cgiTreatUrlEncoding=0;
     233        cgi->cgiTreatUrlEncoding=0;
     234        if (cgiStrEqNc(cgi->cgiRequestMethod, "post")) {
     235                cgi->cgiTreatUrlEncoding=0;
    245236#ifdef CGICDEBUG
    246237                CGICDEBUGSTART
     
    248239                CGICDEBUGEND
    249240#endif /* CGICDEBUG */
    250                 if (cgiStrEqNc(cgiContentType, "application/x-www-form-urlencoded")) { 
     241                if (cgiStrEqNc(cgi->cgiContentType, "application/x-www-form-urlencoded")) {     
    251242#ifdef CGICDEBUG
    252243                        CGICDEBUGSTART
     
    254245                        CGICDEBUGEND   
    255246#endif /* CGICDEBUG */
    256                         if (cgiParsePostFormInput() != cgiParseSuccess) {
     247                        if (cgiParsePostFormInput(&cgi,request->in) != cgiParseSuccess) {
    257248#ifdef CGICDEBUG
    258249                                CGICDEBUGSTART
     
    260251                                CGICDEBUGEND   
    261252#endif /* CGICDEBUG */
    262                                 cgiFreeResources();
     253                                cgiFreeResources(&cgi);
    263254                                return -1;
    264255                        }       
     
    268259                        CGICDEBUGEND   
    269260#endif /* CGICDEBUG */
    270                 } else if (cgiStrEqNc(cgiContentType, "multipart/form-data")) {
     261                } else if (cgiStrEqNc(cgi->cgiContentType, "multipart/form-data")) {
    271262#ifdef CGICDEBUG
    272263                        CGICDEBUGSTART
     
    274265                        CGICDEBUGEND   
    275266#endif /* CGICDEBUG */
    276                         if (cgiParsePostMultipartInput() != cgiParseSuccess) {
     267                        if (cgiParsePostMultipartInput(&cgi,request->in) != cgiParseSuccess) {
    277268#ifdef CGICDEBUG
    278269                                CGICDEBUGSTART
     
    280271                                CGICDEBUGEND   
    281272#endif /* CGICDEBUG */
    282                                 cgiFreeResources();
     273                                cgiFreeResources(&cgi);
    283274                                return -1;
    284275                        }       
     
    289280#endif /* CGICDEBUG */
    290281                }
    291         } else if (cgiStrEqNc(cgiRequestMethod, "get")) {       
     282        } else if (cgiStrEqNc(cgi->cgiRequestMethod, "get")) { 
    292283                /* The spec says this should be taken care of by
    293284                        the server, but... it isn't */
    294                 cgiContentLength = strlen(cgiQueryString);
    295                 if (cgiParseGetFormInput() != cgiParseSuccess) {
     285                cgi->cgiContentLength = strlen(cgi->cgiQueryString);
     286                if (cgiParseGetFormInput(&cgi) != cgiParseSuccess) {
    296287#ifdef CGICDEBUG
    297288                        CGICDEBUGSTART
     
    299290                        CGICDEBUGEND   
    300291#endif /* CGICDEBUG */
    301                         cgiFreeResources();
     292                        cgiFreeResources(&cgi);
    302293                        return -1;
    303294                } else {       
     
    311302        return result;
    312303}
    313 
     304/**
    314305static void cgiGetenv(char **s, char *var){
    315306        *s = getenv(var);
     
    318309        }
    319310}
    320 
    321 static cgiParseResultType cgiParsePostFormInput() {
     311**/
     312static cgiParseResultType cgiParsePostFormInput(struct cgi_env **ce, FCGX_Stream *in) {
     313    struct cgi_env * cgi = *ce;
    322314        char *input;
    323315        cgiParseResultType result;
    324         if (!cgiContentLength) {
     316        if (!cgi->cgiContentLength) {
    325317                return cgiParseSuccess;
    326318        }
    327         input = (char *) malloc(cgiContentLength);
     319        input = (char *) malloc(cgi->cgiContentLength);
    328320        if (!input) {
    329321                return cgiParseMemory; 
    330322        }
    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)   
    333325        {
    334326                return cgiParseIO;
    335327        }       
    336         result = cgiParseFormInput(input, cgiContentLength);
     328        result = cgiParseFormInput(input,cgi->cgiContentLength,&cgi);
    337329        free(input);
    338330        return result;
     
    361353} mpStream, *mpStreamPtr;
    362354
    363 int mpRead(mpStreamPtr mpp, char *buffer, int len)
     355int mpRead(mpStreamPtr mpp, char *buffer, int len, int cgiContentLength,FCGX_Stream *in)
    364356{
    365357        int ilen = len;
     
    381373        }
    382374        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);
    384377                if (fgot >= 0) {
    385378                        mpp->offset += (got + fgot);
     
    430423        char **outP,
    431424        int *bodyLengthP,
    432         int first
     425        int first,
     426    int cgiContentLength,
     427    FCGX_Stream *in,
     428    char * cgiMultipartBoundary
    433429        );
    434430
     
    438434        int attrSpace,
    439435        char *value,
    440         int valueSpace);
     436        int valueSpace,
     437    int cgiContentLength,
     438    FCGX_Stream *in);
    441439
    442440static void decomposeValue(char *value,
     
    454452static cgiParseResultType getTempFileName(char *tfileName);
    455453
    456 static cgiParseResultType cgiParsePostMultipartInput() {
    457         cgiParseResultType result;
     454static cgiParseResultType cgiParsePostMultipartInput(struct cgi_env ** ce,FCGX_Stream * in) {
     455        struct cgi_env * cgi = *ce;
     456    cgiParseResultType result;
    458457        cgiFormEntry *n = 0, *l = 0;
    459458        int got;
     
    464463        mpStreamPtr mpp = &mp;
    465464        memset(&mp, 0, sizeof(mp));
    466         if (!cgiContentLength) {
     465        if (!cgi->cgiContentLength) {
    467466                return cgiParseSuccess;
    468467        }
    469468        /* 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);
    471470        if (result == cgiParseIO) {     
    472471                /* An empty submission is not necessarily an error */
     
    491490                outf = 0;
    492491                /* Check for EOF */
    493                 got = mpRead(mpp, d, 2);
     492                got = mpRead(mpp, d, 2,cgi->cgiContentLength,in);
    494493                if (got < 2) {
    495494                        /* Crude EOF */
     
    503502                /* Read header lines until end of header */
    504503                while (readHeaderLine(
    505                                 mpp, attr, sizeof(attr), value, sizeof(value)))
     504                                mpp, attr, sizeof(attr), value, sizeof(value),cgi->cgiContentLength,in))
    506505                {
    507506                        char *argNames[3];
     
    548547                        tfileName[0] = '\0';
    549548                }       
    550                 result = afterNextBoundary(mpp, outf, &out, &bodyLength, 0);
     549                result = afterNextBoundary(mpp, outf, &out, &bodyLength, 0,cgi->cgiContentLength,in,cgi->cgiMultipartBoundary);
    551550                if (result != cgiParseSuccess) {
    552551                        /* Lack of a boundary here is an error. */
     
    587586                n->next = 0;
    588587                if (!l) {
    589                         cgiFormEntryFirst = n;
     588                        cgi->cgiFormEntryFirst = n;
    590589                } else {
    591590                        l->next = n;
     
    704703
    705704cgiParseResultType afterNextBoundary(mpStreamPtr mpp, FILE *outf, char **outP,
    706         int *bodyLengthP, int first)
     705        int *bodyLengthP, int first,int cgiContentLength,FCGX_Stream *in,char *cgiMultipartBoundary)
    707706{
    708707        int outLen = 0;
     
    733732        workingBoundaryLength = strlen(workingBoundary);
    734733        while (1) {
    735                 got = mpRead(mpp, d, 1);
     734                got = mpRead(mpp, d, 1,cgiContentLength,in);
    736735                if (got != 1) {
    737736                        /* 2.01: cgiParseIO, not cgiFormIO */
     
    768767        /* Read trailing newline or -- EOF marker. A literal EOF here
    769768                would be an error in the input stream. */
    770         got = mpRead(mpp, d, 2);
     769        got = mpRead(mpp, d, 2,cgiContentLength,in);
    771770        if (got != 2) {
    772771                result = cgiParseIO;
     
    929928        int attrSpace,
    930929        char *value,
    931         int valueSpace)
     930        int valueSpace,
     931    int cgiContentLength,
     932    FCGX_Stream *in)
    932933{       
    933934        int attrLen = 0;
     
    936937        while (1) {
    937938                char d[1];
    938                 int got = mpRead(mpp, d, 1);
     939                int got = mpRead(mpp, d, 1,cgiContentLength,in);
    939940                if (got != 1) {
    940941                        return 0;
    941942                }
    942943                if (d[0] == '\r') {
    943                         got = mpRead(mpp, d, 1);
     944                        got = mpRead(mpp, d, 1,cgiContentLength,in);
    944945                        if (got == 1) {
    945946                                if (d[0] == '\n') {
     
    954955                } else if ((d[0] == ':') && attrLen) {
    955956                        valueFound = 1;
    956                         while (mpRead(mpp, d, 1) == 1) {
     957                        while (mpRead(mpp, d, 1,cgiContentLength,in) == 1) {
    957958                                if (!isspace(d[0])) {
    958959                                        mpPutBack(mpp, d, 1);
     
    985986}
    986987
    987 static cgiParseResultType cgiParseGetFormInput() {
    988         return cgiParseFormInput(cgiQueryString, cgiContentLength);
     988static cgiParseResultType cgiParseGetFormInput(struct cgi_env ** ce) {
     989    struct cgi_env * cgi = *ce;
     990        return cgiParseFormInput(cgi->cgiQueryString, cgi->cgiContentLength,ce);
    989991}
    990992
     
    10001002} cgiUnescapeResultType;
    10011003
    1002 static cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len);
    1003 
    1004 static cgiParseResultType cgiParseFormInput(char *data, int length) {
     1004static cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len,int cgiTreatUrlEncoding);
     1005
     1006static cgiParseResultType cgiParseFormInput(char *data, int length,struct cgi_env ** ce) {
    10051007        /* Scan for pairs, unescaping and storing them as they are found. */
     1008    struct cgi_env * cgi = *ce;
    10061009        int pos = 0;
    10071010        cgiFormEntry *n;
     
    10261029                        break;
    10271030                }
    1028                 if (cgiUnescapeChars(&attr, data+start, len)
     1031                if (cgiUnescapeChars(&attr, data+start, len,cgi->cgiTreatUrlEncoding)
    10291032                        != cgiUnescapeSuccess) {
    10301033                        return cgiParseMemory;
     
    10431046                /* The last pair probably won't be followed by a &, but
    10441047                        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)
    10461049                        != cgiUnescapeSuccess) {
    10471050                        free(attr);
     
    10871090                n->next = 0;
    10881091                if (!l) {
    1089                         cgiFormEntryFirst = n;
     1092                        cgi->cgiFormEntryFirst = n;
    10901093                } else {
    10911094                        l->next = n;
     
    11011104static int cgiHexValue[256];
    11021105
    1103 cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len) {
     1106cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len,int cgiTreatUrlEncoding ) {
    11041107        char *s;
    11051108        cgiEscapeState escapeState = cgiEscapeRest;
     
    11721175}
    11731176
    1174 void cgiFreeResources() {
    1175         cgiFormEntry *c = cgiFormEntryFirst;
     1177void cgiFreeResources(struct cgi_env **cgi) {
     1178    struct cgi_env * cc = *cgi;
     1179        cgiFormEntry *c = cc->cgiFormEntryFirst;
    11761180        cgiFormEntry *n;
    11771181        while (c) {
     
    11901194        /* If the cgi environment was restored from a saved environment,
    11911195                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    **/
    12131219        /* 2.0: to clean up the environment for cgiReadEnvironment,
    12141220                we must set these correctly */
    1215         cgiFormEntryFirst = 0;
    1216         cgiRestored = 0;
     1221        cc->cgiFormEntryFirst = 0;
     1222        cc->cgiRestored = 0;
    12171223}
    12181224
     
    12201226        cgiFormEntry *e, char *result, int max, int newlines);
    12211227
    1222 static cgiFormEntry *cgiFormEntryFindFirst(char *name);
    1223 static cgiFormEntry *cgiFormEntryFindNext();
     1228static cgiFormEntry *cgiFormEntryFindFirst(char *name, struct cgi_env ** ce);
     1229static cgiFormEntry *cgiFormEntryFindNext(struct cgi_env ** ce);
    12241230
    12251231cgiFormResultType cgiFormString(
    1226         char *name, char *result, int max) {
     1232        char *name, char *result, int max,struct cgi_env ** ce) {
    12271233        cgiFormEntry *e;
    1228         e = cgiFormEntryFindFirst(name);
     1234        e = cgiFormEntryFindFirst(name,ce);
    12291235        if (!e) {
    12301236                strcpy(result, "");
     
    12351241
    12361242cgiFormResultType cgiFormFileName(
    1237         char *name, char *result, int resultSpace)
     1243        char *name, char *result, int resultSpace,struct cgi_env ** ce)
    12381244{
    12391245        cgiFormEntry *e;
    12401246        int resultLen = 0;
    12411247        char *s;
    1242         e = cgiFormEntryFindFirst(name);
     1248        e = cgiFormEntryFindFirst(name,ce);
    12431249        if (!e) {
    12441250                strcpy(result, "");
     
    12631269
    12641270cgiFormResultType cgiFormFileContentType(
    1265         char *name, char *result, int resultSpace)
     1271        char *name, char *result, int resultSpace,struct cgi_env ** ce)
    12661272{
    12671273        cgiFormEntry *e;
    12681274        int resultLen = 0;
    12691275        char *s;
    1270         e = cgiFormEntryFindFirst(name);
     1276        e = cgiFormEntryFindFirst(name,ce);
    12711277        if (!e) {
    12721278                if (resultSpace) {
     
    12931299
    12941300cgiFormResultType cgiFormFileSize(
    1295         char *name, int *sizeP)
     1301        char *name, int *sizeP,struct cgi_env ** ce)
    12961302{
    12971303        cgiFormEntry *e;
    1298         e = cgiFormEntryFindFirst(name);
     1304        e = cgiFormEntryFindFirst(name,ce);
    12991305        if (!e) {
    13001306                if (sizeP) {
     
    13201326
    13211327cgiFormResultType cgiFormFileOpen(
    1322         char *name, cgiFilePtr *cfpp)
     1328        char *name, cgiFilePtr *cfpp,struct cgi_env ** ce)
    13231329{
    13241330        cgiFormEntry *e;
    13251331        cgiFilePtr cfp;
    1326         e = cgiFormEntryFindFirst(name);
     1332        e = cgiFormEntryFindFirst(name,ce);
    13271333        if (!e) {
    13281334                *cfpp = 0;
     
    13741380
    13751381cgiFormResultType cgiFormStringNoNewlines(
    1376         char *name, char *result, int max) {
     1382        char *name, char *result, int max,struct cgi_env ** ce) {
    13771383        cgiFormEntry *e;
    1378         e = cgiFormEntryFindFirst(name);
     1384        e = cgiFormEntryFindFirst(name,ce);
    13791385        if (!e) {
    13801386                strcpy(result, "");
     
    13851391
    13861392cgiFormResultType cgiFormStringMultiple(
    1387         char *name, char ***result) {
     1393        char *name, char ***result,struct cgi_env ** ce) {
    13881394        char **stringArray;
    13891395        cgiFormEntry *e;
     
    13931399                function is not commonly used. The select menu and
    13941400                radio box functions are faster. */
    1395         e = cgiFormEntryFindFirst(name);
     1401        e = cgiFormEntryFindFirst(name,ce);
    13961402        if (e != 0) {
    13971403                do {
    13981404                        total++;
    1399                 } while ((e = cgiFormEntryFindNext()) != 0);
     1405                } while ((e = cgiFormEntryFindNext(ce)) != 0);
    14001406        }
    14011407        stringArray = (char **) malloc(sizeof(char *) * (total + 1));
     
    14091415        }
    14101416        /* Now go get the entries */
    1411         e = cgiFormEntryFindFirst(name);
     1417        e = cgiFormEntryFindFirst(name,ce);
    14121418#ifdef CGICDEBUG
    14131419        CGICDEBUGSTART
     
    14291435                        cgiFormEntryString(e, stringArray[i], max, 1);
    14301436                        i++;
    1431                 } while ((e = cgiFormEntryFindNext()) != 0);
     1437                } while ((e = cgiFormEntryFindNext(ce)) != 0);
    14321438                *result = stringArray;
    14331439#ifdef CGICDEBUG
     
    14491455
    14501456cgiFormResultType cgiFormStringSpaceNeeded(
    1451         char *name, int *result) {
     1457        char *name, int *result,struct cgi_env ** ce) {
    14521458        cgiFormEntry *e;
    1453         e = cgiFormEntryFindFirst(name);
     1459        e = cgiFormEntryFindFirst(name,ce);
    14541460        if (!e) {
    14551461                *result = 1;
     
    15431549
    15441550cgiFormResultType cgiFormInteger(
    1545         char *name, int *result, int defaultV) {
     1551        char *name, int *result, int defaultV,struct cgi_env ** ce) {
    15461552        cgiFormEntry *e;
    15471553        int ch;
    1548         e = cgiFormEntryFindFirst(name);
     1554        e = cgiFormEntryFindFirst(name,ce);
    15491555        if (!e) {
    15501556                *result = defaultV;
     
    15661572
    15671573cgiFormResultType 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);
    15701576        if (error != cgiFormSuccess) {
    15711577                return error;
     
    15831589
    15841590cgiFormResultType cgiFormDouble(
    1585         char *name, double *result, double defaultV) {
     1591        char *name, double *result, double defaultV,struct cgi_env ** ce) {
    15861592        cgiFormEntry *e;
    15871593        int ch;
    1588         e = cgiFormEntryFindFirst(name);
     1594        e = cgiFormEntryFindFirst(name,ce);
    15891595        if (!e) {
    15901596                *result = defaultV;
     
    16061612
    16071613cgiFormResultType 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);
    16101616        if (error != cgiFormSuccess) {
    16111617                return error;
     
    16241630cgiFormResultType cgiFormSelectSingle(
    16251631        char *name, char **choicesText, int choicesTotal,
    1626         int *result, int defaultV)
     1632        int *result, int defaultV,struct cgi_env ** ce)
    16271633{
    16281634        cgiFormEntry *e;
    16291635        int i;
    1630         e = cgiFormEntryFindFirst(name);
     1636        e = cgiFormEntryFindFirst(name,ce);
    16311637#ifdef CGICDEBUG
    16321638        CGICDEBUGSTART
     
    16601666cgiFormResultType cgiFormSelectMultiple(
    16611667        char *name, char **choicesText, int choicesTotal,
    1662         int *result, int *invalid)
     1668        int *result, int *invalid,struct cgi_env ** ce)
    16631669{
    16641670        cgiFormEntry *e;
     
    16691675                result[i] = 0;
    16701676        }
    1671         e = cgiFormEntryFindFirst(name);
     1677        e = cgiFormEntryFindFirst(name,ce);
    16721678        if (!e) {
    16731679                *invalid = invalidE;
     
    16871693                        invalidE++;
    16881694                }
    1689         } while ((e = cgiFormEntryFindNext()) != 0);
     1695        } while ((e = cgiFormEntryFindNext(ce)) != 0);
    16901696
    16911697        *invalid = invalidE;
     
    16991705
    17001706cgiFormResultType cgiFormCheckboxSingle(
    1701         char *name)
     1707        char *name,struct cgi_env ** ce)
    17021708{
    17031709        cgiFormEntry *e;
    1704         e = cgiFormEntryFindFirst(name);
     1710        e = cgiFormEntryFindFirst(name,ce);
    17051711        if (!e) {
    17061712                return cgiFormNotFound;
     
    17111717extern cgiFormResultType cgiFormCheckboxMultiple(
    17121718        char *name, char **valuesText, int valuesTotal,
    1713         int *result, int *invalid)
     1719        int *result, int *invalid,struct cgi_env ** ce)
    17141720{
    17151721        /* Implementation is identical to cgiFormSelectMultiple. */
    17161722        return cgiFormSelectMultiple(name, valuesText,
    1717                 valuesTotal, result, invalid);
     1723                valuesTotal, result, invalid,ce);
    17181724}
    17191725
    17201726cgiFormResultType cgiFormRadio(
    17211727        char *name,
    1722         char **valuesText, int valuesTotal, int *result, int defaultV)
     1728        char **valuesText, int valuesTotal, int *result, int defaultV,struct cgi_env **ce)
    17231729{
    17241730        /* Implementation is identical to cgiFormSelectSingle. */
    17251731        return cgiFormSelectSingle(name, valuesText, valuesTotal,
    1726                 result, defaultV);
     1732                result, defaultV,ce);
    17271733}
    17281734
     
    17301736        char *name,
    17311737        char *value,
    1732         int space)
     1738        int space,
     1739    char * cgiCookie)
    17331740{
    17341741        char *p = cgiCookie;
     
    18031810        char *name,
    18041811        int *result,
    1805         int defaultV)
     1812        int defaultV,
     1813    char * cgiCookie)
    18061814{
    18071815        char buffer[256];
    18081816        cgiFormResultType r =
    1809                 cgiCookieString(name, buffer, sizeof(buffer));
     1817                cgiCookieString(name, buffer, sizeof(buffer),cgiCookie);
    18101818        if (r != cgiFormSuccess) {
    18111819                *result = defaultV;
     
    18171825
    18181826void cgiHeaderCookieSetInteger(char *name, int value, int secondsToLive,
    1819         char *path, char *domain)
     1827        char *path, char *domain,FCGX_Stream * out)
    18201828{
    18211829        char svalue[256];
    18221830        sprintf(svalue, "%d", value);
    1823         cgiHeaderCookieSetString(name, svalue, secondsToLive, path, domain);
     1831        cgiHeaderCookieSetString(name, svalue, secondsToLive, path, domain,out);
    18241832}
    18251833
     
    18501858
    18511859void cgiHeaderCookieSetString(char *name, char *value, int secondsToLive,
    1852         char *path, char *domain)
     1860        char *path, char *domain,FCGX_Stream * out)
    18531861{
    18541862        /* cgic 2.02: simpler and more widely compatible implementation.
     
    18681876        then = now + secondsToLive;
    18691877        gt = gmtime(&then);
    1870         fprintf(cgiOut,
     1878        FCGX_FPrintF(out,
    18711879                "Set-Cookie: %s=%s; domain=%s; expires=%s, %02d-%s-%04d %02d:%02d:%02d GMT; path=%s\r\n",
    18721880                name, value, domain,
     
    18811889}
    18821890
    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);
     1891void cgiHeaderLocation(char *redirectUrl,FCGX_Stream * out) {
     1892        FCGX_FPrintF(out, "Location: %s\r\n\r\n", redirectUrl);
     1893}
     1894
     1895void cgiHeaderStatus(int status, char *statusMessage,FCGX_Stream * out) {
     1896        FCGX_FPrintF(out, "Status: %d %s\r\n\r\n", status, statusMessage);
     1897}
     1898
     1899void 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);
    18981906
    18991907#define CGIC_VERSION "2.0"
    1900 
     1908/**
    19011909cgiEnvironmentResultType cgiWriteEnvironment(char *filename) {
    19021910        FILE *out;
    19031911        cgiFormEntry *e;
    1904         /* Be sure to open in binary mode */
     1912        // Be sure to open in binary mode
    19051913        out = fopen(filename, "wb");
    19061914        if (!out) {
    1907                 /* Can't create file */
     1915                // Can't create file
    19081916                return cgiEnvironmentIO;
    19091917        }
     
    19831991                        goto error;
    19841992                }
    1985                 /* New 2.0 fields and file uploads */
     1993                // New 2.0 fields and file uploads
    19861994                if (!cgiWriteString(out, e->fileName)) {
    19871995                        goto error;
     
    20222030error:
    20232031        fclose(out);
    2024         /* If this function is not defined in your system,
    2025                 you must substitute the appropriate
    2026                 file-deletion function. */
     2032        // If this function is not defined in your system,
     2033        //      you must substitute the appropriate
     2034        //      file-deletion function.
    20272035        unlink(filename);
    20282036        return cgiEnvironmentIO;
    20292037}
    20302038
     2039**/
     2040
     2041/**
    20312042static int cgiWriteString(FILE *out, char *s) {
    20322043        int len = (int) strlen(s);
     
    20492060static int cgiReadInt(FILE *out, int *i);
    20502061
     2062**/
     2063
     2064
     2065/**
    20512066cgiEnvironmentResultType cgiReadEnvironment(char *filename) {
    20522067        FILE *in;
    20532068        cgiFormEntry *e = 0, *p;
    20542069        char *version;
    2055         /* Prevent compiler warnings */
     2070        // Prevent compiler warnings
    20562071        cgiEnvironmentResultType result = cgiEnvironmentIO;
    2057         /* Free any existing data first */
     2072        // Free any existing data first
    20582073        cgiFreeResources();
    2059         /* Be sure to open in binary mode */
     2074        / Be sure to open in binary mode
    20602075        in = fopen(filename, "rb");
    20612076        if (!in) {
    2062                 /* Can't access file */
     2077                // Can't access file
    20632078                return cgiEnvironmentIO;
    20642079        }
     
    20672082        }
    20682083        if (strcmp(version, "CGIC" CGIC_VERSION)) {
    2069                 /* 2.02: Merezko Oleg */
     2084                // 2.02: Merezko Oleg
    20702085                free(version);
    20712086                return cgiEnvironmentWrongVersion;
    20722087        }       
    2073         /* 2.02: Merezko Oleg */
     2088        // 2.02: Merezko Oleg
    20742089        free(version);
    20752090        if (!cgiReadString(in, &cgiServerSoftware)) {
     
    21302145                goto error;
    21312146        }
    2132         /* 2.0 */
     2147        // 2.0
    21332148        if (!cgiReadString(in, &cgiCookie)) {
    21342149                goto error;
     
    21482163                memset(e, 0, sizeof(cgiFormEntry));
    21492164                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
    21522167                        free(e);
    21532168                        break;
     
    21862201                        }
    21872202                        while (len > 0) {               
    2188                                 /* 2.01: try is a bad variable name in
    2189                                         C++, and it wasn't being used
    2190                                         properly either */
     2203                                // 2.01: try is a bad variable name in
     2204                                //      C++, and it wasn't being used
     2205                                //      properly either
    21912206                                int tryr = len;
    21922207                                if (tryr > ((int) sizeof(buffer))) {
     
    22082223                                len -= got;
    22092224                        }
    2210                         /* cgic 2.05: should be fclose not rewind */
     2225                        // cgic 2.05: should be fclose not rewind
    22112226                        fclose(out);
    22122227                        e->tfileName = (char *) malloc((int) strlen(tfileName) + 1);
     
    22602275        return result;
    22612276}
    2262 
     2277**/
     2278
     2279
     2280/**
    22632281static int cgiReadString(FILE *in, char **s) {
    22642282        int len;
    2265         /* 2.0 fix: test cgiReadInt for failure! */
     2283        //  2.0 fix: test cgiReadInt for failure!
    22662284        if (!cgiReadInt(in, &len)) {
    22672285                return 0;
     
    22842302        return 1;
    22852303}
    2286 
     2304**/
    22872305static int cgiStrEqNc(char *s1, char *s2) {
    22882306        while(1) {
     
    23272345}
    23282346
    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
     2350static 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
     2357static 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)) {
    23432363                        return c;
    23442364                }
     
    23652385}       
    23662386
    2367 cgiFormResultType cgiCookies(char ***result) {
     2387cgiFormResultType cgiCookies(char ***result,char *cgiCookie) {
    23682388        char **stringArray;
    23692389        int i;
     
    24222442}
    24232443
    2424 cgiFormResultType cgiFormEntries(char ***result) {
     2444cgiFormResultType cgiFormEntries(char ***result,struct cgi_env ** ce) {
     2445    struct cgi_env * cgi = *ce;
    24252446        char **stringArray;
    24262447        cgiFormEntry *e, *pe;
    24272448        int i;
    24282449        int total = 0;
    2429         e = cgiFormEntryFirst;
     2450        e = cgi->cgiFormEntryFirst;
    24302451        while (e) {
    24312452                /* Don't count a field name more than once if
    24322453                        multiple values happen to be present for it */
    2433                 pe = cgiFormEntryFirst;
     2454                pe = cgi->cgiFormEntryFirst;
    24342455                while (pe != e) {
    24352456                        if (!strcmp(e->attr, pe->attr)) {
     
    24522473        }
    24532474        /* Now go get the entries */
    2454         e = cgiFormEntryFirst;
     2475        e = cgi->cgiFormEntryFirst;
    24552476        i = 0;
    24562477        while (e) {
     
    24582479                /* Don't return a field name more than once if
    24592480                        multiple values happen to be present for it */
    2460                 pe = cgiFormEntryFirst;
     2481                pe = cgi->cgiFormEntryFirst;
    24612482                while (pe != e) {
    24622483                        if (!strcmp(e->attr, pe->attr)) {
     
    24822503}
    24832504
    2484 #define TRYPUTC(ch) \
     2505#define TRYPUTC(ch,out) \
    24852506        { \
    2486                 if (putc((ch), cgiOut) == EOF) { \
     2507                if (FCGX_PutChar((int)ch, out) == -1) { \
    24872508                        return cgiFormIO; \
    24882509                } \
    24892510        }
    24902511
    2491 cgiFormResultType cgiHtmlEscapeData(char *data, int len)
     2512cgiFormResultType cgiHtmlEscapeData(char *data, int len,FCGX_Stream *out)
    24922513{
    24932514        while (len--) {
    24942515                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);
    24992520                } 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);
    25052526                } 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);
    25102531                } else {
    2511                         TRYPUTC(*data);
     2532                        TRYPUTC(*data,out);
    25122533                }
    25132534                data++;
     
    25162537}
    25172538
    2518 cgiFormResultType cgiHtmlEscape(char *s)
     2539cgiFormResultType cgiHtmlEscape(char *s, FCGX_Stream *out)
    25192540{
    2520         return cgiHtmlEscapeData(s, (int) strlen(s));
     2541        return cgiHtmlEscapeData(s, (int) strlen(s),out);
    25212542}
    25222543
     
    25272548        bytes in 'data'. Returns cgiFormIO in the event
    25282549        of error, cgiFormSuccess otherwise. */
    2529 cgiFormResultType cgiValueEscapeData(char *data, int len)
     2550cgiFormResultType cgiValueEscapeData(char *data, int len,FCGX_Stream *out)
    25302551{
    25312552        while (len--) {
    25322553                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);
    25382559                } else {
    2539                         TRYPUTC(*data);
     2560                        TRYPUTC(*data,out);
    25402561                }
    25412562                data++;
     
    25442565}
    25452566
    2546 cgiFormResultType cgiValueEscape(char *s)
     2567cgiFormResultType cgiValueEscape(char *s,FCGX_Stream *out)
    25472568{
    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  
    1010        types defined by it, such as FILE *. */
    1111
    12 #include "fcgi_stdio.h"
    13 //#include <stdio.h>
     12//#include "fcgi_stdio.h"
     13#include <fcgiapp.h>
     14#include <stdio.h>
    1415
    1516/* The various CGI environment variables. Instead of using getenv(),
     
    2122        for debugging. */
    2223
    23 extern
    24 #ifdef __cplusplus
    25 "C"
    26 #endif
     24
     25typedef 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
     46struct cgi_env {
     47int cgiRestored;// = 0;
    2748char *cgiServerSoftware;
    28 extern
    29 #ifdef __cplusplus
    30 "C"
    31 #endif
    3249char *cgiServerName;
    33 extern
    34 #ifdef __cplusplus
    35 "C"
    36 #endif
    3750char *cgiGatewayInterface;
    38 extern
    39 #ifdef __cplusplus
    40 "C"
    41 #endif
    4251char *cgiServerProtocol;
    43 extern
    44 #ifdef __cplusplus
    45 "C"
    46 #endif
    4752char *cgiServerPort;
    48 extern
    49 #ifdef __cplusplus
    50 "C"
    51 #endif
    5253char *cgiRequestMethod;
    53 extern
    54 #ifdef __cplusplus
    55 "C"
    56 #endif
    5754char *cgiPathInfo;
    58 extern
    59 #ifdef __cplusplus
    60 "C"
    61 #endif
    6255char *cgiPathTranslated;
    63 extern
    64 #ifdef __cplusplus
    65 "C"
    66 #endif
    6756char *cgiScriptName;
    68 extern
    69 #ifdef __cplusplus
    70 "C"
    71 #endif
    7257char *cgiQueryString;
    73 extern
    74 #ifdef __cplusplus
    75 "C"
    76 #endif
    7758char *cgiRemoteHost;
    78 extern
    79 #ifdef __cplusplus
    80 "C"
    81 #endif
    8259char *cgiRemoteAddr;
    83 extern
    84 #ifdef __cplusplus
    85 "C"
    86 #endif
    8760char *cgiAuthType;
    88 extern
    89 #ifdef __cplusplus
    90 "C"
    91 #endif
    9261char *cgiRemoteUser;
    93 extern
    94 #ifdef __cplusplus
    95 "C"
    96 #endif
    9762char *cgiRemoteIdent;
    98 extern
    99 #ifdef __cplusplus
    100 "C"
    101 #endif
    102 char *cgiContentType;
    103 extern
    104 #ifdef __cplusplus
    105 "C"
    106 #endif
     63char cgiContentTypeData[1024];
     64char *cgiContentType;// = cgiContentTypeData;
     65
     66char * cgiMultipartBoundary;
     67cgiFormEntry *cgiFormEntryFirst;
     68int cgiTreatUrlEncoding;
     69
    10770char *cgiAccept;
    108 extern
    109 #ifdef __cplusplus
    110 "C"
    111 #endif
    11271char *cgiUserAgent;
    113 extern
    114 #ifdef __cplusplus
    115 "C"
    116 #endif
    11772char *cgiReferrer;
    11873
    11974/* Cookies as sent to the server. You can also get them
    12075        individually, or as a string array; see the documentation. */
    121 extern
    122 #ifdef __cplusplus
    123 "C"
    124 #endif
    12576char *cgiCookie;
    126 
    127 extern
    128 #ifdef __cplusplus
    129 "C"
    130 #endif
    13177char *cgiSid;
    13278
     
    14086        directly from cgiIn; the programmer need not do so. */
    14187
    142 extern
    143 #ifdef __cplusplus
    144 "C"
    145 #endif
    14688int cgiContentLength;
    14789
     
    15294        cgiOut is always equivalent to stdout. */
    15395
    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 
     96char *cgiFindTarget;
     97cgiFormEntry *cgiFindPos;
     98
     99};
    170100/* Possible return codes from the cgiForm family of functions (see below). */
    171101
     
    195125#endif
    196126cgiFormResultType cgiFormString(
    197         char *name, char *result, int max);
     127        char *name, char *result, int max,struct cgi_env **);
    198128
    199129extern
     
    202132#endif
    203133cgiFormResultType cgiFormStringNoNewlines(
    204         char *name, char *result, int max);
     134        char *name, char *result, int max,struct cgi_env ** ce);
    205135
    206136
     
    210140#endif
    211141cgiFormResultType cgiFormStringSpaceNeeded(
    212         char *name, int *length);
     142        char *name, int *length,struct cgi_env ** ce);
    213143
    214144
     
    218148#endif
    219149cgiFormResultType cgiFormStringMultiple(
    220         char *name, char ***ptrToStringArray);
     150        char *name, char ***ptrToStringArray,struct cgi_env ** ce);
    221151
    222152extern
     
    231161#endif
    232162cgiFormResultType cgiFormInteger(
    233         char *name, int *result, int defaultV);
     163        char *name, int *result, int defaultV,struct cgi_env ** ce);
    234164
    235165extern
     
    238168#endif
    239169cgiFormResultType 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);
    241171
    242172extern
     
    245175#endif
    246176cgiFormResultType cgiFormDouble(
    247         char *name, double *result, double defaultV);
     177        char *name, double *result, double defaultV,struct cgi_env **);
    248178
    249179extern
     
    252182#endif
    253183cgiFormResultType 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);
    255185
    256186extern
     
    260190cgiFormResultType cgiFormSelectSingle(
    261191        char *name, char **choicesText, int choicesTotal,
    262         int *result, int defaultV);     
     192        int *result, int defaultV,struct cgi_env **ce);
    263193
    264194
     
    269199cgiFormResultType cgiFormSelectMultiple(
    270200        char *name, char **choicesText, int choicesTotal,
    271         int *result, int *invalid);
     201        int *result, int *invalid,struct cgi_env **);
    272202
    273203/* Just an alias; users have asked for this */
     
    279209#endif
    280210cgiFormResultType cgiFormCheckboxSingle(
    281         char *name);
     211        char *name,struct cgi_env ** ce);
    282212
    283213extern
     
    287217cgiFormResultType cgiFormCheckboxMultiple(
    288218        char *name, char **valuesText, int valuesTotal,
    289         int *result, int *invalid);
     219        int *result, int *invalid,struct cgi_env ** ce);
    290220
    291221extern
     
    295225cgiFormResultType cgiFormRadio(
    296226        char *name, char **valuesText, int valuesTotal,
    297         int *result, int defaultV);     
     227        int *result, int defaultV,struct cgi_env **ce);
    298228
    299229/* The paths returned by this function are the original names of files
     
    305235#endif
    306236cgiFormResultType cgiFormFileName(
    307         char *name, char *result, int max);
     237        char *name, char *result, int max,struct cgi_env **);
    308238
    309239/* The content type of the uploaded file, as reported by the browser.
     
    315245#endif
    316246cgiFormResultType cgiFormFileContentType(
    317         char *name, char *result, int max);
     247        char *name, char *result, int max,struct cgi_env ** ce);
    318248
    319249extern
     
    322252#endif
    323253cgiFormResultType cgiFormFileSize(
    324         char *name, int *sizeP);
     254        char *name, int *sizeP,struct cgi_env ** ce);
    325255
    326256typedef struct cgiFileStruct *cgiFilePtr;
     
    331261#endif
    332262cgiFormResultType cgiFormFileOpen(
    333         char *name, cgiFilePtr *cfpp);
     263        char *name, cgiFilePtr *cfpp,struct cgi_env ** ce);
    334264
    335265extern
     
    352282#endif
    353283cgiFormResultType cgiCookieString(
    354         char *name, char *result, int max);
     284        char *name, char *result, int max,char * cgiCookie);
    355285
    356286extern
     
    359289#endif
    360290cgiFormResultType cgiCookieInteger(
    361         char *name, int *result, int defaultV);
     291        char *name, int *result, int defaultV,char * cgiCookie);
    362292
    363293cgiFormResultType cgiCookies(
    364         char ***ptrToStringArray);
     294        char ***ptrToStringArray,char* cgiCookie);
    365295
    366296/* path can be null or empty in which case a path of / (entire site) is set.
     
    372302#endif
    373303void cgiHeaderCookieSetString(char *name, char *value,
    374         int secondsToLive, char *path, char *domain);
     304        int secondsToLive, char *path, char *domain,FCGX_Stream *out);
    375305extern
    376306#ifdef __cplusplus
     
    378308#endif
    379309void 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);
     311extern
     312#ifdef __cplusplus
     313"C"
     314#endif
     315void cgiHeaderLocation(char *redirectUrl,FCGX_Stream * out);
     316extern
     317#ifdef __cplusplus
     318"C"
     319#endif
     320void cgiHeaderStatus(int status, char *statusMessage,FCGX_Stream * out);
     321extern
     322#ifdef __cplusplus
     323"C"
     324#endif
     325void cgiHeaderContentType(char *mimeType,FCGX_Stream * out);
    396326
    397327typedef enum {
     
    421351#endif
    422352cgiFormResultType cgiFormEntries(
    423         char ***ptrToStringArray);
     353        char ***ptrToStringArray,struct cgi_env **ce);
    424354
    425355/* Output string with the <, &, and > characters HTML-escaped.
    426356        's' is null-terminated. Returns cgiFormIO in the event
    427357        of error, cgiFormSuccess otherwise. */
    428 cgiFormResultType cgiHtmlEscape(char *s);
     358cgiFormResultType cgiHtmlEscape(char *s,FCGX_Stream *out);
    429359
    430360/* Output data with the <, &, and > characters HTML-escaped.
     
    432362        bytes in 'data'. Returns cgiFormIO in the event
    433363        of error, cgiFormSuccess otherwise. */
    434 cgiFormResultType cgiHtmlEscapeData(char *data, int len);
     364cgiFormResultType cgiHtmlEscapeData(char *data, int len,FCGX_Stream *out);
    435365
    436366/* Output string with the " character HTML-escaped, and no
     
    439369        's' is null-terminated. Returns cgiFormIO in the event
    440370        of error, cgiFormSuccess otherwise. */
    441 cgiFormResultType cgiValueEscape(char *s);
     371cgiFormResultType cgiValueEscape(char *s,FCGX_Stream *out);
    442372
    443373/* Output data with the " character HTML-escaped, and no
     
    447377        bytes in 'data'. Returns cgiFormIO in the event
    448378        of error, cgiFormSuccess otherwise. */
    449 cgiFormResultType cgiValueEscapeData(char *data, int len);
    450 
    451 int cgiMain_init(int argc, char *argv[]);
    452 
    453 void cgiFreeResources();
     379cgiFormResultType cgiValueEscapeData(char *data, int len,FCGX_Stream *out);
     380
     381int cgiMain_init(int argc, char *argv[],struct cgi_env ** c,FCGX_Request *);
     382
     383void cgiFreeResources(struct cgi_env ** c);
    454384
    455385#endif /* CGI_C */
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png