-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 | |||
@@ -34,36 +34,73 @@ namespace kingate { | |||
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. |
@@ -127,28 +164,42 @@ namespace kingate { | |||
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 | */ |
@@ -168,25 +219,25 @@ namespace kingate { | |||
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) |