cgic.h

00001 /* The CGI_C library, by Thomas Boutell, version 2.01. CGI_C is intended
00002   to be a high-quality API to simplify CGI programming tasks. */
00003 
00004 /* Make sure this is only included once. */
00005 
00006 #ifndef CGI_C
00007 #define CGI_C 1
00008 
00009 /* Bring in standard I/O since some of the functions refer to
00010   types defined by it, such as FILE *. */
00011 
00012 #include <stdio.h>
00013 
00014 /* The various CGI environment variables. Instead of using getenv(),
00015   the programmer should refer to these, which are always
00016   valid null-terminated strings (they may be empty, but they 
00017   will never be null). If these variables are used instead
00018   of calling getenv(), then it will be possible to save
00019   and restore CGI environments, which is highly convenient
00020   for debugging. */
00021 
00022 extern char *cgiServerSoftware;
00023 extern char *cgiServerName;
00024 extern char *cgiGatewayInterface;
00025 extern char *cgiServerProtocol;
00026 extern char *cgiServerPort;
00027 extern char *cgiRequestMethod;
00028 extern char *cgiPathInfo;
00029 extern char *cgiPathTranslated;
00030 extern char *cgiScriptName;
00031 extern char *cgiQueryString;
00032 extern char *cgiRemoteHost;
00033 extern char *cgiRemoteAddr;
00034 extern char *cgiAuthType;
00035 extern char *cgiRemoteUser;
00036 extern char *cgiRemoteIdent;
00037 extern char *cgiContentType;
00038 extern char *cgiAccept;
00039 extern char *cgiUserAgent;
00040 extern char *cgiReferrer;
00041 
00042 /* Cookies as sent to the server. You can also get them
00043   individually, or as a string array; see the documentation. */
00044 extern char *cgiCookie;
00045 
00046 /* A macro providing the same incorrect spelling that is
00047   found in the HTTP/CGI specifications */
00048 #define cgiReferer cgiReferrer
00049 
00050 /* The number of bytes of data received.
00051   Note that if the submission is a form submission
00052   the library will read and parse all the information
00053   directly from cgiIn; the programmer need not do so. */
00054 
00055 extern int cgiContentLength;
00056 
00057 /* Pointer to CGI output. The cgiHeader functions should be used
00058   first to output the mime headers; the output HTML
00059   page, GIF image or other web document should then be written
00060   to cgiOut by the programmer. In the standard CGIC library,
00061   cgiOut is always equivalent to stdout. */
00062 
00063 extern FILE *cgiOut;
00064 
00065 /* Pointer to CGI input. The programmer does not read from this.
00066   We have continued to export it for backwards compatibility
00067   so that cgic 1.x applications link properly. */
00068 
00069 extern FILE *cgiIn;
00070 
00071 /* Possible return codes from the cgiForm family of functions (see below). */
00072 
00073 typedef enum {
00074   cgiFormSuccess,
00075   cgiFormTruncated,
00076   cgiFormBadType,
00077   cgiFormEmpty,
00078   cgiFormNotFound,
00079   cgiFormConstrained,
00080   cgiFormNoSuchChoice,
00081   cgiFormMemory,
00082   cgiFormNoFileName,
00083   cgiFormNoContentType,
00084   cgiFormNotAFile,
00085   cgiFormOpenFailed,
00086   cgiFormIO,
00087   cgiFormEOF
00088 } cgiFormResultType;
00089 
00090 /* These functions are used to retrieve form data. See
00091   cgic.html for documentation. */
00092 
00093 extern cgiFormResultType cgiFormString(
00094   char *name, char *result, int max);
00095 
00096 extern cgiFormResultType cgiFormStringNoNewlines(
00097   char *name, char *result, int max);
00098 
00099 
00100 extern cgiFormResultType cgiFormStringSpaceNeeded(
00101   char *name, int *length);
00102 
00103 
00104 extern cgiFormResultType cgiFormStringMultiple(
00105   char *name, char ***ptrToStringArray);
00106 
00107 extern void cgiStringArrayFree(char **stringArray);
00108 
00109 extern cgiFormResultType cgiFormInteger(
00110   char *name, int *result, int defaultV);
00111 
00112 extern cgiFormResultType cgiFormIntegerBounded(
00113   char *name, int *result, int min, int max, int defaultV);
00114 
00115 extern cgiFormResultType cgiFormDouble(
00116   char *name, double *result, double defaultV);
00117 
00118 extern cgiFormResultType cgiFormDoubleBounded(
00119   char *name, double *result, double min, double max, double defaultV);
00120 
00121 extern cgiFormResultType cgiFormSelectSingle(
00122   char *name, char **choicesText, int choicesTotal, 
00123   int *result, int defaultV); 
00124 
00125 
00126 extern cgiFormResultType cgiFormSelectMultiple(
00127   char *name, char **choicesText, int choicesTotal, 
00128   int *result, int *invalid);
00129 
00130 /* Just an alias; users have asked for this */
00131 #define cgiFormSubmitClicked cgiFormCheckboxSingle
00132 
00133 extern cgiFormResultType cgiFormCheckboxSingle(
00134   char *name);
00135 
00136 extern cgiFormResultType cgiFormCheckboxMultiple(
00137   char *name, char **valuesText, int valuesTotal, 
00138   int *result, int *invalid);
00139 
00140 extern cgiFormResultType cgiFormRadio(
00141   char *name, char **valuesText, int valuesTotal, 
00142   int *result, int defaultV); 
00143 
00144 /* The paths returned by this function are the original names of files
00145   as reported by the uploading web browser and shoult NOT be
00146   blindly assumed to be "safe" names for server-side use! */
00147 extern cgiFormResultType cgiFormFileName(
00148   char *name, char *result, int max);
00149 
00150 /* The content type of the uploaded file, as reported by the browser.
00151   It should NOT be assumed that browsers will never falsify
00152   such information. */
00153 extern cgiFormResultType cgiFormFileContentType(
00154   char *name, char *result, int max);
00155 
00156 extern cgiFormResultType cgiFormFileSize(
00157   char *name, int *sizeP);
00158 
00159 typedef struct cgiFileStruct *cgiFilePtr;
00160 
00161 extern cgiFormResultType cgiFormFileOpen(
00162   char *name, cgiFilePtr *cfpp);
00163 
00164 extern cgiFormResultType cgiFormFileRead(
00165   cgiFilePtr cfp, char *buffer, int bufferSize, int *gotP);
00166 
00167 extern cgiFormResultType cgiFormFileClose(
00168   cgiFilePtr cfp);
00169 
00170 extern cgiFormResultType cgiCookieString(
00171   char *name, char *result, int max);
00172 
00173 extern cgiFormResultType cgiCookieInteger(
00174   char *name, int *result, int defaultV);
00175 
00176 cgiFormResultType cgiCookies(
00177   char ***ptrToStringArray);
00178 
00179 /* path can be null or empty in which case a path of / (entire site) is set. 
00180   domain can be a single web site; if it is an entire domain, such as
00181   'boutell.com', it should begin with a dot: '.boutell.com' */
00182 extern void cgiHeaderCookieSetString(char *name, char *value, 
00183   int secondsToLive, char *path, char *domain);
00184 extern void cgiHeaderCookieSetInteger(char *name, int value,
00185   int secondsToLive, char *path, char *domain);
00186 extern void cgiHeaderLocation(char *redirectUrl);
00187 extern void cgiHeaderStatus(int status, char *statusMessage);
00188 extern void cgiHeaderContentType(char *mimeType);
00189 
00190 typedef enum {
00191   cgiEnvironmentIO,
00192   cgiEnvironmentMemory,
00193   cgiEnvironmentSuccess,
00194   cgiEnvironmentWrongVersion
00195 } cgiEnvironmentResultType;
00196 
00197 extern cgiEnvironmentResultType cgiWriteEnvironment(char *filename);
00198 extern cgiEnvironmentResultType cgiReadEnvironment(char *filename);
00199 
00200 extern int cgiMain();
00201 
00202 extern cgiFormResultType cgiFormEntries(
00203   char ***ptrToStringArray);
00204 
00205 /* Output string with the <, &, and > characters HTML-escaped. 
00206   's' is null-terminated. Returns cgiFormIO in the event
00207   of error, cgiFormSuccess otherwise. */
00208 cgiFormResultType cgiHtmlEscape(char *s);
00209 
00210 /* Output data with the <, &, and > characters HTML-escaped. 
00211   'data' is not null-terminated; 'len' is the number of
00212   bytes in 'data'. Returns cgiFormIO in the event
00213   of error, cgiFormSuccess otherwise. */
00214 cgiFormResultType cgiHtmlEscapeData(char *data, int len);
00215 
00216 /* Output string with the " character HTML-escaped, and no
00217   other characters escaped. This is useful when outputting
00218   the contents of a tag attribute such as 'href' or 'src'.
00219   's' is null-terminated. Returns cgiFormIO in the event
00220   of error, cgiFormSuccess otherwise. */
00221 cgiFormResultType cgiValueEscape(char *s);
00222 
00223 /* Output data with the " character HTML-escaped, and no
00224   other characters escaped. This is useful when outputting
00225   the contents of a tag attribute such as 'href' or 'src'.
00226   'data' is not null-terminated; 'len' is the number of
00227   bytes in 'data'. Returns cgiFormIO in the event
00228   of error, cgiFormSuccess otherwise. */
00229 cgiFormResultType cgiValueEscapeData(char *data, int len);
00230 
00231 #endif /* CGI_C */
00232 

Generated on Thu Oct 28 10:59:07 2004 for gitk by doxygen 1.3.6