Classes | Defines | Typedefs | Enumerations | Functions | Variables

cgic.c File Reference

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "cgic.h"
Include dependency graph for cgic.c:

Classes

Defines

Typedefs

Enumerations

Functions

Variables


Define Documentation

#define cgicTempDir   "/tmp"

Referenced by getTempFileName().

#define CGICDEBUGSTART
#define CGICDEBUGEND
#define cgiStrEq (   a,
  b 
)    (!strcmp((a), (b)))
#define APPEND (   string,
  char 
)
Value:
{ \
                if ((string##Len + 1) < string##Space) { \
                        string[string##Len++] = (char); \
                } \
        }

Referenced by cgiFormFileContentType(), cgiFormFileName(), and decomposeValue().

#define RAPPEND (   string,
  ch 
)
Value:
{ \
                if ((string##Len + 1) == string##Space)  { \
                        char *sold = string; \
                        string##Space *= 2; \
                        string = (char *) realloc(string, string##Space); \
                        if (!string) { \
                                string = sold; \
                                goto outOfMemory; \
                        } \
                } \
                string[string##Len++] = (ch); \
        }
#define BAPPEND (   ch  ) 
Value:
{ \
                if (outf) { \
                        putc(ch, outf); \
                        outLen++; \
                } else if (out) { \
                        RAPPEND(out, ch); \
                } \
        }

Referenced by afterNextBoundary().

#define CGIC_VERSION   "2.0"

Referenced by cgiReadEnvironment().

#define TRYPUTC (   ch  ) 
Value:
{ \
                if (putc((ch), cgiOut) == EOF) { \
                        return cgiFormIO; \
                } \
        }

Referenced by cgiHtmlEscapeData(), and cgiValueEscapeData().


Typedef Documentation

typedef struct mpStream * mpStreamPtr
typedef struct cgiFileStruct cgiFile

Enumeration Type Documentation

Enumerator:
cgiParseSuccess 
cgiParseMemory 
cgiParseIO 
cgiParseSuccess 
cgiParseMemory 
cgiParseIO 
Enumerator:
cgiEscapeRest 
cgiEscapeFirst 
cgiEscapeSecond 
cgiEscapeRest 
cgiEscapeFirst 
cgiEscapeSecond 
Enumerator:
cgiUnescapeSuccess 
cgiUnescapeMemory 
cgiUnescapeSuccess 
cgiUnescapeMemory 

Function Documentation

static void cgiGetenv ( char **  s,
char *  var 
) [static]

Referenced by main().

Here is the caller graph for this function:

static cgiParseResultType cgiParseGetFormInput (  )  [static]

References cgiContentLength, cgiParseFormInput(), and cgiQueryString.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

static cgiParseResultType cgiParsePostFormInput (  )  [static]

References cgiContentLength, cgiIn, and cgiParseFormInput().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

static cgiParseResultType cgiParsePostMultipartInput (  )  [static]
static cgiParseResultType cgiParseFormInput ( char *  data,
int  length 
) [static]
static void cgiSetupConstants (  )  [static]

References cgiHexValue.

Referenced by main().

Here is the caller graph for this function:

static void cgiFreeResources (  )  [static]
static int cgiStrEqNc ( char *  s1,
char *  s2 
) [static]

Referenced by cgiParsePostMultipartInput(), decomposeValue(), and main().

Here is the caller graph for this function:

static int cgiStrBeginsNc ( char *  s1,
char *  s2 
) [static]

Referenced by main().

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)
int mpRead ( mpStreamPtr  mpp,
char *  buffer,
int  len 
)
void mpPutBack ( mpStreamPtr  mpp,
char *  data,
int  len 
)

References mpStream::offset, mpStream::putback, and mpStream::writePos.

Referenced by afterNextBoundary(), cgiParsePostMultipartInput(), and readHeaderLine().

Here is the caller graph for this function:

cgiParseResultType afterNextBoundary ( mpStreamPtr  mpp,
FILE *  outf,
char **  outP,
int *  bodyLengthP,
int  first 
) [static]

References BAPPEND, cgiMultipartBoundary, mpPutBack(), and mpRead().

Referenced by cgiParsePostMultipartInput().

Here is the call graph for this function:

Here is the caller graph for this function:

static int readHeaderLine ( mpStreamPtr  mpp,
char *  attr,
int  attrSpace,
char *  value,
int  valueSpace 
) [static]

References mpPutBack(), and mpRead().

Referenced by cgiParsePostMultipartInput().

Here is the call graph for this function:

Here is the caller graph for this function:

static void decomposeValue ( char *  value,
char *  mvalue,
int  mvalueSpace,
char **  argNames,
char **  argValues,
int  argValueSpace 
) [static]

References APPEND, and cgiStrEqNc().

Referenced by cgiParsePostMultipartInput().

Here is the call graph for this function:

Here is the caller graph for this function:

static cgiParseResultType getTempFileName ( char *  tfileName  )  [static]

References cgicTempDir.

Referenced by cgiParsePostMultipartInput(), and cgiReadEnvironment().

Here is the caller graph for this function:

cgiUnescapeResultType cgiUnescapeChars ( char **  sp,
char *  cp,
int  len 
) [static]

References cgiEscapeFirst, cgiEscapeRest, cgiEscapeSecond, and cgiHexValue.

Referenced by cgiParseFormInput().

Here is the caller graph for this function:

static cgiFormResultType cgiFormEntryString ( cgiFormEntry e,
char *  result,
int  max,
int  newlines 
) [static]

References cgiFormEntryStruct::value.

Referenced by cgiFormString(), cgiFormStringMultiple(), and cgiFormStringNoNewlines().

Here is the caller graph for this function:

static cgiFormEntry * cgiFormEntryFindFirst ( char *  name  )  [static]
static cgiFormEntry * cgiFormEntryFindNext (  )  [static]

References cgiFindTarget, and cgiFormEntryStruct::next.

Referenced by cgiFormEntryFindFirst(), cgiFormSelectMultiple(), and cgiFormStringMultiple().

Here is the caller graph for this function:

cgiFormResultType cgiFormString ( char *  name,
char *  result,
int  max 
)

References cgiFormEntryFindFirst(), and cgiFormEntryString().

Here is the call graph for this function:

cgiFormResultType cgiFormFileName ( char *  name,
char *  result,
int  resultSpace 
)

References APPEND, cgiFormEntryFindFirst(), and cgiFormEntryStruct::fileName.

Here is the call graph for this function:

cgiFormResultType cgiFormFileContentType ( char *  name,
char *  result,
int  resultSpace 
)

References APPEND, cgiFormEntryFindFirst(), and cgiFormEntryStruct::contentType.

Here is the call graph for this function:

cgiFormResultType cgiFormFileSize ( char *  name,
int *  sizeP 
)

References cgiFormEntryFindFirst(), cgiFormEntryStruct::tfileName, and cgiFormEntryStruct::valueLength.

Here is the call graph for this function:

cgiFormResultType cgiFormFileOpen ( char *  name,
cgiFilePtr cfpp 
)

References cgiFormEntryFindFirst(), cgiFileStruct::in, and cgiFormEntryStruct::tfileName.

Referenced by cgiWriteEnvironment().

Here is the call graph for this function:

Here is the caller graph for this function:

cgiFormResultType cgiFormFileRead ( cgiFilePtr  cfp,
char *  buffer,
int  bufferSize,
int *  gotP 
)

References cgiFileStruct::in.

Referenced by cgiWriteEnvironment().

Here is the caller graph for this function:

cgiFormResultType cgiFormFileClose ( cgiFilePtr  cfp  ) 

References cgiFileStruct::in.

Referenced by cgiWriteEnvironment().

Here is the caller graph for this function:

cgiFormResultType cgiFormStringNoNewlines ( char *  name,
char *  result,
int  max 
)

References cgiFormEntryFindFirst(), and cgiFormEntryString().

Referenced by ReadFromHtml().

Here is the call graph for this function:

Here is the caller graph for this function:

cgiFormResultType cgiFormStringMultiple ( char *  name,
char ***  result 
)
cgiFormResultType cgiFormStringSpaceNeeded ( char *  name,
int *  result 
)

References cgiFormEntryFindFirst(), and cgiFormEntryStruct::value.

Here is the call graph for this function:

static int cgiFirstNonspaceChar ( char *  s  )  [static]

Referenced by cgiFormDouble(), and cgiFormInteger().

Here is the caller graph for this function:

cgiFormResultType cgiFormInteger ( char *  name,
int *  result,
int  defaultV 
)

References cgiFirstNonspaceChar(), cgiFormEntryFindFirst(), and cgiFormEntryStruct::value.

Referenced by cgiFormIntegerBounded(), and ReadFromHtml().

Here is the call graph for this function:

Here is the caller graph for this function:

cgiFormResultType cgiFormIntegerBounded ( char *  name,
int *  result,
int  min,
int  max,
int  defaultV 
)

References cgiFormInteger(), and cgiFormSuccess.

Here is the call graph for this function:

cgiFormResultType cgiFormDouble ( char *  name,
double *  result,
double  defaultV 
)

References cgiFirstNonspaceChar(), cgiFormEntryFindFirst(), and cgiFormEntryStruct::value.

Referenced by cgiFormDoubleBounded().

Here is the call graph for this function:

Here is the caller graph for this function:

cgiFormResultType cgiFormDoubleBounded ( char *  name,
double *  result,
double  min,
double  max,
double  defaultV 
)

References cgiFormDouble(), and cgiFormSuccess.

Here is the call graph for this function:

cgiFormResultType cgiFormSelectSingle ( char *  name,
char **  choicesText,
int  choicesTotal,
int *  result,
int  defaultV 
)

References CGICDEBUGEND, CGICDEBUGSTART, cgiFormEntryFindFirst(), and cgiStrEq.

Referenced by cgiFormRadio().

Here is the call graph for this function:

Here is the caller graph for this function:

cgiFormResultType cgiFormSelectMultiple ( char *  name,
char **  choicesText,
int  choicesTotal,
int *  result,
int *  invalid 
)

References cgiFormEntryFindFirst(), cgiFormEntryFindNext(), cgiStrEq, and cgiFormEntryStruct::value.

Referenced by cgiFormCheckboxMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

cgiFormResultType cgiFormCheckboxSingle ( char *  name  ) 

References cgiFormEntryFindFirst().

Here is the call graph for this function:

cgiFormResultType cgiFormCheckboxMultiple ( char *  name,
char **  valuesText,
int  valuesTotal,
int *  result,
int *  invalid 
)

References cgiFormSelectMultiple().

Here is the call graph for this function:

cgiFormResultType cgiFormRadio ( char *  name,
char **  valuesText,
int  valuesTotal,
int *  result,
int  defaultV 
)

References cgiFormSelectSingle().

Here is the call graph for this function:

cgiFormResultType cgiCookieString ( char *  name,
char *  value,
int  space 
)

References cgiCookie.

Referenced by cgiCookieInteger().

Here is the caller graph for this function:

cgiFormResultType cgiCookieInteger ( char *  name,
int *  result,
int  defaultV 
)

References cgiCookieString(), and cgiFormSuccess.

Here is the call graph for this function:

void cgiHeaderCookieSetInteger ( char *  name,
int  value,
int  secondsToLive,
char *  path,
char *  domain 
)

References cgiHeaderCookieSetString().

Here is the call graph for this function:

void cgiHeaderCookieSetString ( char *  name,
char *  value,
int  secondsToLive,
char *  path,
char *  domain 
)

References cgiOut, days, and months.

Referenced by cgiHeaderCookieSetInteger().

Here is the caller graph for this function:

void cgiHeaderLocation ( char *  redirectUrl  ) 

References cgiOut.

void cgiHeaderStatus ( int  status,
char *  statusMessage 
)

References cgiOut.

void cgiHeaderContentType ( char *  mimeType  ) 

References cgiOut.

static int cgiWriteString ( FILE *  out,
char *  s 
) [static]

References cgiWriteInt().

Referenced by cgiWriteEnvironment().

Here is the call graph for this function:

Here is the caller graph for this function:

static int cgiWriteInt ( FILE *  out,
int  i 
) [static]

Referenced by cgiWriteEnvironment(), and cgiWriteString().

Here is the caller graph for this function:

cgiEnvironmentResultType cgiWriteEnvironment ( char *  filename  ) 
static int cgiReadString ( FILE *  out,
char **  s 
) [static]

References cgiReadInt().

Referenced by cgiReadEnvironment().

Here is the call graph for this function:

Here is the caller graph for this function:

static int cgiReadInt ( FILE *  out,
int *  i 
) [static]

Referenced by cgiReadEnvironment(), and cgiReadString().

Here is the caller graph for this function:

cgiEnvironmentResultType cgiReadEnvironment ( char *  filename  ) 
void cgiStringArrayFree ( char **  stringArray  ) 

Referenced by cgiCookies(), cgiFormEntries(), and cgiFormStringMultiple().

Here is the caller graph for this function:

cgiFormResultType cgiCookies ( char ***  result  ) 

References cgiCookie, and cgiStringArrayFree().

Here is the call graph for this function:

cgiFormResultType cgiFormEntries ( char ***  result  ) 

References cgiFormEntryStruct::attr, cgiStringArrayFree(), and cgiFormEntryStruct::next.

Here is the call graph for this function:

cgiFormResultType cgiHtmlEscapeData ( char *  data,
int  len 
)

References TRYPUTC.

Referenced by cgiHtmlEscape().

Here is the caller graph for this function:

cgiFormResultType cgiHtmlEscape ( char *  s  ) 

References cgiHtmlEscapeData().

Here is the call graph for this function:

cgiFormResultType cgiValueEscapeData ( char *  data,
int  len 
)

References TRYPUTC.

Referenced by cgiValueEscape().

Here is the caller graph for this function:

cgiFormResultType cgiValueEscape ( char *  s  ) 

References cgiValueEscapeData().

Here is the call graph for this function:


Variable Documentation

char* cgiPathInfo
char* cgiAuthType
char cgiContentTypeData[1024]

Referenced by main().

Referenced by afterNextBoundary(), and main().

char* cgiCookie
char* cgiAccept
char* cgiUserAgent
char* cgiReferrer
FILE* cgiIn

Referenced by cgiParsePostFormInput(), main(), and mpRead().

FILE* cgiOut
int cgiRestored = 0 [static]
int cgiHexValue[256] [static]
char* days[]
Initial value:
 {
        "Sun",
        "Mon",
        "Tue",
        "Wed",
        "Thu",
        "Fri",
        "Sat"
}

Referenced by cgiHeaderCookieSetString().

char* months[]
Initial value:
 {
        "Jan",
        "Feb",
        "Mar",
        "Apr",
        "May",
        "Jun",
        "Jul",
        "Aug",
        "Sep",
        "Oct",
        "Nov",
        "Dec"
}
char* cgiFindTarget = 0 [static]
cgiFormEntry* cgiFindPos = 0 [static]