source: branches/PublicaMundi_David-devel/thirds/cgic206/cgic.h @ 677

Last change on this file since 677 was 548, checked in by david, 10 years ago
  • FCX_Stream integration
  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr
File size: 9.5 KB
RevLine 
[1]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. */
3
4/* Make sure this is only included once. */
5
6#ifndef CGI_C
7#define CGI_C 1
8
9/* Bring in standard I/O since some of the functions refer to
10        types defined by it, such as FILE *. */
11
[548]12//#include "fcgi_stdio.h"
13#include <fcgiapp.h>
14#include <stdio.h>
[1]15
16/* The various CGI environment variables. Instead of using getenv(),
17        the programmer should refer to these, which are always
18        valid null-terminated strings (they may be empty, but they
19        will never be null). If these variables are used instead
20        of calling getenv(), then it will be possible to save
21        and restore CGI environments, which is highly convenient
22        for debugging. */
23
[548]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;
[1]48char *cgiServerSoftware;
49char *cgiServerName;
50char *cgiGatewayInterface;
51char *cgiServerProtocol;
52char *cgiServerPort;
53char *cgiRequestMethod;
54char *cgiPathInfo;
55char *cgiPathTranslated;
56char *cgiScriptName;
57char *cgiQueryString;
58char *cgiRemoteHost;
59char *cgiRemoteAddr;
60char *cgiAuthType;
61char *cgiRemoteUser;
62char *cgiRemoteIdent;
[548]63char cgiContentTypeData[1024];
64char *cgiContentType;// = cgiContentTypeData;
65
66char * cgiMultipartBoundary;
67cgiFormEntry *cgiFormEntryFirst;
68int cgiTreatUrlEncoding;
69
[1]70char *cgiAccept;
71char *cgiUserAgent;
72char *cgiReferrer;
73
74/* Cookies as sent to the server. You can also get them
75        individually, or as a string array; see the documentation. */
76char *cgiCookie;
[216]77char *cgiSid;
78
[1]79/* A macro providing the same incorrect spelling that is
80        found in the HTTP/CGI specifications */
81#define cgiReferer cgiReferrer
82
83/* The number of bytes of data received.
84        Note that if the submission is a form submission
85        the library will read and parse all the information
86        directly from cgiIn; the programmer need not do so. */
87
88int cgiContentLength;
89
90/* Pointer to CGI output. The cgiHeader functions should be used
91        first to output the mime headers; the output HTML
92        page, GIF image or other web document should then be written
93        to cgiOut by the programmer. In the standard CGIC library,
94        cgiOut is always equivalent to stdout. */
95
[548]96char *cgiFindTarget;
97cgiFormEntry *cgiFindPos;
[1]98
[548]99};
[1]100/* Possible return codes from the cgiForm family of functions (see below). */
101
102typedef enum {
103        cgiFormSuccess,
104        cgiFormTruncated,
105        cgiFormBadType,
106        cgiFormEmpty,
107        cgiFormNotFound,
108        cgiFormConstrained,
109        cgiFormNoSuchChoice,
110        cgiFormMemory,
111        cgiFormNoFileName,
112        cgiFormNoContentType,
113        cgiFormNotAFile,
114        cgiFormOpenFailed,
115        cgiFormIO,
116        cgiFormEOF
117} cgiFormResultType;
118
119/* These functions are used to retrieve form data. See
120        cgic.html for documentation. */
121
122extern 
123#ifdef __cplusplus
124"C" 
125#endif
126cgiFormResultType cgiFormString(
[548]127        char *name, char *result, int max,struct cgi_env **);
[1]128
129extern 
130#ifdef __cplusplus
131"C" 
132#endif
133cgiFormResultType cgiFormStringNoNewlines(
[548]134        char *name, char *result, int max,struct cgi_env ** ce);
[1]135
136
137extern 
138#ifdef __cplusplus
139"C" 
140#endif
141cgiFormResultType cgiFormStringSpaceNeeded(
[548]142        char *name, int *length,struct cgi_env ** ce);
[1]143
144
145extern 
146#ifdef __cplusplus
147"C" 
148#endif
149cgiFormResultType cgiFormStringMultiple(
[548]150        char *name, char ***ptrToStringArray,struct cgi_env ** ce);
[1]151
152extern 
153#ifdef __cplusplus
154"C" 
155#endif
156void cgiStringArrayFree(char **stringArray);
157
158extern 
159#ifdef __cplusplus
160"C" 
161#endif
162cgiFormResultType cgiFormInteger(
[548]163        char *name, int *result, int defaultV,struct cgi_env ** ce);
[1]164
165extern 
166#ifdef __cplusplus
167"C" 
168#endif
169cgiFormResultType cgiFormIntegerBounded(
[548]170        char *name, int *result, int min, int max, int defaultV,struct cgi_env **ce);
[1]171
172extern 
173#ifdef __cplusplus
174"C" 
175#endif
176cgiFormResultType cgiFormDouble(
[548]177        char *name, double *result, double defaultV,struct cgi_env **);
[1]178
179extern 
180#ifdef __cplusplus
181"C" 
182#endif
183cgiFormResultType cgiFormDoubleBounded(
[548]184        char *name, double *result, double min, double max, double defaultV, struct cgi_env ** ce);
[1]185
186extern 
187#ifdef __cplusplus
188"C" 
189#endif
190cgiFormResultType cgiFormSelectSingle(
191        char *name, char **choicesText, int choicesTotal, 
[548]192        int *result, int defaultV,struct cgi_env **ce); 
[1]193
194
195extern 
196#ifdef __cplusplus
197"C" 
198#endif
199cgiFormResultType cgiFormSelectMultiple(
200        char *name, char **choicesText, int choicesTotal, 
[548]201        int *result, int *invalid,struct cgi_env **);
[1]202
203/* Just an alias; users have asked for this */
204#define cgiFormSubmitClicked cgiFormCheckboxSingle
205
206extern 
207#ifdef __cplusplus
208"C" 
209#endif
210cgiFormResultType cgiFormCheckboxSingle(
[548]211        char *name,struct cgi_env ** ce);
[1]212
213extern 
214#ifdef __cplusplus
215"C" 
216#endif
217cgiFormResultType cgiFormCheckboxMultiple(
218        char *name, char **valuesText, int valuesTotal, 
[548]219        int *result, int *invalid,struct cgi_env ** ce);
[1]220
221extern 
222#ifdef __cplusplus
223"C" 
224#endif
225cgiFormResultType cgiFormRadio(
226        char *name, char **valuesText, int valuesTotal, 
[548]227        int *result, int defaultV,struct cgi_env **ce); 
[1]228
229/* The paths returned by this function are the original names of files
230        as reported by the uploading web browser and shoult NOT be
231        blindly assumed to be "safe" names for server-side use! */
232extern 
233#ifdef __cplusplus
234"C" 
235#endif
236cgiFormResultType cgiFormFileName(
[548]237        char *name, char *result, int max,struct cgi_env **);
[1]238
239/* The content type of the uploaded file, as reported by the browser.
240        It should NOT be assumed that browsers will never falsify
241        such information. */
242extern 
243#ifdef __cplusplus
244"C" 
245#endif
246cgiFormResultType cgiFormFileContentType(
[548]247        char *name, char *result, int max,struct cgi_env ** ce);
[1]248
249extern 
250#ifdef __cplusplus
251"C" 
252#endif
253cgiFormResultType cgiFormFileSize(
[548]254        char *name, int *sizeP,struct cgi_env ** ce);
[1]255
256typedef struct cgiFileStruct *cgiFilePtr;
257
258extern 
259#ifdef __cplusplus
260"C" 
261#endif
262cgiFormResultType cgiFormFileOpen(
[548]263        char *name, cgiFilePtr *cfpp,struct cgi_env ** ce);
[1]264
265extern 
266#ifdef __cplusplus
267"C" 
268#endif
269cgiFormResultType cgiFormFileRead(
270        cgiFilePtr cfp, char *buffer, int bufferSize, int *gotP);
271
272extern 
273#ifdef __cplusplus
274"C" 
275#endif
276cgiFormResultType cgiFormFileClose(
277        cgiFilePtr cfp);
278
279extern 
280#ifdef __cplusplus
281"C" 
282#endif
283cgiFormResultType cgiCookieString(
[548]284        char *name, char *result, int max,char * cgiCookie);
[1]285
286extern 
287#ifdef __cplusplus
288"C" 
289#endif
290cgiFormResultType cgiCookieInteger(
[548]291        char *name, int *result, int defaultV,char * cgiCookie);
[1]292
293cgiFormResultType cgiCookies(
[548]294        char ***ptrToStringArray,char* cgiCookie);
[1]295
296/* path can be null or empty in which case a path of / (entire site) is set.
297        domain can be a single web site; if it is an entire domain, such as
298        'boutell.com', it should begin with a dot: '.boutell.com' */
299extern 
300#ifdef __cplusplus
301"C" 
302#endif
303void cgiHeaderCookieSetString(char *name, char *value, 
[548]304        int secondsToLive, char *path, char *domain,FCGX_Stream *out);
[1]305extern 
306#ifdef __cplusplus
307"C" 
308#endif
309void cgiHeaderCookieSetInteger(char *name, int value,
[548]310        int secondsToLive, char *path, char *domain,FCGX_Stream *out);
[1]311extern 
312#ifdef __cplusplus
313"C" 
314#endif
[548]315void cgiHeaderLocation(char *redirectUrl,FCGX_Stream * out);
[1]316extern 
317#ifdef __cplusplus
318"C" 
319#endif
[548]320void cgiHeaderStatus(int status, char *statusMessage,FCGX_Stream * out);
[1]321extern 
322#ifdef __cplusplus
323"C" 
324#endif
[548]325void cgiHeaderContentType(char *mimeType,FCGX_Stream * out);
[1]326
327typedef enum {
328        cgiEnvironmentIO,
329        cgiEnvironmentMemory,
330        cgiEnvironmentSuccess,
331        cgiEnvironmentWrongVersion
332} cgiEnvironmentResultType;
333
334extern 
335#ifdef __cplusplus
336"C" 
337#endif
338cgiEnvironmentResultType cgiWriteEnvironment(char *filename);
339extern cgiEnvironmentResultType cgiReadEnvironment(char *filename);
340
341extern 
342#ifdef __cplusplus
343"C" 
344#endif
345int cgiMain();
346extern 
347
348
349#ifdef __cplusplus
350"C" 
351#endif
352cgiFormResultType cgiFormEntries(
[548]353        char ***ptrToStringArray,struct cgi_env **ce);
[1]354
355/* Output string with the <, &, and > characters HTML-escaped.
356        's' is null-terminated. Returns cgiFormIO in the event
357        of error, cgiFormSuccess otherwise. */
[548]358cgiFormResultType cgiHtmlEscape(char *s,FCGX_Stream *out);
[1]359
360/* Output data with the <, &, and > characters HTML-escaped.
361        'data' is not null-terminated; 'len' is the number of
362        bytes in 'data'. Returns cgiFormIO in the event
363        of error, cgiFormSuccess otherwise. */
[548]364cgiFormResultType cgiHtmlEscapeData(char *data, int len,FCGX_Stream *out);
[1]365
366/* Output string with the " character HTML-escaped, and no
367        other characters escaped. This is useful when outputting
368        the contents of a tag attribute such as 'href' or 'src'.
369        's' is null-terminated. Returns cgiFormIO in the event
370        of error, cgiFormSuccess otherwise. */
[548]371cgiFormResultType cgiValueEscape(char *s,FCGX_Stream *out);
[1]372
373/* Output data with the " character HTML-escaped, and no
374        other characters escaped. This is useful when outputting
375        the contents of a tag attribute such as 'href' or 'src'.
376        'data' is not null-terminated; 'len' is the number of
377        bytes in 'data'. Returns cgiFormIO in the event
378        of error, cgiFormSuccess otherwise. */
[548]379cgiFormResultType cgiValueEscapeData(char *data, int len,FCGX_Stream *out);
[1]380
[548]381int cgiMain_init(int argc, char *argv[],struct cgi_env ** c,FCGX_Request *);
[511]382
[548]383void cgiFreeResources(struct cgi_env ** c);
[511]384
[1]385#endif /* CGI_C */
386
Note: See TracBrowser for help on using the repository browser.

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