/src/httpd/include/http_protocol.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Licensed to the Apache Software Foundation (ASF) under one or more |
2 | | * contributor license agreements. See the NOTICE file distributed with |
3 | | * this work for additional information regarding copyright ownership. |
4 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
5 | | * (the "License"); you may not use this file except in compliance with |
6 | | * the License. You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | /** |
18 | | * @file http_protocol.h |
19 | | * @brief HTTP protocol handling |
20 | | * |
21 | | * @defgroup APACHE_CORE_PROTO HTTP Protocol Handling |
22 | | * @ingroup APACHE_CORE |
23 | | * @{ |
24 | | */ |
25 | | |
26 | | #ifndef APACHE_HTTP_PROTOCOL_H |
27 | | #define APACHE_HTTP_PROTOCOL_H |
28 | | |
29 | | #include "httpd.h" |
30 | | #include "apr_portable.h" |
31 | | #include "apr_mmap.h" |
32 | | #include "apr_buckets.h" |
33 | | #include "util_filter.h" |
34 | | |
35 | | #ifdef __cplusplus |
36 | | extern "C" { |
37 | | #endif |
38 | | |
39 | | /** |
40 | | * This hook allows modules to insert filters for the current error response |
41 | | * @param r the current request |
42 | | * @ingroup hooks |
43 | | */ |
44 | | AP_DECLARE_HOOK(void,insert_error_filter,(request_rec *r)) |
45 | | |
46 | | /** This is an optimization. We keep a record of the filter_rec that |
47 | | * stores the old_write filter, so that we can avoid strcmp's later. |
48 | | */ |
49 | | AP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func; |
50 | | |
51 | | /* |
52 | | * Prototypes for routines which either talk directly back to the user, |
53 | | * or control the ones that eventually do. |
54 | | */ |
55 | | |
56 | | /** |
57 | | * Read an empty request and set reasonable defaults. |
58 | | * @param c The current connection |
59 | | * @return The new request_rec |
60 | | */ |
61 | | AP_DECLARE(request_rec *) ap_create_request(conn_rec *c); |
62 | | |
63 | | /** |
64 | | * Read a request and fill in the fields. |
65 | | * @param c The current connection |
66 | | * @return The new request_rec |
67 | | */ |
68 | | AP_DECLARE(request_rec *) ap_read_request(conn_rec *c); |
69 | | |
70 | | /** |
71 | | * Assign the method, uri and protocol (in HTTP/1.x the |
72 | | * items from the first line) to the request. |
73 | | * @param r The current request |
74 | | * @param method the HTTP method |
75 | | * @param uri the request uri |
76 | | * @param protocol the request protocol |
77 | | * @return 1 on success, 0 on failure |
78 | | */ |
79 | | AP_DECLARE(int) ap_assign_request_line(request_rec *r, |
80 | | const char *method, const char *uri, |
81 | | const char *protocol); |
82 | | |
83 | | /** |
84 | | * Parse a HTTP/1.x request line, validate and return the components |
85 | | * @param r The current request |
86 | | * @param line the line to parse |
87 | | * @param pmethod the parsed method on success |
88 | | * @param puri the parsed uri on success |
89 | | * @param pprotocol the parsed protocol on success |
90 | | * @return 1 on success, 0 on failure |
91 | | */ |
92 | | AP_DECLARE(int) ap_h1_tokenize_request_line( |
93 | | request_rec *r, const char *line, |
94 | | const char **pmethod, const char **puri, const char **pprotocol); |
95 | | |
96 | | /** |
97 | | * Parse and validate the request line. |
98 | | * @param r The current request |
99 | | * @return 1 on success, 0 on failure |
100 | | */ |
101 | | AP_DECLARE(int) ap_parse_request_line(request_rec *r); |
102 | | |
103 | | /** |
104 | | * Validate the request header and select vhost. |
105 | | * @param r The current request |
106 | | * @return 1 on success, 0 on failure |
107 | | */ |
108 | | AP_DECLARE(int) ap_check_request_header(request_rec *r); |
109 | | |
110 | | /** |
111 | | * Read the mime-encoded headers. |
112 | | * @param r The current request |
113 | | */ |
114 | | AP_DECLARE(void) ap_get_mime_headers(request_rec *r); |
115 | | |
116 | | /** |
117 | | * Optimized version of ap_get_mime_headers() that requires a |
118 | | * temporary brigade to work with |
119 | | * @param r The current request |
120 | | * @param bb temp brigade |
121 | | */ |
122 | | AP_DECLARE(void) ap_get_mime_headers_core(request_rec *r, |
123 | | apr_bucket_brigade *bb); |
124 | | |
125 | | /** |
126 | | * Run post_read_request hook and validate. |
127 | | * @param r The current request |
128 | | * @return OK or HTTP_... |
129 | | */ |
130 | | AP_DECLARE(int) ap_post_read_request(request_rec *r); |
131 | | |
132 | | /* Finish up stuff after a request */ |
133 | | |
134 | | /** |
135 | | * Called at completion of sending the response. It sends the terminating |
136 | | * protocol information. |
137 | | * @param r The current request |
138 | | */ |
139 | | AP_DECLARE(void) ap_finalize_request_protocol(request_rec *r); |
140 | | |
141 | | /** |
142 | | * Send error back to client. |
143 | | * @param r The current request |
144 | | * @param recursive_error last arg indicates error status in case we get |
145 | | * an error in the process of trying to deal with an ErrorDocument |
146 | | * to handle some other error. In that case, we print the default |
147 | | * report for the first thing that went wrong, and more briefly report |
148 | | * on the problem with the ErrorDocument. |
149 | | */ |
150 | | AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error); |
151 | | |
152 | | /* Set last modified header line from the lastmod date of the associated file. |
153 | | * Also, set content length. |
154 | | * |
155 | | * May return an error status, typically HTTP_NOT_MODIFIED (that when the |
156 | | * permit_cache argument is set to one). |
157 | | */ |
158 | | |
159 | | /** |
160 | | * Set the content length for this request |
161 | | * @param r The current request |
162 | | * @param length The new content length |
163 | | */ |
164 | | AP_DECLARE(void) ap_set_content_length(request_rec *r, apr_off_t length); |
165 | | |
166 | | /** |
167 | | * Set the keepalive status for this request |
168 | | * @param r The current request |
169 | | * @return 1 if keepalive can be set, 0 otherwise |
170 | | */ |
171 | | AP_DECLARE(int) ap_set_keepalive(request_rec *r); |
172 | | |
173 | | /** |
174 | | * Return the latest rational time from a request/mtime pair. Mtime is |
175 | | * returned unless it's in the future, in which case we return the current time. |
176 | | * @param r The current request |
177 | | * @param mtime The last modified time |
178 | | * @return the latest rational time. |
179 | | */ |
180 | | AP_DECLARE(apr_time_t) ap_rationalize_mtime(request_rec *r, apr_time_t mtime); |
181 | | |
182 | | /** |
183 | | * Build the content-type that should be sent to the client from the |
184 | | * content-type specified. The following rules are followed: |
185 | | * - if type is NULL or "", return NULL (do not set content-type). |
186 | | * - if charset adding is disabled, stop processing and return type. |
187 | | * - then, if there are no parameters on type, add the default charset |
188 | | * - return type |
189 | | * @param r The current request |
190 | | * @param type The content type |
191 | | * @return The content-type |
192 | | */ |
193 | | AP_DECLARE(const char *) ap_make_content_type(request_rec *r, |
194 | | const char *type); |
195 | | |
196 | | /** |
197 | | * Precompile metadata structures used by ap_make_content_type() |
198 | | * @param pool The pool to use for allocations |
199 | | */ |
200 | | AP_DECLARE(void) ap_setup_make_content_type(apr_pool_t *pool); |
201 | | |
202 | | /** A structure with the ingredients for a file based etag */ |
203 | | typedef struct etag_rec etag_rec; |
204 | | |
205 | | /** |
206 | | * @brief A structure with the ingredients for a file based etag |
207 | | */ |
208 | | struct etag_rec { |
209 | | /** Optional vary list validator */ |
210 | | const char *vlist_validator; |
211 | | /** Time when the request started */ |
212 | | apr_time_t request_time; |
213 | | /** finfo.protection (st_mode) set to zero if no such file */ |
214 | | apr_finfo_t *finfo; |
215 | | /** File pathname used when generating a digest */ |
216 | | const char *pathname; |
217 | | /** File descriptor used when generating a digest */ |
218 | | apr_file_t *fd; |
219 | | /** Force a non-digest etag to be weak */ |
220 | | int force_weak; |
221 | | }; |
222 | | |
223 | | /** |
224 | | * Construct an entity tag from the resource information. If it's a real |
225 | | * file, build in some of the file characteristics. |
226 | | * @param r The current request |
227 | | * @param force_weak Force the entity tag to be weak - it could be modified |
228 | | * again in as short an interval. |
229 | | * @return The entity tag |
230 | | */ |
231 | | AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak); |
232 | | |
233 | | /** |
234 | | * Construct an entity tag from information provided in the etag_rec |
235 | | * structure. |
236 | | * @param r The current request |
237 | | * @param er The etag record, containing ingredients for the etag. |
238 | | */ |
239 | | AP_DECLARE(char *) ap_make_etag_ex(request_rec *r, etag_rec *er); |
240 | | |
241 | | /** |
242 | | * Set the E-tag outgoing header |
243 | | * @param r The current request |
244 | | */ |
245 | | AP_DECLARE(void) ap_set_etag(request_rec *r); |
246 | | |
247 | | /** |
248 | | * Set the E-tag outgoing header, with the option of forcing a strong ETag. |
249 | | * @param r The current request |
250 | | * @param fd The file descriptor |
251 | | */ |
252 | | AP_DECLARE(void) ap_set_etag_fd(request_rec *r, apr_file_t *fd); |
253 | | |
254 | | /** |
255 | | * Set the last modified time for the file being sent |
256 | | * @param r The current request |
257 | | */ |
258 | | AP_DECLARE(void) ap_set_last_modified(request_rec *r); |
259 | | |
260 | | typedef enum { |
261 | | AP_CONDITION_NONE, |
262 | | AP_CONDITION_NOMATCH, |
263 | | AP_CONDITION_WEAK, |
264 | | AP_CONDITION_STRONG |
265 | | } ap_condition_e; |
266 | | |
267 | | /** |
268 | | * Tests conditional request rules for the If-Match header. |
269 | | * @param r The current request |
270 | | * @param headers The response headers to check against |
271 | | * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH |
272 | | * if the header does not match, AP_CONDITION_STRONG for a strong |
273 | | * match. Weak matches are not permitted for the If-Match header. |
274 | | */ |
275 | | AP_DECLARE(ap_condition_e) ap_condition_if_match(request_rec *r, |
276 | | apr_table_t *headers); |
277 | | |
278 | | /** |
279 | | * Tests conditional request rules for the If-Unmodified-Since header. |
280 | | * @param r The current request |
281 | | * @param headers The response headers to check against |
282 | | * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH |
283 | | * if the header does not match, AP_CONDITION_WEAK if a weak match |
284 | | * was present and allowed by RFC2616, AP_CONDITION_STRONG for a |
285 | | * strong match. |
286 | | */ |
287 | | AP_DECLARE(ap_condition_e) ap_condition_if_unmodified_since(request_rec *r, |
288 | | apr_table_t *headers); |
289 | | |
290 | | /** |
291 | | * Tests conditional request rules for the If-None-Match header. |
292 | | * @param r The current request |
293 | | * @param headers The response headers to check against |
294 | | * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH |
295 | | * if the header does not match, AP_CONDITION_WEAK if a weak match |
296 | | * was present and allowed by RFC2616, AP_CONDITION_STRONG for a |
297 | | * strong match. |
298 | | */ |
299 | | AP_DECLARE(ap_condition_e) ap_condition_if_none_match(request_rec *r, |
300 | | apr_table_t *headers); |
301 | | |
302 | | /** |
303 | | * Tests conditional request rules for the If-Modified-Since header. |
304 | | * @param r The current request |
305 | | * @param headers The response headers to check against |
306 | | * @return AP_CONDITION_NONE if the header is missing, AP_CONDITION_NOMATCH |
307 | | * if the header does not match, AP_CONDITION_WEAK if a weak match |
308 | | * was present and allowed by RFC2616, AP_CONDITION_STRONG for a |
309 | | * strong match. |
310 | | */ |
311 | | AP_DECLARE(ap_condition_e) ap_condition_if_modified_since(request_rec *r, |
312 | | apr_table_t *headers); |
313 | | |
314 | | /** |
315 | | * Tests conditional request rules for the If-Range header. |
316 | | * @param r The current request |
317 | | * @param headers The response headers to check against |
318 | | * @return AP_CONDITION_NONE if either the If-Range or Range header is |
319 | | * missing, AP_CONDITION_NOMATCH if the header does not match, |
320 | | * AP_CONDITION_STRONG for a strong match. Weak matches are not |
321 | | * permitted for the If-Range header. |
322 | | */ |
323 | | AP_DECLARE(ap_condition_e) ap_condition_if_range(request_rec *r, |
324 | | apr_table_t *headers); |
325 | | |
326 | | /** |
327 | | * Implements condition GET rules for HTTP/1.1 specification. This function |
328 | | * inspects the client headers and determines if the response fulfills |
329 | | * the requirements specified. |
330 | | * @param r The current request |
331 | | * @return OK if the response fulfills the condition GET rules, some |
332 | | * other status code otherwise |
333 | | */ |
334 | | AP_DECLARE(int) ap_meets_conditions(request_rec *r); |
335 | | |
336 | | /* Other ways to send stuff at the client. All of these keep track |
337 | | * of bytes_sent automatically. This indirection is intended to make |
338 | | * it a little more painless to slide things like HTTP-NG packetization |
339 | | * underneath the main body of the code later. In the meantime, it lets |
340 | | * us centralize a bit of accounting (bytes_sent). |
341 | | * |
342 | | * These also return the number of bytes written by the call. |
343 | | * They should only be called with a timeout registered, for obvious reaasons. |
344 | | * (Ditto the send_header stuff). |
345 | | */ |
346 | | |
347 | | /** |
348 | | * Send an entire file to the client, using sendfile if supported by the |
349 | | * current platform |
350 | | * @param fd The file to send. |
351 | | * @param r The current request |
352 | | * @param offset Offset into the file to start sending. |
353 | | * @param length Amount of data to send |
354 | | * @param nbytes Amount of data actually sent |
355 | | */ |
356 | | AP_DECLARE(apr_status_t) ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, |
357 | | apr_size_t length, apr_size_t *nbytes); |
358 | | |
359 | | #if APR_HAS_MMAP |
360 | | /** |
361 | | * Send an MMAP'ed file to the client |
362 | | * @param mm The MMAP'ed file to send |
363 | | * @param r The current request |
364 | | * @param offset The offset into the MMAP to start sending |
365 | | * @param length The amount of data to send |
366 | | * @return The number of bytes sent |
367 | | */ |
368 | | AP_DECLARE(apr_size_t) ap_send_mmap(apr_mmap_t *mm, |
369 | | request_rec *r, |
370 | | apr_size_t offset, |
371 | | apr_size_t length); |
372 | | #endif |
373 | | |
374 | | |
375 | | /** |
376 | | * Register a new request method, and return the offset that will be |
377 | | * associated with that method. |
378 | | * |
379 | | * @param p The pool to create registered method numbers from. |
380 | | * @param methname The name of the new method to register. |
381 | | * @return An int value representing an offset into a bitmask. |
382 | | */ |
383 | | AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname); |
384 | | |
385 | | /** |
386 | | * Initialize the method_registry and allocate memory for it. |
387 | | * |
388 | | * @param p Pool to allocate memory for the registry from. |
389 | | */ |
390 | | AP_DECLARE(void) ap_method_registry_init(apr_pool_t *p); |
391 | | |
392 | | /** |
393 | | * This is a convenience macro to ease with checking a mask |
394 | | * against a method name. |
395 | | */ |
396 | | #define AP_METHOD_CHECK_ALLOWED(mask, methname) \ |
397 | | ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname)))) |
398 | | |
399 | | /** |
400 | | * Create a new method list with the specified number of preallocated |
401 | | * slots for extension methods. |
402 | | * |
403 | | * @param p Pointer to a pool in which the structure should be |
404 | | * allocated. |
405 | | * @param nelts Number of preallocated extension slots |
406 | | * @return Pointer to the newly created structure. |
407 | | */ |
408 | | AP_DECLARE(ap_method_list_t *) ap_make_method_list(apr_pool_t *p, int nelts); |
409 | | |
410 | | |
411 | | /** |
412 | | * Copy a method list |
413 | | * |
414 | | * @param dest List to copy to |
415 | | * @param src List to copy from |
416 | | */ |
417 | | AP_DECLARE(void) ap_copy_method_list(ap_method_list_t *dest, |
418 | | ap_method_list_t *src); |
419 | | |
420 | | /** |
421 | | * Search for an HTTP method name in an ap_method_list_t structure, and |
422 | | * return true if found. |
423 | | * |
424 | | * @param method String containing the name of the method to check. |
425 | | * @param l Pointer to a method list, such as r->allowed_methods. |
426 | | * @return 1 if method is in the list, otherwise 0 |
427 | | */ |
428 | | AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method); |
429 | | |
430 | | /** |
431 | | * Add an HTTP method name to an ap_method_list_t structure if it isn't |
432 | | * already listed. |
433 | | * |
434 | | * @param method String containing the name of the method to check. |
435 | | * @param l Pointer to a method list, such as r->allowed_methods. |
436 | | * @return None. |
437 | | */ |
438 | | AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method); |
439 | | |
440 | | /** |
441 | | * Remove an HTTP method name from an ap_method_list_t structure. |
442 | | * |
443 | | * @param l Pointer to a method list, such as r->allowed_methods. |
444 | | * @param method String containing the name of the method to remove. |
445 | | * @return None. |
446 | | */ |
447 | | AP_DECLARE(void) ap_method_list_remove(ap_method_list_t *l, |
448 | | const char *method); |
449 | | |
450 | | /** |
451 | | * Reset a method list to be completely empty. |
452 | | * |
453 | | * @param l Pointer to a method list, such as r->allowed_methods. |
454 | | * @return None. |
455 | | */ |
456 | | AP_DECLARE(void) ap_clear_method_list(ap_method_list_t *l); |
457 | | |
458 | | /** |
459 | | * Set the content type for this request (r->content_type). |
460 | | * @param r The current request |
461 | | * @param ct The new content type |
462 | | * @warning This function must be called to set r->content_type in order |
463 | | * for the AddOutputFilterByType directive to work correctly. |
464 | | */ |
465 | | AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct); |
466 | | |
467 | | /** |
468 | | * Set the Accept-Ranges header for this response |
469 | | * @param r The current request |
470 | | */ |
471 | | AP_DECLARE(void) ap_set_accept_ranges(request_rec *r); |
472 | | |
473 | | |
474 | | /* Hmmm... could macrofy these for now, and maybe forever, though the |
475 | | * definitions of the macros would get a whole lot hairier. |
476 | | */ |
477 | | |
478 | | /** |
479 | | * Output one character for this request |
480 | | * @param c the character to output |
481 | | * @param r the current request |
482 | | * @return The number of bytes sent |
483 | | */ |
484 | | AP_DECLARE(int) ap_rputc(int c, request_rec *r); |
485 | | |
486 | | /** |
487 | | * Write a buffer for the current request |
488 | | * @param buf The buffer to write |
489 | | * @param nbyte The number of bytes to send from the buffer |
490 | | * @param r The current request |
491 | | * @return The number of bytes sent |
492 | | */ |
493 | | AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r); |
494 | | |
495 | | /** |
496 | | * Output a string for the current request |
497 | | * @param str The string to output |
498 | | * @param r The current request |
499 | | * @return The number of bytes sent |
500 | | * @note ap_rputs may be implemented as macro or inline function |
501 | | */ |
502 | | static APR_INLINE int ap_rputs(const char *str, request_rec *r) |
503 | 0 | { |
504 | 0 | apr_size_t len; |
505 | 0 |
|
506 | 0 | len = strlen(str); |
507 | 0 |
|
508 | 0 | for (;;) { |
509 | 0 | if (len <= INT_MAX) { |
510 | 0 | return ap_rwrite(str, (int)len, r); |
511 | 0 | } |
512 | 0 | else { |
513 | 0 | int rc; |
514 | 0 |
|
515 | 0 | rc = ap_rwrite(str, INT_MAX, r); |
516 | 0 | if (rc < 0) { |
517 | 0 | return rc; |
518 | 0 | } |
519 | 0 | else { |
520 | 0 | str += INT_MAX; |
521 | 0 | len -= INT_MAX; |
522 | 0 | } |
523 | 0 | } |
524 | 0 | } |
525 | 0 | } Unexecuted instantiation: core.c:ap_rputs Unexecuted instantiation: request.c:ap_rputs Unexecuted instantiation: ssl.c:ap_rputs Unexecuted instantiation: core_filters.c:ap_rputs Unexecuted instantiation: util_expr_eval.c:ap_rputs Unexecuted instantiation: config.c:ap_rputs Unexecuted instantiation: vhost.c:ap_rputs Unexecuted instantiation: util.c:ap_rputs Unexecuted instantiation: util_etag.c:ap_rputs Unexecuted instantiation: util_script.c:ap_rputs Unexecuted instantiation: connection.c:ap_rputs Unexecuted instantiation: mpm_common.c:ap_rputs Unexecuted instantiation: scoreboard.c:ap_rputs Unexecuted instantiation: protocol.c:ap_rputs Unexecuted instantiation: eor_bucket.c:ap_rputs Unexecuted instantiation: headers_bucket.c:ap_rputs Unexecuted instantiation: error_bucket.c:ap_rputs Unexecuted instantiation: http_core.c:ap_rputs Unexecuted instantiation: http_protocol.c:ap_rputs Unexecuted instantiation: http_request.c:ap_rputs Unexecuted instantiation: http_filters.c:ap_rputs Unexecuted instantiation: chunk_filter.c:ap_rputs Unexecuted instantiation: byterange_filter.c:ap_rputs Unexecuted instantiation: event.c:ap_rputs |
526 | | |
527 | | /** |
528 | | * Write an unspecified number of strings to the request |
529 | | * @param r The current request |
530 | | * @param ... The strings to write |
531 | | * @return The number of bytes sent |
532 | | */ |
533 | | AP_DECLARE_NONSTD(int) ap_rvputs(request_rec *r,...) |
534 | | AP_FN_ATTR_SENTINEL; |
535 | | |
536 | | /** |
537 | | * Output data to the client in a printf format |
538 | | * @param r The current request |
539 | | * @param fmt The format string |
540 | | * @param vlist The arguments to use to fill out the format string |
541 | | * @return The number of bytes sent |
542 | | */ |
543 | | AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist); |
544 | | |
545 | | /** |
546 | | * Output data to the client in a printf format |
547 | | * @param r The current request |
548 | | * @param fmt The format string |
549 | | * @param ... The arguments to use to fill out the format string |
550 | | * @return The number of bytes sent |
551 | | */ |
552 | | AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...) |
553 | | __attribute__((format(printf,2,3))); |
554 | | |
555 | | /** |
556 | | * Flush all of the data for the current request to the client |
557 | | * @param r The current request |
558 | | * @return 0 on success, -1 if an error occurred |
559 | | */ |
560 | | AP_DECLARE(int) ap_rflush(request_rec *r); |
561 | | |
562 | | /** |
563 | | * Index used in custom_responses array for a specific error code |
564 | | * (only use outside protocol.c is in getting them configured). |
565 | | * @param status HTTP status code |
566 | | * @return The index of the response |
567 | | */ |
568 | | AP_DECLARE(int) ap_index_of_response(int status); |
569 | | |
570 | | /** |
571 | | * Return the Status-Line for a given status code (excluding the |
572 | | * HTTP-Version field). If an invalid or unknown status code is |
573 | | * passed, "500 Internal Server Error" will be returned. |
574 | | * @param status The HTTP status code |
575 | | * @return The Status-Line |
576 | | */ |
577 | | AP_DECLARE(const char *) ap_get_status_line(int status); |
578 | | |
579 | | /** |
580 | | * Return the Status-Line for a given status code (excluding the |
581 | | * HTTP-Version field). If an invalid status code is passed, |
582 | | * "500 Internal Server Error" will be returned, whereas an unknown |
583 | | * status will be returned like "xxx Status xxx". |
584 | | * @param p The pool to allocate from when status is unknown |
585 | | * @param status The HTTP status code |
586 | | * @return The Status-Line |
587 | | */ |
588 | | AP_DECLARE(const char *) ap_get_status_line_ex(apr_pool_t *p, int status); |
589 | | |
590 | | /* Reading a block of data from the client connection (e.g., POST arg) */ |
591 | | |
592 | | /** |
593 | | * Setup the client to allow Apache to read the request body. |
594 | | * @param r The current request |
595 | | * @param read_policy How the server should interpret a chunked |
596 | | * transfer-encoding. One of: <pre> |
597 | | * REQUEST_NO_BODY Send 413 error if message has any body |
598 | | * REQUEST_CHUNKED_ERROR Send 411 error if body without Content-Length |
599 | | * REQUEST_CHUNKED_DECHUNK If chunked, remove the chunks for me. |
600 | | * </pre> |
601 | | * @return either OK or an error code |
602 | | */ |
603 | | AP_DECLARE(int) ap_setup_client_block(request_rec *r, int read_policy); |
604 | | |
605 | | /** |
606 | | * Determine if the client has sent any data. This also sends a |
607 | | * 100 Continue response to HTTP/1.1 clients, so modules should not be called |
608 | | * until the module is ready to read content. |
609 | | * @warning Never call this function more than once. |
610 | | * @param r The current request |
611 | | * @return 0 if there is no message to read, 1 otherwise |
612 | | */ |
613 | | AP_DECLARE(int) ap_should_client_block(request_rec *r); |
614 | | |
615 | | /** |
616 | | * Call this in a loop. It will put data into a buffer and return the length |
617 | | * of the input block |
618 | | * @param r The current request |
619 | | * @param buffer The buffer in which to store the data |
620 | | * @param bufsiz The size of the buffer |
621 | | * @return Number of bytes inserted into the buffer. When done reading, 0 |
622 | | * if EOF, or -1 if there was an error |
623 | | */ |
624 | | AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz); |
625 | | |
626 | | /** |
627 | | * Map specific APR codes returned by the filter stack to HTTP error |
628 | | * codes, or the default status code provided. Use it as follows: |
629 | | * |
630 | | * return ap_map_http_request_error(rv, HTTP_BAD_REQUEST); |
631 | | * |
632 | | * If the filter has already handled the error, AP_FILTER_ERROR will |
633 | | * be returned, which is cleanly passed through. |
634 | | * |
635 | | * These mappings imply that the filter stack is reading from the |
636 | | * downstream client, the proxy will map these codes differently. |
637 | | * @param rv APR status code |
638 | | * @param status Default HTTP code should the APR code not be recognised |
639 | | * @return Mapped HTTP status code |
640 | | */ |
641 | | AP_DECLARE(int) ap_map_http_request_error(apr_status_t rv, int status); |
642 | | |
643 | | /** |
644 | | * In HTTP/1.1, any method can have a body. However, most GET handlers |
645 | | * wouldn't know what to do with a request body if they received one. |
646 | | * This helper routine tests for and reads any message body in the request, |
647 | | * simply discarding whatever it receives. We need to do this because |
648 | | * failing to read the request body would cause it to be interpreted |
649 | | * as the next request on a persistent connection. |
650 | | * @param r The current request |
651 | | * @return error status if request is malformed, OK otherwise |
652 | | */ |
653 | | AP_DECLARE(int) ap_discard_request_body(request_rec *r); |
654 | | |
655 | | /** |
656 | | * Setup the output headers so that the client knows how to authenticate |
657 | | * itself the next time, if an authentication request failed. |
658 | | * @param r The current request |
659 | | */ |
660 | | AP_DECLARE(void) ap_note_auth_failure(request_rec *r); |
661 | | |
662 | | /** |
663 | | * @deprecated @see ap_note_auth_failure |
664 | | */ |
665 | | AP_DECLARE(void) ap_note_basic_auth_failure(request_rec *r); |
666 | | |
667 | | /** |
668 | | * @deprecated @see ap_note_auth_failure |
669 | | */ |
670 | | AP_DECLARE(void) ap_note_digest_auth_failure(request_rec *r); |
671 | | |
672 | | /** |
673 | | * This hook allows modules to add support for a specific auth type to |
674 | | * ap_note_auth_failure |
675 | | * @param r the current request |
676 | | * @param auth_type the configured auth_type |
677 | | * @return OK, DECLINED |
678 | | */ |
679 | | AP_DECLARE_HOOK(int, note_auth_failure, (request_rec *r, const char *auth_type)) |
680 | | |
681 | | /** |
682 | | * Get the password from the request headers. This function has multiple side |
683 | | * effects due to its prior use in the old authentication framework, including |
684 | | * setting r->user (which is supposed to indicate that the user in question has |
685 | | * been authenticated for the current request). |
686 | | * |
687 | | * Modules which call ap_get_basic_auth_pw() during the authentication phase |
688 | | * MUST either immediately authenticate the user after the call, or else stop |
689 | | * the request immediately with an error response, to avoid incorrectly |
690 | | * authenticating the current request. (See CVE-2017-3167.) The replacement |
691 | | * ap_get_basic_auth_components() API should be preferred. |
692 | | * |
693 | | * @deprecated @see ap_get_basic_auth_components |
694 | | * @param r The current request |
695 | | * @param pw The password as set in the headers |
696 | | * @return 0 (OK) if it set the 'pw' argument (and assured |
697 | | * a correct value in r->user); otherwise it returns |
698 | | * an error code, either HTTP_INTERNAL_SERVER_ERROR if things are |
699 | | * really confused, HTTP_UNAUTHORIZED if no authentication at all |
700 | | * seemed to be in use, or DECLINED if there was authentication but |
701 | | * it wasn't Basic (in which case, the caller should presumably |
702 | | * decline as well). |
703 | | */ |
704 | | AP_DECLARE(int) ap_get_basic_auth_pw(request_rec *r, const char **pw); |
705 | | |
706 | 0 | #define AP_GET_BASIC_AUTH_PW_NOTE "AP_GET_BASIC_AUTH_PW_NOTE" |
707 | | |
708 | | /** |
709 | | * Get the username and/or password from the request's Basic authentication |
710 | | * headers. Unlike ap_get_basic_auth_pw(), calling this function has no side |
711 | | * effects on the passed request_rec. |
712 | | * |
713 | | * @param r The current request |
714 | | * @param username If not NULL, set to the username sent by the client |
715 | | * @param password If not NULL, set to the password sent by the client |
716 | | * @return APR_SUCCESS if the credentials were successfully parsed and returned; |
717 | | * APR_EINVAL if there was no authentication header sent or if the |
718 | | * client was not using the Basic authentication scheme. username and |
719 | | * password are unchanged on failure. |
720 | | */ |
721 | | AP_DECLARE(apr_status_t) ap_get_basic_auth_components(const request_rec *r, |
722 | | const char **username, |
723 | | const char **password); |
724 | | |
725 | | /** |
726 | | * parse_uri: break apart the uri |
727 | | * @warning Side Effects: |
728 | | * @li sets r->args to rest after '?' (or NULL if no '?') |
729 | | * @li sets r->uri to request uri (without r->args part) |
730 | | * @li sets r->hostname (if not set already) from request (scheme://host:port) |
731 | | * @param r The current request |
732 | | * @param uri The uri to break apart |
733 | | */ |
734 | | AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri); |
735 | | |
736 | 0 | #define AP_GETLINE_FOLD (1 << 0) /* Whether to merge continuation lines */ |
737 | 0 | #define AP_GETLINE_CRLF (1 << 1) /* Whether line ends must be CRLF */ |
738 | 0 | #define AP_GETLINE_NOSPC_EOL (1 << 2) /* Whether to consume up to and including |
739 | | the end of line on APR_ENOSPC */ |
740 | 0 | #define AP_GETLINE_NONBLOCK (1 << 3) /* Whether to read non-blocking */ |
741 | | |
742 | | /** |
743 | | * Get the next line of input for the request |
744 | | * @param s The buffer into which to read the line |
745 | | * @param n The size of the buffer |
746 | | * @param r The request |
747 | | * @param flags Bit mask of AP_GETLINE_* options |
748 | | * @return The length of the line, if successful |
749 | | * n, if the line is too big to fit in the buffer |
750 | | * -1 for miscellaneous errors |
751 | | */ |
752 | | AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags); |
753 | | |
754 | | /** |
755 | | * Get the next line from an input filter |
756 | | * |
757 | | * @param s Pointer to the pointer to the buffer into which the line |
758 | | * should be read; if *s==NULL, a buffer of the necessary size |
759 | | * to hold the data will be allocated from \p p |
760 | | * @param n The size of the buffer |
761 | | * @param read The length of the line. |
762 | | * @param f Input filter to read from |
763 | | * @param flags Bit mask of AP_GETLINE_* options |
764 | | * @param bb Working brigade to use when reading buckets |
765 | | * @param p The pool to allocate the buffer from (if needed) |
766 | | * @return APR_SUCCESS, if successful |
767 | | * APR_ENOSPC, if the line is too big to fit in the buffer |
768 | | * Other errors where appropriate |
769 | | */ |
770 | | AP_DECLARE(apr_status_t) ap_fgetline(char **s, apr_size_t n, |
771 | | apr_size_t *read, ap_filter_t *f, |
772 | | int flags, apr_bucket_brigade *bb, |
773 | | apr_pool_t *p); |
774 | | |
775 | | /** |
776 | | * @see ap_fgetline |
777 | | * |
778 | | * Note: genuinely calls, ap_fgetline(s, n, read, r->proto_input_filters, |
779 | | * flags, bb, r->pool) |
780 | | */ |
781 | | AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n, |
782 | | apr_size_t *read, request_rec *r, |
783 | | int flags, apr_bucket_brigade *bb); |
784 | | |
785 | | /** |
786 | | * Get the method number associated with the given string, assumed to |
787 | | * contain an HTTP method. Returns M_INVALID if not recognized. |
788 | | * @param method A string containing a valid HTTP method |
789 | | * @return The method number |
790 | | */ |
791 | | AP_DECLARE(int) ap_method_number_of(const char *method); |
792 | | |
793 | | /** |
794 | | * Get the method name associated with the given internal method |
795 | | * number. Returns NULL if not recognized. |
796 | | * @param p A pool to use for temporary allocations. |
797 | | * @param methnum An integer value corresponding to an internal method number |
798 | | * @return The name corresponding to the method number |
799 | | */ |
800 | | AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum); |
801 | | |
802 | | |
803 | | /* Hooks */ |
804 | | /* |
805 | | * pre_read_request --- run right before read_request_line(), |
806 | | * and not run during any subrequests. |
807 | | */ |
808 | | /** |
809 | | * This hook allows modules to affect the request or connection immediately before |
810 | | * the request has been read, and before any other phases have been processes. |
811 | | * @param r The current request of the soon-to-be-read request |
812 | | * @param c The connection |
813 | | * @return None/void |
814 | | */ |
815 | | AP_DECLARE_HOOK(void,pre_read_request,(request_rec *r, conn_rec *c)) |
816 | | |
817 | | /* |
818 | | * post_read_request --- run right after read_request or internal_redirect, |
819 | | * and not run during any subrequests. |
820 | | */ |
821 | | /** |
822 | | * This hook allows modules to affect the request immediately after the request |
823 | | * has been read, and before any other phases have been processes. This allows |
824 | | * modules to make decisions based upon the input header fields |
825 | | * @param r The current request |
826 | | * @return OK or DECLINED |
827 | | */ |
828 | | AP_DECLARE_HOOK(int,post_read_request,(request_rec *r)) |
829 | | |
830 | | /** |
831 | | * This hook allows modules to perform any module-specific logging activities |
832 | | * over and above the normal server things. |
833 | | * @param r The current request |
834 | | * @return OK, DECLINED, or HTTP_... |
835 | | */ |
836 | | AP_DECLARE_HOOK(int,log_transaction,(request_rec *r)) |
837 | | |
838 | | /** |
839 | | * This hook allows modules to retrieve the http scheme for a request. This |
840 | | * allows Apache modules to easily extend the schemes that Apache understands |
841 | | * @param r The current request |
842 | | * @return The http scheme from the request |
843 | | */ |
844 | | AP_DECLARE_HOOK(const char *,http_scheme,(const request_rec *r)) |
845 | | |
846 | | /** |
847 | | * Return the default port from the current request |
848 | | * @param r The current request |
849 | | * @return The current port |
850 | | */ |
851 | | AP_DECLARE_HOOK(apr_port_t,default_port,(const request_rec *r)) |
852 | | |
853 | | |
854 | 0 | #define AP_PROTOCOL_HTTP1 "http/1.1" |
855 | | |
856 | | /** |
857 | | * Determine the list of protocols available for a connection/request. This may |
858 | | * be collected with or without any request sent, in which case the request is |
859 | | * NULL. Or it may be triggered by the request received, e.g. through the |
860 | | * "Upgrade" header. |
861 | | * |
862 | | * This hook will be run whenever protocols are being negotiated (ALPN as |
863 | | * one example). It may also be invoked at other times, e.g. when the server |
864 | | * wants to advertise protocols it is capable of switching to. |
865 | | * |
866 | | * The identifiers for protocols are taken from the TLS extension type ALPN: |
867 | | * https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xml |
868 | | * |
869 | | * If no protocols are added to the proposals, the server not perform any |
870 | | * switch. If the protocol selected from the proposals is the protocol |
871 | | * already in place, also no protocol switch will be invoked. |
872 | | * |
873 | | * The client may already have announced the protocols it is willing to |
874 | | * accept. These will then be listed as offers. This parameter may also |
875 | | * be NULL, indicating that offers from the client are not known and |
876 | | * the hooks should propose all protocols that are valid for the |
877 | | * current connection/request. |
878 | | * |
879 | | * All hooks are run, unless one returns an error. Proposals may contain |
880 | | * duplicates. The order in which proposals are added is usually ignored. |
881 | | * |
882 | | * @param c The current connection |
883 | | * @param r The current request or NULL |
884 | | * @param s The server/virtual host selected |
885 | | * @param offers A list of protocol identifiers offered by the client or |
886 | | * NULL to indicated that the hooks are free to propose |
887 | | * @param proposals The list of protocol identifiers proposed by the hooks |
888 | | * @return OK or DECLINED |
889 | | */ |
890 | | AP_DECLARE_HOOK(int,protocol_propose,(conn_rec *c, request_rec *r, |
891 | | server_rec *s, |
892 | | const apr_array_header_t *offers, |
893 | | apr_array_header_t *proposals)) |
894 | | |
895 | | /** |
896 | | * Perform a protocol switch on the connection. The exact requirements for |
897 | | * that depend on the protocol in place and the one switched to. The first |
898 | | * protocol module to handle the switch is the last module run. |
899 | | * |
900 | | * For a connection level switch (r == NULL), the handler must on return |
901 | | * leave the conn_rec in a state suitable for processing the switched |
902 | | * protocol, e.g. correct filters in place. |
903 | | * |
904 | | * For a request triggered switch (r != NULL), the protocol switch is done |
905 | | * before the response is sent out. When switching from "http/1.1" via Upgrade |
906 | | * header, the 101 intermediate response will have been sent. The |
907 | | * hook needs then to process the connection until it can be closed. Which |
908 | | * the server will enforce on hook return. |
909 | | * Any error the hook might encounter must already be sent by the hook itself |
910 | | * to the client in whatever form the new protocol requires. |
911 | | * |
912 | | * @param c The current connection |
913 | | * @param r The current request or NULL |
914 | | * @param s The server/virtual host selected |
915 | | * @param protocol The protocol identifier we try to switch to |
916 | | * @return OK or DECLINED |
917 | | */ |
918 | | AP_DECLARE_HOOK(int,protocol_switch,(conn_rec *c, request_rec *r, |
919 | | server_rec *s, |
920 | | const char *protocol)) |
921 | | |
922 | | /** |
923 | | * Return the protocol used on the connection. Modules implementing |
924 | | * protocol switching must register here and return the correct protocol |
925 | | * identifier for connections they switched. |
926 | | * |
927 | | * To find out the protocol for the current connection, better call |
928 | | * @see ap_get_protocol which internally uses this hook. |
929 | | * |
930 | | * @param c The current connection |
931 | | * @return The identifier of the protocol in place or NULL |
932 | | */ |
933 | | AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c)) |
934 | | |
935 | | /** |
936 | | * Get the protocols that the connection and optional request may |
937 | | * upgrade to - besides the protocol currently active on the connection. These |
938 | | * values may be used to announce to a client what choices it has. |
939 | | * |
940 | | * If report_all == 0, only protocols more preferable than the one currently |
941 | | * being used, are reported. Otherwise, all available protocols beside the |
942 | | * current one are being reported. |
943 | | * |
944 | | * @param c The current connection |
945 | | * @param r The current request or NULL |
946 | | * @param s The server/virtual host selected or NULL |
947 | | * @param report_all include also protocols less preferred than the current one |
948 | | * @param pupgrades on return, possible protocols to upgrade to in descending order |
949 | | * of preference. Maybe NULL if none are available. |
950 | | */ |
951 | | AP_DECLARE(apr_status_t) ap_get_protocol_upgrades(conn_rec *c, request_rec *r, |
952 | | server_rec *s, int report_all, |
953 | | const apr_array_header_t **pupgrades); |
954 | | |
955 | | /** |
956 | | * Select a protocol for the given connection and optional request. Will return |
957 | | * the protocol identifier selected which may be the protocol already in place |
958 | | * on the connection. The selected protocol will be NULL if non of the given |
959 | | * choices could be agreed upon (e.g. no proposal as made). |
960 | | * |
961 | | * A special case is where the choices itself is NULL (instead of empty). In |
962 | | * this case there are no restrictions imposed on protocol selection. |
963 | | * |
964 | | * @param c The current connection |
965 | | * @param r The current request or NULL |
966 | | * @param s The server/virtual host selected |
967 | | * @param choices A list of protocol identifiers, normally the client's wishes |
968 | | * @return The selected protocol or NULL if no protocol could be agreed upon |
969 | | */ |
970 | | AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r, |
971 | | server_rec *s, |
972 | | const apr_array_header_t *choices); |
973 | | |
974 | | /** |
975 | | * Perform the actual protocol switch. The protocol given must have been |
976 | | * selected before on the very same connection and request pair. |
977 | | * |
978 | | * @param c The current connection |
979 | | * @param r The current request or NULL |
980 | | * @param s The server/virtual host selected |
981 | | * @param protocol the protocol to switch to |
982 | | * @return APR_SUCCESS, if caller may continue processing as usual |
983 | | * APR_EOF, if caller needs to stop processing the connection |
984 | | * APR_EINVAL, if the protocol is already in place |
985 | | * APR_NOTIMPL, if no module performed the switch |
986 | | * Other errors where appropriate |
987 | | */ |
988 | | AP_DECLARE(apr_status_t) ap_switch_protocol(conn_rec *c, request_rec *r, |
989 | | server_rec *s, |
990 | | const char *protocol); |
991 | | |
992 | | /** |
993 | | * Call the protocol_get hook to determine the protocol currently in use |
994 | | * for the given connection. |
995 | | * |
996 | | * Unless another protocol has been switch to, will default to |
997 | | * @see AP_PROTOCOL_HTTP1 and modules implementing a new protocol must |
998 | | * report a switched connection via the protocol_get hook. |
999 | | * |
1000 | | * @param c The connection to determine the protocol for |
1001 | | * @return the protocol in use, never NULL |
1002 | | */ |
1003 | | AP_DECLARE(const char *) ap_get_protocol(conn_rec *c); |
1004 | | |
1005 | | /** |
1006 | | * Check if the given protocol is an allowed choice on the given |
1007 | | * combination of connection, request and server. |
1008 | | * |
1009 | | * When server is NULL, it is taken from request_rec, unless |
1010 | | * request_rec is NULL. Then it is taken from the connection base |
1011 | | * server. |
1012 | | * |
1013 | | * @param c The current connection |
1014 | | * @param r The current request or NULL |
1015 | | * @param s The server/virtual host selected or NULL |
1016 | | * @param protocol the protocol to switch to |
1017 | | * @return != 0 iff protocol is allowed |
1018 | | */ |
1019 | | AP_DECLARE(int) ap_is_allowed_protocol(conn_rec *c, request_rec *r, |
1020 | | server_rec *s, const char *protocol); |
1021 | | |
1022 | | /** @see ap_bucket_type_error */ |
1023 | | typedef struct ap_bucket_error ap_bucket_error; |
1024 | | |
1025 | | /** |
1026 | | * @struct ap_bucket_error |
1027 | | * @brief A bucket referring to an HTTP error |
1028 | | * |
1029 | | * This bucket can be passed down the filter stack to indicate that an |
1030 | | * HTTP error occurred while running a filter. In order for this bucket |
1031 | | * to be used successfully, it MUST be sent as the first bucket in the |
1032 | | * first brigade to be sent from a given filter. |
1033 | | */ |
1034 | | struct ap_bucket_error { |
1035 | | /** Number of buckets using this memory */ |
1036 | | apr_bucket_refcount refcount; |
1037 | | /** The error code */ |
1038 | | int status; |
1039 | | /** The error string */ |
1040 | | const char *data; |
1041 | | }; |
1042 | | |
1043 | | /** @see ap_bucket_type_error */ |
1044 | | AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_error; |
1045 | | |
1046 | | /** |
1047 | | * Determine if a bucket is an error bucket |
1048 | | * @param e The bucket to inspect |
1049 | | * @return true or false |
1050 | | */ |
1051 | 0 | #define AP_BUCKET_IS_ERROR(e) (e->type == &ap_bucket_type_error) |
1052 | | |
1053 | | /** |
1054 | | * Make the bucket passed in an error bucket |
1055 | | * @param b The bucket to make into an error bucket |
1056 | | * @param error The HTTP error code to put in the bucket. |
1057 | | * @param buf An optional error string to put in the bucket. |
1058 | | * @param p A pool to allocate out of. |
1059 | | * @return The new bucket, or NULL if allocation failed |
1060 | | */ |
1061 | | AP_DECLARE(apr_bucket *) ap_bucket_error_make(apr_bucket *b, int error, |
1062 | | const char *buf, apr_pool_t *p); |
1063 | | |
1064 | | /** |
1065 | | * Create a bucket referring to an HTTP error. |
1066 | | * @param error The HTTP error code to put in the bucket. |
1067 | | * @param buf An optional error string to put in the bucket. |
1068 | | * @param p A pool to allocate the error string out of. |
1069 | | * @param list The bucket allocator from which to allocate the bucket |
1070 | | * @return The new bucket, or NULL if allocation failed |
1071 | | */ |
1072 | | AP_DECLARE(apr_bucket *) ap_bucket_error_create(int error, const char *buf, |
1073 | | apr_pool_t *p, |
1074 | | apr_bucket_alloc_t *list); |
1075 | | |
1076 | | /** @see ap_bucket_type_request */ |
1077 | | typedef struct ap_bucket_request ap_bucket_request; |
1078 | | |
1079 | | /** |
1080 | | * @struct ap_bucket_request |
1081 | | * @brief A bucket referring to a HTTP request |
1082 | | * |
1083 | | */ |
1084 | | struct ap_bucket_request { |
1085 | | /** Number of buckets using this memory */ |
1086 | | apr_bucket_refcount refcount; |
1087 | | apr_pool_t *pool; /* pool that holds the contents, not for modification */ |
1088 | | const char *method; /* request method */ |
1089 | | const char *uri; /* request uri */ |
1090 | | const char *protocol; /* request protocol */ |
1091 | | apr_table_t *headers; /* request headers */ |
1092 | | }; |
1093 | | |
1094 | | /** @see ap_bucket_type_request */ |
1095 | | AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_request; |
1096 | | |
1097 | | /** |
1098 | | * Determine if a bucket is a request bucket |
1099 | | * @param e The bucket to inspect |
1100 | | * @return true or false |
1101 | | */ |
1102 | 0 | #define AP_BUCKET_IS_REQUEST(e) (e->type == &ap_bucket_type_request) |
1103 | | |
1104 | | /** |
1105 | | * Make the bucket passed in a request bucket |
1106 | | * Copies all parameters to the given pool. |
1107 | | * @param b The bucket to make into a request bucket |
1108 | | * @param method the HTTP method |
1109 | | * @param uri the uri requested |
1110 | | * @param protocol the protocol requested |
1111 | | * @param headers the table of response headers. |
1112 | | * @param p A pool to allocate out of. |
1113 | | * @return The new bucket, or NULL if allocation failed |
1114 | | */ |
1115 | | AP_DECLARE(apr_bucket *) ap_bucket_request_make( |
1116 | | apr_bucket *b, |
1117 | | const char *method, |
1118 | | const char *uri, |
1119 | | const char *protocol, |
1120 | | apr_table_t *headers, |
1121 | | apr_pool_t *p); |
1122 | | |
1123 | | /** |
1124 | | * Make the bucket passed in a request bucket |
1125 | | * Uses all paramters without copying. |
1126 | | * @param b The bucket to make into a request bucket |
1127 | | * @param method the HTTP method |
1128 | | * @param uri the uri requested |
1129 | | * @param protocol the protocol requested |
1130 | | * @param headers the table of response headers. |
1131 | | * @param p A pool to allocate out of. |
1132 | | * @return The new bucket, or NULL if allocation failed |
1133 | | */ |
1134 | | AP_DECLARE(apr_bucket *) ap_bucket_request_maken( |
1135 | | apr_bucket *b, |
1136 | | const char *method, |
1137 | | const char *uri, |
1138 | | const char *protocol, |
1139 | | apr_table_t *headers, |
1140 | | apr_pool_t *p); |
1141 | | |
1142 | | /** |
1143 | | * Create a bucket referring to a HTTP request. |
1144 | | * Copies all parameters to the given pool. |
1145 | | * @param method the HTTP method |
1146 | | * @param uri the uri requested |
1147 | | * @param protocol the protocol requested |
1148 | | * @param headers the table of response headers. |
1149 | | * @param p A pool to allocate the error string out of. |
1150 | | * @param list The bucket allocator from which to allocate the bucket |
1151 | | * @return The new bucket, or NULL if allocation failed |
1152 | | */ |
1153 | | AP_DECLARE(apr_bucket *) ap_bucket_request_create( |
1154 | | const char *method, |
1155 | | const char *uri, |
1156 | | const char *protocol, |
1157 | | apr_table_t *headers, |
1158 | | apr_pool_t *p, |
1159 | | apr_bucket_alloc_t *list); |
1160 | | |
1161 | | /** |
1162 | | * Create a bucket referring to a HTTP request. |
1163 | | * Uses all paramters without copying. |
1164 | | * @param method the HTTP method |
1165 | | * @param uri the uri requested |
1166 | | * @param protocol the protocol requested |
1167 | | * @param headers the HTTP response headers. |
1168 | | * @param p A pool to allocate the error string out of. |
1169 | | * @param list The bucket allocator from which to allocate the bucket |
1170 | | * @return The new bucket, or NULL if allocation failed |
1171 | | */ |
1172 | | AP_DECLARE(apr_bucket *) ap_bucket_request_createn( |
1173 | | const char *method, |
1174 | | const char *uri, |
1175 | | const char *protocol, |
1176 | | apr_table_t *headers, |
1177 | | apr_pool_t *p, |
1178 | | apr_bucket_alloc_t *list); |
1179 | | |
1180 | | /** |
1181 | | * Clone a request bucket into another pool/bucket_alloc that may |
1182 | | * have a separate lifetime than the source bucket/pool. |
1183 | | * @param source the request bucket to clone |
1184 | | * @param p A pool to allocate the data out of. |
1185 | | * @param list The bucket allocator from which to allocate the bucket |
1186 | | * @return The new bucket, or NULL if allocation failed |
1187 | | */ |
1188 | | AP_DECLARE(apr_bucket *) ap_bucket_request_clone(apr_bucket *source, |
1189 | | apr_pool_t *p, |
1190 | | apr_bucket_alloc_t *list); |
1191 | | |
1192 | | /** @see ap_bucket_type_response */ |
1193 | | typedef struct ap_bucket_response ap_bucket_response; |
1194 | | |
1195 | | /** |
1196 | | * @struct ap_bucket_response |
1197 | | * @brief A bucket referring to a HTTP response |
1198 | | * |
1199 | | */ |
1200 | | struct ap_bucket_response { |
1201 | | /** Number of buckets using this memory */ |
1202 | | apr_bucket_refcount refcount; |
1203 | | apr_pool_t *pool; /* pool that holds the contents, not for modification */ |
1204 | | int status; /* The status code */ |
1205 | | const char *reason; /* The optional HTTP reason for the status. */ |
1206 | | apr_table_t *headers; /* The response headers */ |
1207 | | apr_table_t *notes; /* internal notes about the response */ |
1208 | | }; |
1209 | | |
1210 | | /** @see ap_bucket_type_headers */ |
1211 | | AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_response; |
1212 | | |
1213 | | /** |
1214 | | * Determine if a bucket is a response bucket |
1215 | | * @param e The bucket to inspect |
1216 | | * @return true or false |
1217 | | */ |
1218 | 0 | #define AP_BUCKET_IS_RESPONSE(e) (e->type == &ap_bucket_type_response) |
1219 | | |
1220 | | /** |
1221 | | * Make the bucket passed in a response bucket |
1222 | | * @param b The bucket to make into a response bucket |
1223 | | * @param status The HTTP status code of the response. |
1224 | | * @param reason textual description of status, can be NULL. |
1225 | | * @param headers the table of response headers. |
1226 | | * @param notes internal notes on the response |
1227 | | * @param p A pool to allocate out of. |
1228 | | * @return The new bucket, or NULL if allocation failed |
1229 | | */ |
1230 | | AP_DECLARE(apr_bucket *) ap_bucket_response_make(apr_bucket *b, int status, |
1231 | | const char *reason, apr_table_t *headers, |
1232 | | apr_table_t *notes, apr_pool_t *p); |
1233 | | |
1234 | | /** |
1235 | | * Create a bucket referring to a HTTP response. |
1236 | | * @param status The HTTP status code. |
1237 | | * @param reason textual description of status, can be NULL. |
1238 | | * @param headers the HTTP response headers. |
1239 | | * @param notes internal notes on the response |
1240 | | * @param p A pool to allocate the error string out of. |
1241 | | * @param list The bucket allocator from which to allocate the bucket |
1242 | | * @return The new bucket, or NULL if allocation failed |
1243 | | */ |
1244 | | AP_DECLARE(apr_bucket *) ap_bucket_response_create( |
1245 | | int status, const char *reason, |
1246 | | apr_table_t *headers, |
1247 | | apr_table_t *notes, |
1248 | | apr_pool_t *p, |
1249 | | apr_bucket_alloc_t *list); |
1250 | | |
1251 | | /** |
1252 | | * Clone a RESPONSE bucket into another pool/bucket_alloc that may |
1253 | | * have a separate lifetime than the source bucket/pool. |
1254 | | * @param source the response bucket to clone |
1255 | | * @param p A pool to allocate the data out of. |
1256 | | * @param list The bucket allocator from which to allocate the bucket |
1257 | | * @return The new bucket, or NULL if allocation failed |
1258 | | */ |
1259 | | AP_DECLARE(apr_bucket *) ap_bucket_response_clone(apr_bucket *source, |
1260 | | apr_pool_t *p, |
1261 | | apr_bucket_alloc_t *list); |
1262 | | |
1263 | | /** @see ap_bucket_type_headers */ |
1264 | | typedef struct ap_bucket_headers ap_bucket_headers; |
1265 | | |
1266 | | /** |
1267 | | * @struct ap_bucket_headers |
1268 | | * @brief A bucket referring to an HTTP header set |
1269 | | * |
1270 | | */ |
1271 | | struct ap_bucket_headers { |
1272 | | /** Number of buckets using this memory */ |
1273 | | apr_bucket_refcount refcount; |
1274 | | apr_pool_t *pool; /* pool that holds the contents, not for modification */ |
1275 | | apr_table_t *headers; /* The headers */ |
1276 | | |
1277 | | }; |
1278 | | |
1279 | | /** @see ap_bucket_type_headers */ |
1280 | | AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_headers; |
1281 | | |
1282 | | /** |
1283 | | * Determine if a bucket is an headers bucket |
1284 | | * @param e The bucket to inspect |
1285 | | * @return true or false |
1286 | | */ |
1287 | 0 | #define AP_BUCKET_IS_HEADERS(e) (e->type == &ap_bucket_type_headers) |
1288 | | |
1289 | | /** |
1290 | | * Make the bucket passed in a headers bucket |
1291 | | * @param b The bucket to make into a headers bucket |
1292 | | * @param headers the table of headers. |
1293 | | * @param p A pool to allocate out of. |
1294 | | * @return The new bucket, or NULL if allocation failed |
1295 | | */ |
1296 | | AP_DECLARE(apr_bucket *) ap_bucket_headers_make(apr_bucket *b, |
1297 | | apr_table_t *headers, apr_pool_t *p); |
1298 | | |
1299 | | /** |
1300 | | * Create a bucket referring to a table of HTTP headers. |
1301 | | * @param headers the HTTP headers in the bucket. |
1302 | | * @param p A pool to allocate the error string out of. |
1303 | | * @param list The bucket allocator from which to allocate the bucket |
1304 | | * @return The new bucket, or NULL if allocation failed |
1305 | | */ |
1306 | | AP_DECLARE(apr_bucket *) ap_bucket_headers_create(apr_table_t *headers, |
1307 | | apr_pool_t *p, |
1308 | | apr_bucket_alloc_t *list); |
1309 | | |
1310 | | /** |
1311 | | * Clone a HEADER bucket into another pool/bucket_alloc that may |
1312 | | * have a separate lifetime than the source bucket/pool. |
1313 | | * @param source the header bucket to clone |
1314 | | * @param p A pool to allocate the data out of. |
1315 | | * @param list The bucket allocator from which to allocate the bucket |
1316 | | * @return The new bucket, or NULL if allocation failed |
1317 | | */ |
1318 | | AP_DECLARE(apr_bucket *) ap_bucket_headers_clone(apr_bucket *source, |
1319 | | apr_pool_t *p, |
1320 | | apr_bucket_alloc_t *list); |
1321 | | |
1322 | | AP_DECLARE_NONSTD(apr_status_t) ap_byterange_filter(ap_filter_t *f, apr_bucket_brigade *b); |
1323 | | AP_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f, apr_bucket_brigade *b); |
1324 | | AP_DECLARE_NONSTD(apr_status_t) ap_content_length_filter(ap_filter_t *, |
1325 | | apr_bucket_brigade *); |
1326 | | AP_DECLARE_NONSTD(apr_status_t) ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b); |
1327 | | |
1328 | | /** |
1329 | | * Sett up the protocol fields for subsidiary requests |
1330 | | * @param rnew New Sub Request |
1331 | | * @param r current request |
1332 | | */ |
1333 | | AP_DECLARE(void) ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r); |
1334 | | |
1335 | | /** |
1336 | | * A wrapup function to keep the internal accounting straight. |
1337 | | * Indicates that there is no more content coming. |
1338 | | * @param sub_r Subrequest that is now compete |
1339 | | */ |
1340 | | AP_DECLARE(void) ap_finalize_sub_req_protocol(request_rec *sub_r); |
1341 | | |
1342 | | /** |
1343 | | * Set standard response headers, such as `Date` and `Server` |
1344 | | * in r->headers_out. Takes care of precedence of existing |
1345 | | * values from proxied requests. |
1346 | | */ |
1347 | | AP_DECLARE(void) ap_set_std_response_headers(request_rec *r); |
1348 | | |
1349 | | /** |
1350 | | * Send an interim (HTTP 1xx) response immediately. |
1351 | | * @param r The request |
1352 | | * @param send_headers Whether to send&clear headers in r->headers_out |
1353 | | */ |
1354 | | AP_DECLARE(void) ap_send_interim_response(request_rec *r, int send_headers); |
1355 | | |
1356 | | /** |
1357 | | * Append a header in HTTP/1.1 format to the brigade. |
1358 | | * @param b the brigade to append to |
1359 | | * @param p the pool to use |
1360 | | * @param name the name of the header field |
1361 | | * @param value the value of the header field |
1362 | | */ |
1363 | | AP_DECLARE(apr_status_t) ap_h1_append_header(apr_bucket_brigade *b, |
1364 | | apr_pool_t *pool, |
1365 | | const char *name, const char *value); |
1366 | | /** |
1367 | | * Append the headers in HTTP/1.1 format to the brigade. |
1368 | | * @param b the brigade to append to |
1369 | | * @param r the request this is done for (pool and logging) |
1370 | | * @param headers the headers to append |
1371 | | */ |
1372 | | AP_DECLARE(apr_status_t) ap_h1_append_headers(apr_bucket_brigade *b, |
1373 | | request_rec *r, |
1374 | | apr_table_t *headers); |
1375 | | |
1376 | | /** |
1377 | | * Append the HTTP/1.1 header termination (empty CRLF) to the brigade. |
1378 | | * @param b the brigade to append to |
1379 | | */ |
1380 | | AP_DECLARE(apr_status_t) ap_h1_terminate_header(apr_bucket_brigade *b); |
1381 | | |
1382 | | /** |
1383 | | * Insert/Append the last chunk in a HTTP/1.1 Transfer-Encoding chunked. |
1384 | | * @param b the brigade to add the chunk to |
1385 | | * @param eos the bucket before to add or NULL for insert at tail |
1386 | | * @param r the request handled |
1387 | | * @param trailers table of trailers or NULL |
1388 | | */ |
1389 | | AP_DECLARE(void) ap_h1_add_end_chunk(apr_bucket_brigade *b, |
1390 | | apr_bucket *eos, |
1391 | | request_rec *r, |
1392 | | apr_table_t *trailers); |
1393 | | |
1394 | | #ifdef __cplusplus |
1395 | | } |
1396 | | #endif |
1397 | | |
1398 | | #endif /* !APACHE_HTTP_PROTOCOL_H */ |
1399 | | /** @} */ |