#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"
#define cgicTempDir "/tmp" |
Referenced by getTempFileName().
#define CGICDEBUGSTART |
Referenced by cgiFormSelectSingle(), cgiFormStringMultiple(), and main().
#define CGICDEBUGEND |
Referenced by cgiFormSelectSingle(), cgiFormStringMultiple(), and main().
#define cgiStrEq | ( | a, | ||
b | ||||
) | (!strcmp((a), (b))) |
Referenced by cgiFormSelectMultiple(), and cgiFormSelectSingle().
#define APPEND | ( | string, | ||
char | ||||
) |
{ \ if ((string##Len + 1) < string##Space) { \ string[string##Len++] = (char); \ } \ }
Referenced by cgiFormFileContentType(), cgiFormFileName(), and decomposeValue().
#define RAPPEND | ( | string, | ||
ch | ||||
) |
{ \ 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 | ) |
{ \ 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 | ) |
{ \ if (putc((ch), cgiOut) == EOF) { \ return cgiFormIO; \ } \ }
Referenced by cgiHtmlEscapeData(), and cgiValueEscapeData().
typedef struct cgiFormEntryStruct cgiFormEntry |
typedef struct mpStream * mpStreamPtr |
typedef struct cgiFileStruct cgiFile |
enum cgiParseResultType |
enum cgiEscapeState |
static void cgiGetenv | ( | char ** | s, | |
char * | var | |||
) | [static] |
static cgiParseResultType cgiParseGetFormInput | ( | ) | [static] |
References cgiContentLength, cgiParseFormInput(), and cgiQueryString.
Referenced by main().
static cgiParseResultType cgiParsePostFormInput | ( | ) | [static] |
References cgiContentLength, cgiIn, and cgiParseFormInput().
Referenced by main().
static cgiParseResultType cgiParsePostMultipartInput | ( | ) | [static] |
References afterNextBoundary(), cgiFormEntryStruct::attr, cgiContentLength, cgiParseIO, cgiParseSuccess, cgiStrEqNc(), cgiFormEntryStruct::contentType, decomposeValue(), cgiFormEntryStruct::fileName, getTempFileName(), mpPutBack(), mpRead(), cgiFormEntryStruct::next, readHeaderLine(), cgiFormEntryStruct::tfileName, cgiFormEntryStruct::value, and cgiFormEntryStruct::valueLength.
Referenced by main().
static cgiParseResultType cgiParseFormInput | ( | char * | data, | |
int | length | |||
) | [static] |
References cgiFormEntryStruct::attr, cgiUnescapeChars(), cgiUnescapeSuccess, cgiFormEntryStruct::contentType, cgiFormEntryStruct::fileName, cgiFormEntryStruct::next, cgiFormEntryStruct::tfileName, cgiFormEntryStruct::value, and cgiFormEntryStruct::valueLength.
Referenced by cgiParseGetFormInput(), and cgiParsePostFormInput().
static void cgiSetupConstants | ( | ) | [static] |
static void cgiFreeResources | ( | ) | [static] |
References cgiFormEntryStruct::attr, cgiAccept, cgiAuthType, cgiContentType, cgiGatewayInterface, cgiPathInfo, cgiPathTranslated, cgiQueryString, cgiReferrer, cgiRemoteAddr, cgiRemoteHost, cgiRemoteIdent, cgiRemoteUser, cgiRequestMethod, cgiRestored, cgiScriptName, cgiServerName, cgiServerPort, cgiServerProtocol, cgiServerSoftware, cgiUserAgent, cgiFormEntryStruct::contentType, cgiFormEntryStruct::fileName, cgiFormEntryStruct::next, cgiFormEntryStruct::tfileName, and cgiFormEntryStruct::value.
Referenced by cgiReadEnvironment(), and main().
static int cgiStrEqNc | ( | char * | s1, | |
char * | s2 | |||
) | [static] |
Referenced by cgiParsePostMultipartInput(), decomposeValue(), and main().
static int cgiStrBeginsNc | ( | char * | s1, | |
char * | s2 | |||
) | [static] |
int main | ( | int | argc, | |
char * | argv[] | |||
) |
References cgiAccept, cgiAuthType, CGICDEBUGEND, CGICDEBUGSTART, cgiContentLength, cgiContentType, cgiContentTypeData, cgiCookie, cgiFreeResources(), cgiGatewayInterface, cgiGetenv(), cgiIn, cgiMain(), cgiMultipartBoundary, cgiOut, cgiParseGetFormInput(), cgiParsePostFormInput(), cgiParsePostMultipartInput(), cgiParseSuccess, cgiPathInfo, cgiPathTranslated, cgiQueryString, cgiReferrer, cgiRemoteAddr, cgiRemoteHost, cgiRemoteIdent, cgiRemoteUser, cgiRequestMethod, cgiRestored, cgiScriptName, cgiServerName, cgiServerPort, cgiServerProtocol, cgiServerSoftware, cgiSetupConstants(), cgiStrBeginsNc(), cgiStrEqNc(), and cgiUserAgent.
int mpRead | ( | mpStreamPtr | mpp, | |
char * | buffer, | |||
int | len | |||
) |
References cgiContentLength, cgiIn, mpStream::offset, mpStream::putback, mpStream::readPos, and mpStream::writePos.
Referenced by afterNextBoundary(), cgiParsePostMultipartInput(), and readHeaderLine().
void mpPutBack | ( | mpStreamPtr | mpp, | |
char * | data, | |||
int | len | |||
) |
References mpStream::offset, mpStream::putback, and mpStream::writePos.
Referenced by afterNextBoundary(), cgiParsePostMultipartInput(), and readHeaderLine().
cgiParseResultType afterNextBoundary | ( | mpStreamPtr | mpp, | |
FILE * | outf, | |||
char ** | outP, | |||
int * | bodyLengthP, | |||
int | first | |||
) | [static] |
References BAPPEND, cgiMultipartBoundary, mpPutBack(), and mpRead().
Referenced by cgiParsePostMultipartInput().
static int readHeaderLine | ( | mpStreamPtr | mpp, | |
char * | attr, | |||
int | attrSpace, | |||
char * | value, | |||
int | valueSpace | |||
) | [static] |
References mpPutBack(), and mpRead().
Referenced by cgiParsePostMultipartInput().
static void decomposeValue | ( | char * | value, | |
char * | mvalue, | |||
int | mvalueSpace, | |||
char ** | argNames, | |||
char ** | argValues, | |||
int | argValueSpace | |||
) | [static] |
References APPEND, and cgiStrEqNc().
Referenced by cgiParsePostMultipartInput().
static cgiParseResultType getTempFileName | ( | char * | tfileName | ) | [static] |
References cgicTempDir.
Referenced by cgiParsePostMultipartInput(), and cgiReadEnvironment().
cgiUnescapeResultType cgiUnescapeChars | ( | char ** | sp, | |
char * | cp, | |||
int | len | |||
) | [static] |
References cgiEscapeFirst, cgiEscapeRest, cgiEscapeSecond, and cgiHexValue.
Referenced by cgiParseFormInput().
static cgiFormResultType cgiFormEntryString | ( | cgiFormEntry * | e, | |
char * | result, | |||
int | max, | |||
int | newlines | |||
) | [static] |
References cgiFormEntryStruct::value.
Referenced by cgiFormString(), cgiFormStringMultiple(), and cgiFormStringNoNewlines().
static cgiFormEntry * cgiFormEntryFindFirst | ( | char * | name | ) | [static] |
References cgiFindTarget, and cgiFormEntryFindNext().
Referenced by cgiFormCheckboxSingle(), cgiFormDouble(), cgiFormFileContentType(), cgiFormFileName(), cgiFormFileOpen(), cgiFormFileSize(), cgiFormInteger(), cgiFormSelectMultiple(), cgiFormSelectSingle(), cgiFormString(), cgiFormStringMultiple(), cgiFormStringNoNewlines(), and cgiFormStringSpaceNeeded().
static cgiFormEntry * cgiFormEntryFindNext | ( | ) | [static] |
References cgiFindTarget, and cgiFormEntryStruct::next.
Referenced by cgiFormEntryFindFirst(), cgiFormSelectMultiple(), and cgiFormStringMultiple().
cgiFormResultType cgiFormString | ( | char * | name, | |
char * | result, | |||
int | max | |||
) |
References cgiFormEntryFindFirst(), and cgiFormEntryString().
cgiFormResultType cgiFormFileName | ( | char * | name, | |
char * | result, | |||
int | resultSpace | |||
) |
References APPEND, cgiFormEntryFindFirst(), and cgiFormEntryStruct::fileName.
cgiFormResultType cgiFormFileContentType | ( | char * | name, | |
char * | result, | |||
int | resultSpace | |||
) |
References APPEND, cgiFormEntryFindFirst(), and cgiFormEntryStruct::contentType.
cgiFormResultType cgiFormFileSize | ( | char * | name, | |
int * | sizeP | |||
) |
References cgiFormEntryFindFirst(), cgiFormEntryStruct::tfileName, and cgiFormEntryStruct::valueLength.
cgiFormResultType cgiFormFileOpen | ( | char * | name, | |
cgiFilePtr * | cfpp | |||
) |
References cgiFormEntryFindFirst(), cgiFileStruct::in, and cgiFormEntryStruct::tfileName.
Referenced by cgiWriteEnvironment().
cgiFormResultType cgiFormFileRead | ( | cgiFilePtr | cfp, | |
char * | buffer, | |||
int | bufferSize, | |||
int * | gotP | |||
) |
References cgiFileStruct::in.
Referenced by cgiWriteEnvironment().
cgiFormResultType cgiFormFileClose | ( | cgiFilePtr | cfp | ) |
References cgiFileStruct::in.
Referenced by cgiWriteEnvironment().
cgiFormResultType cgiFormStringNoNewlines | ( | char * | name, | |
char * | result, | |||
int | max | |||
) |
References cgiFormEntryFindFirst(), and cgiFormEntryString().
Referenced by ReadFromHtml().
cgiFormResultType cgiFormStringMultiple | ( | char * | name, | |
char *** | result | |||
) |
References CGICDEBUGEND, CGICDEBUGSTART, cgiFormEntryFindFirst(), cgiFormEntryFindNext(), cgiFormEntryString(), cgiStringArrayFree(), and cgiFormEntryStruct::value.
cgiFormResultType cgiFormStringSpaceNeeded | ( | char * | name, | |
int * | result | |||
) |
References cgiFormEntryFindFirst(), and cgiFormEntryStruct::value.
static int cgiFirstNonspaceChar | ( | char * | s | ) | [static] |
cgiFormResultType cgiFormInteger | ( | char * | name, | |
int * | result, | |||
int | defaultV | |||
) |
References cgiFirstNonspaceChar(), cgiFormEntryFindFirst(), and cgiFormEntryStruct::value.
Referenced by cgiFormIntegerBounded(), and ReadFromHtml().
cgiFormResultType cgiFormIntegerBounded | ( | char * | name, | |
int * | result, | |||
int | min, | |||
int | max, | |||
int | defaultV | |||
) |
cgiFormResultType cgiFormDouble | ( | char * | name, | |
double * | result, | |||
double | defaultV | |||
) |
References cgiFirstNonspaceChar(), cgiFormEntryFindFirst(), and cgiFormEntryStruct::value.
Referenced by cgiFormDoubleBounded().
cgiFormResultType cgiFormDoubleBounded | ( | char * | name, | |
double * | result, | |||
double | min, | |||
double | max, | |||
double | defaultV | |||
) |
cgiFormResultType cgiFormSelectSingle | ( | char * | name, | |
char ** | choicesText, | |||
int | choicesTotal, | |||
int * | result, | |||
int | defaultV | |||
) |
References CGICDEBUGEND, CGICDEBUGSTART, cgiFormEntryFindFirst(), and cgiStrEq.
Referenced by cgiFormRadio().
cgiFormResultType cgiFormSelectMultiple | ( | char * | name, | |
char ** | choicesText, | |||
int | choicesTotal, | |||
int * | result, | |||
int * | invalid | |||
) |
References cgiFormEntryFindFirst(), cgiFormEntryFindNext(), cgiStrEq, and cgiFormEntryStruct::value.
Referenced by cgiFormCheckboxMultiple().
cgiFormResultType cgiFormCheckboxSingle | ( | char * | name | ) |
cgiFormResultType cgiFormCheckboxMultiple | ( | char * | name, | |
char ** | valuesText, | |||
int | valuesTotal, | |||
int * | result, | |||
int * | invalid | |||
) |
cgiFormResultType cgiFormRadio | ( | char * | name, | |
char ** | valuesText, | |||
int | valuesTotal, | |||
int * | result, | |||
int | defaultV | |||
) |
cgiFormResultType cgiCookieString | ( | char * | name, | |
char * | value, | |||
int | space | |||
) |
cgiFormResultType cgiCookieInteger | ( | char * | name, | |
int * | result, | |||
int | defaultV | |||
) |
void cgiHeaderCookieSetInteger | ( | char * | name, | |
int | value, | |||
int | secondsToLive, | |||
char * | path, | |||
char * | domain | |||
) |
void cgiHeaderCookieSetString | ( | char * | name, | |
char * | value, | |||
int | secondsToLive, | |||
char * | path, | |||
char * | domain | |||
) |
References cgiOut, days, and months.
Referenced by cgiHeaderCookieSetInteger().
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().
static int cgiWriteInt | ( | FILE * | out, | |
int | i | |||
) | [static] |
Referenced by cgiWriteEnvironment(), and cgiWriteString().
cgiEnvironmentResultType cgiWriteEnvironment | ( | char * | filename | ) |
static int cgiReadString | ( | FILE * | out, | |
char ** | s | |||
) | [static] |
References cgiReadInt().
Referenced by cgiReadEnvironment().
static int cgiReadInt | ( | FILE * | out, | |
int * | i | |||
) | [static] |
Referenced by cgiReadEnvironment(), and cgiReadString().
cgiEnvironmentResultType cgiReadEnvironment | ( | char * | filename | ) |
void cgiStringArrayFree | ( | char ** | stringArray | ) |
Referenced by cgiCookies(), cgiFormEntries(), and cgiFormStringMultiple().
cgiFormResultType cgiCookies | ( | char *** | result | ) |
cgiFormResultType cgiFormEntries | ( | char *** | result | ) |
References cgiFormEntryStruct::attr, cgiStringArrayFree(), and cgiFormEntryStruct::next.
cgiFormResultType cgiHtmlEscapeData | ( | char * | data, | |
int | len | |||
) |
cgiFormResultType cgiHtmlEscape | ( | char * | s | ) |
cgiFormResultType cgiValueEscapeData | ( | char * | data, | |
int | len | |||
) |
cgiFormResultType cgiValueEscape | ( | char * | s | ) |
char* cgiServerSoftware |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiServerName |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiGatewayInterface |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiServerProtocol |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiServerPort |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiRequestMethod |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiPathInfo |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiPathTranslated |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiScriptName |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiQueryString |
Referenced by cgiFreeResources(), cgiParseGetFormInput(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiRemoteHost |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiRemoteAddr |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiAuthType |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiRemoteUser |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiRemoteIdent |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char cgiContentTypeData[1024] |
Referenced by main().
char* cgiContentType = cgiContentTypeData |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiMultipartBoundary |
Referenced by afterNextBoundary(), and main().
char* cgiCookie |
Referenced by cgiCookies(), cgiCookieString(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
int cgiContentLength |
char* cgiAccept |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiUserAgent |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
char* cgiReferrer |
Referenced by cgiFreeResources(), cgiReadEnvironment(), cgiWriteEnvironment(), and main().
FILE* cgiIn |
Referenced by cgiParsePostFormInput(), main(), and mpRead().
FILE* cgiOut |
Referenced by cgiHeaderContentType(), cgiHeaderCookieSetString(), cgiHeaderLocation(), cgiHeaderStatus(), and main().
int cgiRestored = 0 [static] |
Referenced by cgiFreeResources(), cgiReadEnvironment(), and main().
cgiFormEntry* cgiFormEntryFirst [static] |
int cgiHexValue[256] [static] |
Referenced by cgiSetupConstants(), and cgiUnescapeChars().
char* days[] |
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
Referenced by cgiHeaderCookieSetString().
char* months[] |
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
char* cgiFindTarget = 0 [static] |
Referenced by cgiFormEntryFindFirst(), and cgiFormEntryFindNext().
cgiFormEntry* cgiFindPos = 0 [static] |