1 /* The CGI_C library, by Thomas Boutell, version 2.01. CGI_C is intended
2 to be a high-quality API to simplify CGI programming tasks. */
4 /* Make sure this is only included once. */
9 /* Bring in standard I/O since some of the functions refer to
10 types defined by it, such as FILE *. */
14 /* The various CGI environment variables. Instead of using getenv(),
15 the programmer should refer to these, which are always
16 valid null-terminated strings (they may be empty, but they
17 will never be null). If these variables are used instead
18 of calling getenv(), then it will be possible to save
19 and restore CGI environments, which is highly convenient
22 extern char *cgiServerSoftware;
23 extern char *cgiServerName;
24 extern char *cgiGatewayInterface;
25 extern char *cgiServerProtocol;
26 extern char *cgiServerPort;
27 extern char *cgiRequestMethod;
28 extern char *cgiPathInfo;
29 extern char *cgiPathTranslated;
30 extern char *cgiScriptName;
31 extern char *cgiQueryString;
32 extern char *cgiRemoteHost;
33 extern char *cgiRemoteAddr;
34 extern char *cgiAuthType;
35 extern char *cgiRemoteUser;
36 extern char *cgiRemoteIdent;
37 extern char *cgiContentType;
38 extern char *cgiAccept;
39 extern char *cgiUserAgent;
40 extern char *cgiReferrer;
42 /* Cookies as sent to the server. You can also get them
43 individually, or as a string array; see the documentation. */
44 extern char *cgiCookie;
46 /* A macro providing the same incorrect spelling that is
47 found in the HTTP/CGI specifications */
48 #define cgiReferer cgiReferrer
50 /* The number of bytes of data received.
51 Note that if the submission is a form submission
52 the library will read and parse all the information
53 directly from cgiIn; the programmer need not do so. */
55 extern int cgiContentLength;
57 /* Pointer to CGI output. The cgiHeader functions should be used
58 first to output the mime headers; the output HTML
59 page, GIF image or other web document should then be written
60 to cgiOut by the programmer. In the standard CGIC library,
61 cgiOut is always equivalent to stdout. */
65 /* Pointer to CGI input. The programmer does not read from this.
66 We have continued to export it for backwards compatibility
67 so that cgic 1.x applications link properly. */
71 /* Possible return codes from the cgiForm family of functions (see below). */
90 /* These functions are used to retrieve form data. See
91 cgic.html for documentation. */
93 extern cgiFormResultType cgiFormString(
94 char *name, char *result, int max);
96 extern cgiFormResultType cgiFormStringNoNewlines(
97 char *name, char *result, int max);
100 extern cgiFormResultType cgiFormStringSpaceNeeded(
101 char *name, int *length);
104 extern cgiFormResultType cgiFormStringMultiple(
105 char *name, char ***ptrToStringArray);
107 extern void cgiStringArrayFree(char **stringArray);
109 extern cgiFormResultType cgiFormInteger(
110 char *name, int *result, int defaultV);
112 extern cgiFormResultType cgiFormIntegerBounded(
113 char *name, int *result, int min, int max, int defaultV);
115 extern cgiFormResultType cgiFormDouble(
116 char *name, double *result, double defaultV);
118 extern cgiFormResultType cgiFormDoubleBounded(
119 char *name, double *result, double min, double max, double defaultV);
121 extern cgiFormResultType cgiFormSelectSingle(
122 char *name, char **choicesText, int choicesTotal,
123 int *result, int defaultV);
126 extern cgiFormResultType cgiFormSelectMultiple(
127 char *name, char **choicesText, int choicesTotal,
128 int *result, int *invalid);
130 /* Just an alias; users have asked for this */
131 #define cgiFormSubmitClicked cgiFormCheckboxSingle
133 extern cgiFormResultType cgiFormCheckboxSingle(
136 extern cgiFormResultType cgiFormCheckboxMultiple(
137 char *name, char **valuesText, int valuesTotal,
138 int *result, int *invalid);
140 extern cgiFormResultType cgiFormRadio(
141 char *name, char **valuesText, int valuesTotal,
142 int *result, int defaultV);
144 /* The paths returned by this function are the original names of files
145 as reported by the uploading web browser and shoult NOT be
146 blindly assumed to be "safe" names for server-side use! */
147 extern cgiFormResultType cgiFormFileName(
148 char *name, char *result, int max);
150 /* The content type of the uploaded file, as reported by the browser.
151 It should NOT be assumed that browsers will never falsify
153 extern cgiFormResultType cgiFormFileContentType(
154 char *name, char *result, int max);
156 extern cgiFormResultType cgiFormFileSize(
157 char *name, int *sizeP);
159 typedef struct cgiFileStruct *cgiFilePtr;
161 extern cgiFormResultType cgiFormFileOpen(
162 char *name, cgiFilePtr *cfpp);
164 extern cgiFormResultType cgiFormFileRead(
165 cgiFilePtr cfp, char *buffer, int bufferSize, int *gotP);
167 extern cgiFormResultType cgiFormFileClose(
170 extern cgiFormResultType cgiCookieString(
171 char *name, char *result, int max);
173 extern cgiFormResultType cgiCookieInteger(
174 char *name, int *result, int defaultV);
176 cgiFormResultType cgiCookies(
177 char ***ptrToStringArray);
179 /* path can be null or empty in which case a path of / (entire site) is set.
180 domain can be a single web site; if it is an entire domain, such as
181 'boutell.com', it should begin with a dot: '.boutell.com' */
182 extern void cgiHeaderCookieSetString(char *name, char *value,
183 int secondsToLive, char *path, char *domain);
184 extern void cgiHeaderCookieSetInteger(char *name, int value,
185 int secondsToLive, char *path, char *domain);
186 extern void cgiHeaderLocation(char *redirectUrl);
187 extern void cgiHeaderStatus(int status, char *statusMessage);
188 extern void cgiHeaderContentType(char *mimeType);
192 cgiEnvironmentMemory,
193 cgiEnvironmentSuccess,
194 cgiEnvironmentWrongVersion
195 } cgiEnvironmentResultType;
197 extern cgiEnvironmentResultType cgiWriteEnvironment(char *filename);
198 extern cgiEnvironmentResultType cgiReadEnvironment(char *filename);
200 extern int cgiMain(void);
202 extern cgiFormResultType cgiFormEntries(
203 char ***ptrToStringArray);
205 /* Output string with the <, &, and > characters HTML-escaped.
206 's' is null-terminated. Returns cgiFormIO in the event
207 of error, cgiFormSuccess otherwise. */
208 cgiFormResultType cgiHtmlEscape(char *s);
210 /* Output data with the <, &, and > characters HTML-escaped.
211 'data' is not null-terminated; 'len' is the number of
212 bytes in 'data'. Returns cgiFormIO in the event
213 of error, cgiFormSuccess otherwise. */
214 cgiFormResultType cgiHtmlEscapeData(char *data, int len);
216 /* Output string with the " character HTML-escaped, and no
217 other characters escaped. This is useful when outputting
218 the contents of a tag attribute such as 'href' or 'src'.
219 's' is null-terminated. Returns cgiFormIO in the event
220 of error, cgiFormSuccess otherwise. */
221 cgiFormResultType cgiValueEscape(char *s);
223 /* Output data with the " character HTML-escaped, and no
224 other characters escaped. This is useful when outputting
225 the contents of a tag attribute such as 'href' or 'src'.
226 'data' is not null-terminated; 'len' is the number of
227 bytes in 'data'. Returns cgiFormIO in the event
228 of error, cgiFormSuccess otherwise. */
229 cgiFormResultType cgiValueEscapeData(char *data, int len);