-rw-r--r-- | include/kingate/cgi_gateway.h | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/include/kingate/cgi_gateway.h b/include/kingate/cgi_gateway.h index f20d72b..a26b0ae 100644 --- a/include/kingate/cgi_gateway.h +++ b/include/kingate/cgi_gateway.h | |||
@@ -22,60 +22,97 @@ namespace kingate { | |||
22 | using namespace std; | 22 | using namespace std; |
23 | 23 | ||
24 | /** | 24 | /** |
25 | * The main class interfacing with the CGI environment. | 25 | * The main class interfacing with the CGI environment. |
26 | */ | 26 | */ |
27 | class cgi_gateway { | 27 | class cgi_gateway { |
28 | public: | 28 | public: |
29 | /** | 29 | /** |
30 | * The interface to CGI environment (e.g. fastcgi). | 30 | * The interface to CGI environment (e.g. fastcgi). |
31 | */ | 31 | */ |
32 | cgi_interface& iface; | 32 | cgi_interface& iface; |
33 | /** | 33 | /** |
34 | * The type describing map holding parameters parsed from query string or input. | 34 | * The type describing map holding parameters parsed from query string or input. |
35 | */ | 35 | */ |
36 | typedef multimap<string,string> params_t; | 36 | typedef multimap<string,string> params_t; |
37 | /** | 37 | /** |
38 | * The GET-passed parameters. | 38 | * The GET-passed parameters. |
39 | */ | 39 | */ |
40 | params_t get; | 40 | params_t get; |
41 | /** | 41 | /** |
42 | * The POST-passed parameters. | 42 | * The POST-passed parameters. |
43 | */ | 43 | */ |
44 | params_t post; | 44 | params_t post; |
45 | /** | 45 | /** |
46 | * Abstract base class for retrieving posted files. | ||
47 | */ | ||
48 | class basic_file_t { | ||
49 | public: | ||
50 | /** | ||
51 | * Retrieve file name. | ||
52 | * @return filename | ||
53 | */ | ||
54 | virtual const string& filename() const = 0; | ||
55 | /** | ||
56 | * Retrieve file content type. | ||
57 | * @return content type | ||
58 | */ | ||
59 | virtual const string& content_type() const = 0; | ||
60 | /** | ||
61 | * Retrieve file contents. | ||
62 | * @return reference to the stream for accessing file content. | ||
63 | */ | ||
64 | virtual istream& content() = 0; | ||
65 | virtual ~basic_file_t(); | ||
66 | }; | ||
67 | typedef basic_file_t *file_t; | ||
68 | /** | ||
69 | * The map holding information pertaining to files uploaded via post. | ||
70 | */ | ||
71 | typedef multimap<string,file_t> files_t; | ||
72 | /** | ||
73 | * Files uploaded via post | ||
74 | */ | ||
75 | files_t files; | ||
76 | /** | ||
46 | * Cookies passed. | 77 | * Cookies passed. |
47 | */ | 78 | */ |
48 | cookies_t cookies; | 79 | cookies_t cookies; |
49 | /** | 80 | /** |
50 | * Was the stdin content parsed? | 81 | * Was the stdin content parsed? |
51 | */ | 82 | */ |
52 | bool b_parsed_content; | 83 | bool b_parsed_content; |
53 | 84 | ||
54 | /** | 85 | /** |
55 | * @param ci the interface to use. | 86 | * @param ci the interface to use. |
56 | */ | 87 | */ |
57 | cgi_gateway(cgi_interface& ci); | 88 | cgi_gateway(cgi_interface& ci,bool parsebody = true); |
89 | virtual ~cgi_gateway() throw(); | ||
90 | |||
91 | /** | ||
92 | * Parse request body. | ||
93 | */ | ||
94 | void parse_request_body(); | ||
58 | 95 | ||
59 | /** | 96 | /** |
60 | * Check whether there is an 'environment' meta-variable with specific name | 97 | * Check whether there is an 'environment' meta-variable with specific name |
61 | * passed to CGI. | 98 | * passed to CGI. |
62 | * @param n variable name. | 99 | * @param n variable name. |
63 | * @return true if yes. | 100 | * @return true if yes. |
64 | * @see cgi_interface::has_meta() | 101 | * @see cgi_interface::has_meta() |
65 | * @see get_meta() | 102 | * @see get_meta() |
66 | */ | 103 | */ |
67 | bool has_meta(const string& n) const { return iface.has_meta(n); } | 104 | bool has_meta(const string& n) const { return iface.has_meta(n); } |
68 | /** | 105 | /** |
69 | * Retrieve the 'environment' meta-variable value. | 106 | * Retrieve the 'environment' meta-variable value. |
70 | * @param n variable name. | 107 | * @param n variable name. |
71 | * @return variable contents. | 108 | * @return variable contents. |
72 | * @see exception_notfound | 109 | * @see exception_notfound |
73 | * @see cgi_interface::get_meta() | 110 | * @see cgi_interface::get_meta() |
74 | */ | 111 | */ |
75 | const string& get_meta(const string& n) const { return iface.get_meta(n); } | 112 | const string& get_meta(const string& n) const { return iface.get_meta(n); } |
76 | 113 | ||
77 | /** | 114 | /** |
78 | * fetch reference to the 'stdin' stream. | 115 | * fetch reference to the 'stdin' stream. |
79 | * @return the reference to the corresponding istream object. | 116 | * @return the reference to the corresponding istream object. |
80 | * @see cgi_interface::in() | 117 | * @see cgi_interface::in() |
81 | */ | 118 | */ |
@@ -115,90 +152,104 @@ namespace kingate { | |||
115 | /** | 152 | /** |
116 | * Check to see whether the parameter was passed via POST. | 153 | * Check to see whether the parameter was passed via POST. |
117 | * @param n the parameter name. | 154 | * @param n the parameter name. |
118 | * @return true if yes. | 155 | * @return true if yes. |
119 | */ | 156 | */ |
120 | bool has_POST(const string& n) const; | 157 | bool has_POST(const string& n) const; |
121 | /** | 158 | /** |
122 | * Retrieve the POST-parameter. | 159 | * Retrieve the POST-parameter. |
123 | * @param n the parameter name. | 160 | * @param n the parameter name. |
124 | * @return the parameter contents. | 161 | * @return the parameter contents. |
125 | * @see exception_notfound | 162 | * @see exception_notfound |
126 | */ | 163 | */ |
127 | const string& get_POST(const string& n) const; | 164 | const string& get_POST(const string& n) const; |
128 | /** | 165 | /** |
129 | * Check to see whether the parameter was passed either via POST or | 166 | * Check to see whether the parameter was passed either via POST or |
130 | * GET. | 167 | * GET. |
131 | * @param n the parameter name. | 168 | * @param n the parameter name. |
132 | * @return true if yes. | 169 | * @return true if yes. |
133 | */ | 170 | */ |
134 | bool has_param(const string& n) const; | 171 | bool has_param(const string& n) const; |
135 | /** | 172 | /** |
136 | * Retrieve the parameter passed either via POST or GET | 173 | * Retrieve the parameter passed either via POST or GET |
137 | * (GET-parameter takes precedence). | 174 | * (GET-parameter takes precedence). |
138 | * @param n the parameter name. | 175 | * @param n the parameter name. |
139 | * @return true if yes. | 176 | * @return the parameter contents. |
140 | * @see exception_notfound. | 177 | * @see exception_notfound. |
141 | */ | 178 | */ |
142 | const string& get_param(const string& n) const; | 179 | const string& get_param(const string& n) const; |
180 | /** | ||
181 | * Check to see whether the file was uploaded in the request body. | ||
182 | * @param n the parameter name. | ||
183 | * @return true if yes. | ||
184 | */ | ||
185 | bool has_file(const string& n) const; | ||
186 | /** | ||
187 | * Retrieve the file uploaded in the request body. | ||
188 | * @param n the parameter name. | ||
189 | * @return the file. | ||
190 | * @see exception_notfound. | ||
191 | */ | ||
192 | const file_t get_file(const string& n) const; | ||
193 | file_t get_file(const string& n); | ||
143 | 194 | ||
144 | /** | 195 | /** |
145 | * Retrieve the POST content-type (as passed via CONTENT_TYPE | 196 | * Retrieve the POST content-type (as passed via CONTENT_TYPE |
146 | * environment variable). | 197 | * environment variable). |
147 | * @return the content type. | 198 | * @return the content type. |
148 | */ | 199 | */ |
149 | const string& __deprecated get_content_type() const; | 200 | const string& __deprecated get_content_type() const; |
150 | /** | 201 | /** |
151 | * Retrieve the POST content length (as passed via the | 202 | * Retrieve the POST content length (as passed via the |
152 | * CONTENT_LENGTH environment variable). | 203 | * CONTENT_LENGTH environment variable). |
153 | * @return the content length. | 204 | * @return the content length. |
154 | */ | 205 | */ |
155 | unsigned long __deprecated get_content_length() const; | 206 | unsigned long __deprecated get_content_length() const; |
156 | 207 | ||
157 | /** | 208 | /** |
158 | * Check to see whether the content from stdin stream was parsed. | 209 | * Check to see whether the content from stdin stream was parsed. |
159 | * @return true if yes. | 210 | * @return true if yes. |
160 | */ | 211 | */ |
161 | bool is_content_parsed() const { return b_parsed_content; } | 212 | bool is_content_parsed() const { return b_parsed_content; } |
162 | 213 | ||
163 | /** | 214 | /** |
164 | * Retrieve the HTTP header value from the HTTP_ meta-variable. | 215 | * Retrieve the HTTP header value from the HTTP_ meta-variable. |
165 | * (see RFC3875) | 216 | * (see RFC3875) |
166 | * @param hn header field name. | 217 | * @param hn header field name. |
167 | * @return the HTTP header value. | 218 | * @return the HTTP header value. |
168 | */ | 219 | */ |
169 | const string& http_request_header(const string& hn) const; | 220 | const string& http_request_header(const string& hn) const; |
170 | 221 | ||
171 | /** | 222 | /** |
172 | * Retrieve the AUTH_TYPE meta-variable (see RFC3875) | 223 | * Retrieve the AUTH_TYPE meta-variable (see RFC3875) |
173 | * @return authentication type. | 224 | * @return authentication type. |
174 | */ | 225 | */ |
175 | const string& auth_type() const; | 226 | const string& auth_type() const; |
176 | /** | 227 | /** |
177 | * Retrieve the CONTENT_LENGTH meta-variable (see RFC3875) | 228 | * Retrieve the CONTENT_LENGTH meta-variable (see RFC3875) |
178 | * @return size of the request message body. | 229 | * @return size of the request message body. |
179 | */ | 230 | */ |
180 | unsigned long cgi_gateway::content_length() const; | 231 | unsigned long content_length() const; |
181 | /** | 232 | /** |
182 | * Retrieve the CONTENT_TYPE meta-variable (see RFC3875) | 233 | * Retrieve the CONTENT_TYPE meta-variable (see RFC3875) |
183 | * @return media type of the request message body. | 234 | * @return media type of the request message body. |
184 | */ | 235 | */ |
185 | const string& content_type() const; | 236 | const string& content_type() const; |
186 | /** | 237 | /** |
187 | * Retrieve the GATEWAY_INTERFACE meta-variable (see RFC3875) | 238 | * Retrieve the GATEWAY_INTERFACE meta-variable (see RFC3875) |
188 | * @return the gateway interface dialect. | 239 | * @return the gateway interface dialect. |
189 | */ | 240 | */ |
190 | const string& gateway_interface() const; | 241 | const string& gateway_interface() const; |
191 | /** | 242 | /** |
192 | * Retrieve the PATH_INFO meta-variable (see RFC3875) | 243 | * Retrieve the PATH_INFO meta-variable (see RFC3875) |
193 | * @return path to be interpreted by the script. | 244 | * @return path to be interpreted by the script. |
194 | */ | 245 | */ |
195 | const string& path_info() const; | 246 | const string& path_info() const; |
196 | /** | 247 | /** |
197 | * Retrieve the PATH_TRANSLATED meta-variable (see RFC3875) | 248 | * Retrieve the PATH_TRANSLATED meta-variable (see RFC3875) |
198 | * @return the translated path to the document. | 249 | * @return the translated path to the document. |
199 | */ | 250 | */ |
200 | const string& path_translated() const; | 251 | const string& path_translated() const; |
201 | /** | 252 | /** |
202 | * Retrieve the QUERY_STRING meta-variable (see RFC3875) | 253 | * Retrieve the QUERY_STRING meta-variable (see RFC3875) |
203 | * @return the query string. | 254 | * @return the query string. |
204 | */ | 255 | */ |