1 /*
2     cgi.h - Routines for CGI programming
3     Copyright (c) 1996-8,2007,8  Martin Schulze <joey@infodrom.org>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software Foundation
17     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef _CGI_H_
21 #define _CGI_H_
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef struct var_s {
28 	char	*name,
29 		*value;
30 } s_var;
31 
32 typedef struct cookie_s {
33 	char	*version,
34 		*name,
35 		*value,
36 		*path,
37 		*domain;
38 } s_cookie;
39 
40 typedef struct file_s {
41 	char	*name,
42 		*type,
43 		*filename,
44 		*tmpfile;
45 } s_file;
46 
47 typedef struct cgi_s {
48 	s_var **vars;
49 	s_cookie **cookies;
50 	s_file **files;
51 } s_cgi;
52 
53 /* cgiSetHeader
54  *
55  *  Sets additional HTTP header lines to be printed with cgiHeader
56  */
57 int cgiSetHeader (const char *name, const char *value);
58 
59 /* cgiSetType
60  *
61  *  Sets result type for HTTP
62  */
63 int cgiSetType (const char *type);
64 
65 /* cgiHeader
66  *
67  *  Prints a valid CGI Header (Content-type...) etc.
68  */
69 void cgiHeader ();
70 
71 /* cgiDebug
72  *
73  *  Set/unsets debugging
74  */
75 void cgiDebug (int level, int where);
76 
77 /* cgiInit
78  *
79  *  Reads in variables set via POST or stdin, reads HTTP Cookies.
80  */
81 s_cgi *cgiInit ();
82 
83 /* cgiGetValue
84  *
85  *  Returns the value of the specified variable or NULL if it's empty
86  *  or doesn't exist.
87  */
88 char *cgiGetValue (s_cgi *parms, const char *name);
89 
90 /* cgiGetVariables
91  *
92  *  Returns the names of all form variables.
93  */
94 char **cgiGetVariables (s_cgi *parms);
95 
96 /* cgiRedirect
97  *
98  *  Provides a valid redirect for web pages.
99  */
100 void cgiRedirect (const char *url);
101 
102 /* cgiGetCookie
103  *
104  *  Returns the cookie referenced by the given name or NULL if it
105  *  doesn't exist or is empty.
106  */
107 s_cookie *cgiGetCookie (s_cgi *parms, const char *name);
108 
109 /* cgiGetCookies
110  *
111  * Returns a list of names of all cookies.
112  */
113 char **cgiGetCookies (s_cgi *parms);
114 
115 /* cgiGetFiles
116  *
117  * Returns a list of names of all files.
118  */
119 char **cgiGetFiles (s_cgi *parms);
120 
121 /* cgiGetFile
122  *
123  * Return data structure for CGI file variable
124  */
125 s_file *cgiGetFile (s_cgi *parms, const char *name);
126 
127 /* cgiFreeList
128  *
129  * Frees a list as returned by cgiGetVariables() and cgiGetCookies()
130  */
131 void cgiFreeList (char **list);
132 
133 /* cgiFree
134  *
135  * Frees the internal data structures
136  */
137 void cgiFree (s_cgi *parms);
138 
139 /* cgiEscape
140  *
141  * Escapes <&> in a string
142  */
143 char *cgiEscape (char *string);
144 
145 #ifdef __cplusplus
146 extern }
147 #endif
148 
149 #endif /* _CGI_H_ */
150