Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
http_protocol.h
Go to the documentation of this file.
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 
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 
45 
46 
50 
51 /*
52  * Prototypes for routines which either talk directly back to the user,
53  * or control the ones that eventually do.
54  */
55 
62 
69 
76 
83 
89 
98 
99 /* Finish up stuff after a request */
100 
107 
117 AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
118 
119 /* Set last modified header line from the lastmod date of the associated file.
120  * Also, set content length.
121  *
122  * May return an error status, typically HTTP_NOT_MODIFIED (that when the
123  * permit_cache argument is set to one).
124  */
125 
132 
139 
148 
161  const char *type);
162 
168 
170 typedef struct etag_rec etag_rec;
171 
175 struct etag_rec {
177  const char *vlist_validator;
183  const char *pathname;
188 };
189 
198 AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
199 
207 
213 
220 
226 
227 typedef enum {
233 
243  apr_table_t *headers);
244 
255  apr_table_t *headers);
256 
267  apr_table_t *headers);
268 
279  apr_table_t *headers);
280 
291  apr_table_t *headers);
292 
302 
303 /* Other ways to send stuff at the client. All of these keep track
304  * of bytes_sent automatically. This indirection is intended to make
305  * it a little more painless to slide things like HTTP-NG packetization
306  * underneath the main body of the code later. In the meantime, it lets
307  * us centralize a bit of accounting (bytes_sent).
308  *
309  * These also return the number of bytes written by the call.
310  * They should only be called with a timeout registered, for obvious reaasons.
311  * (Ditto the send_header stuff).
312  */
313 
324  apr_size_t length, apr_size_t *nbytes);
325 
326 #if APR_HAS_MMAP
327 
336  request_rec *r,
337  apr_size_t offset,
338  apr_size_t length);
339 #endif
340 
341 
350 AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
351 
358 
363 #define AP_METHOD_CHECK_ALLOWED(mask, methname) \
364  ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
365 
376 
377 
386 
395 AP_DECLARE(int) ap_method_in_list(ap_method_list_t *l, const char *method);
396 
405 AP_DECLARE(void) ap_method_list_add(ap_method_list_t *l, const char *method);
406 
415  const char *method);
416 
424 
432 AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct);
433 
439 
440 
441 /* Hmmm... could macrofy these for now, and maybe forever, though the
442  * definitions of the macros would get a whole lot hairier.
443  */
444 
451 AP_DECLARE(int) ap_rputc(int c, request_rec *r);
452 
460 AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
461 
469 static APR_INLINE int ap_rputs(const char *str, request_rec *r)
470 {
471  return ap_rwrite(str, (int)strlen(str), r);
472 }
473 
482 
490 AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
491 
499 AP_DECLARE_NONSTD(int) ap_rprintf(request_rec *r, const char *fmt,...)
500  __attribute__((format(printf,2,3)));
501 
508 
516 
524 AP_DECLARE(const char *) ap_get_status_line(int status);
525 
535 AP_DECLARE(const char *) ap_get_status_line_ex(apr_pool_t *p, int status);
536 
537 /* Reading a block of data from the client connection (e.g., POST arg) */
538 
550 AP_DECLARE(int) ap_setup_client_block(request_rec *r, int read_policy);
551 
561 
571 AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz);
572 
589 
601 
608 
613 
618 
626 AP_DECLARE_HOOK(int, note_auth_failure, (request_rec *r, const char *auth_type))
627 
651 AP_DECLARE(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
652 
653 #define AP_GET_BASIC_AUTH_PW_NOTE "AP_GET_BASIC_AUTH_PW_NOTE"
654 
669  const char **username,
670  const char **password);
671 
681 AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri);
682 
683 #define AP_GETLINE_FOLD (1 << 0) /* Whether to merge continuation lines */
684 #define AP_GETLINE_CRLF (1 << 1) /* Whether line ends must be CRLF */
685 #define AP_GETLINE_NOSPC_EOL (1 << 2) /* Whether to consume up to and including
686  the end of line on APR_ENOSPC */
687 #define AP_GETLINE_NONBLOCK (1 << 3) /* Whether to read non-blocking */
688 
699 AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags);
700 
718  apr_size_t *read, ap_filter_t *f,
719  int flags, apr_bucket_brigade *bb,
720  apr_pool_t *p);
721 
729  apr_size_t *read, request_rec *r,
730  int flags, apr_bucket_brigade *bb);
731 
738 AP_DECLARE(int) ap_method_number_of(const char *method);
739 
747 AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum);
748 
749 
750 /* Hooks */
751 /*
752  * pre_read_request --- run right before read_request_line(),
753  * and not run during any subrequests.
754  */
763 
764 /*
765  * post_read_request --- run right after read_request or internal_redirect,
766  * and not run during any subrequests.
767  */
776 
784 
791 AP_DECLARE_HOOK(const char *,http_scheme,(const request_rec *r))
792 
799 
800 
801 #define AP_PROTOCOL_HTTP1 "http/1.1"
802 
838  server_rec *s,
839  const apr_array_header_t *offers,
840  apr_array_header_t *proposals))
841 
842 
866  server_rec *s,
867  const char *protocol))
868 
869 
880 AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c))
881 
882 
899  server_rec *s, int report_all,
900  const apr_array_header_t **pupgrades);
901 
917 AP_DECLARE(const char *) ap_select_protocol(conn_rec *c, request_rec *r,
918  server_rec *s,
919  const apr_array_header_t *choices);
920 
936  server_rec *s,
937  const char *protocol);
938 
950 AP_DECLARE(const char *) ap_get_protocol(conn_rec *c);
951 
967  server_rec *s, const char *protocol);
968 
971 
981 struct ap_bucket_error {
985  int status;
987  const char *data;
988 };
989 
992 
998 #define AP_BUCKET_IS_ERROR(e) (e->type == &ap_bucket_type_error)
999 
1009  const char *buf, apr_pool_t *p);
1010 
1019 AP_DECLARE(apr_bucket *) ap_bucket_error_create(int error, const char *buf,
1020  apr_pool_t *p,
1021  apr_bucket_alloc_t *list);
1022 
1026  apr_bucket_brigade *);
1027 AP_DECLARE_NONSTD(apr_status_t) ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b);
1028 
1035 
1042 
1048 AP_DECLARE(void) ap_send_interim_response(request_rec *r, int send_headers);
1049 
1050 
1051 #ifdef __cplusplus
1052 }
1053 #endif
1054 
1055 #endif /* !APACHE_HTTP_PROTOCOL_H */
1056 
This structure is used for recording information about the registered filters. It associates a name w...
Definition: util_filter.h:226
apr_status_t ap_fgetline(char **s, apr_size_t n, apr_size_t *read, ap_filter_t *f, int flags, apr_bucket_brigade *bb, apr_pool_t *p)
size_t apr_size_t
Definition: apr.h:393
A bucket referring to an HTTP error.
Definition: http_protocol.h:981
int ap_discard_request_body(request_rec *r)
Definition: http_protocol.h:230
#define AP_CORE_DECLARE(x)
Definition: macros.h:3
int protocol_propose(conn_rec *c, request_rec *r, server_rec *s, const apr_array_header_t *offers, apr_array_header_t *proposals)
int ap_should_client_block(request_rec *r)
Definition: apr_arch_file_io.h:107
Definition: apr_tables.h:62
int ap_index_of_response(int status)
apr_status_t ap_switch_protocol(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
void ap_finalize_sub_req_protocol(request_rec *sub_r)
long ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz)
int force_weak
Definition: http_protocol.h:187
ap_method_list_t * ap_make_method_list(apr_pool_t *p, int nelts)
int ap_is_allowed_protocol(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
The representation of a filter chain.
Definition: util_filter.h:278
void ap_set_etag(request_rec *r)
#define AP_FN_ATTR_SENTINEL
Definition: ap_config.h:231
struct apr_bucket_alloc_t apr_bucket_alloc_t
Definition: apr_buckets.h:123
apr_bucket_brigade request_rec apr_pool_t * pool
Definition: mod_dav.h:555
const char * ap_method_name_of(apr_pool_t *p, int methnum)
int ap_getline(char *s, int n, request_rec *r, int flags)
A structure with the ingredients for a file based etag.
Definition: http_protocol.h:175
int ap_set_keepalive(request_rec *r)
#define AP_DECLARE(x)
Definition: macros.h:1
int status
Definition: http_protocol.h:985
void ap_note_auth_failure(request_rec *r)
request_rec * ap_create_request(conn_rec *c)
void ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb)
const char * ap_get_status_line_ex(apr_pool_t *p, int status)
const char * pathname
Definition: http_protocol.h:183
void ap_set_content_length(request_rec *r, apr_off_t length)
void ap_copy_method_list(ap_method_list_t *dest, ap_method_list_t *src)
void insert_error_filter(request_rec *r)
#define AP_DECLARE_NONSTD(x)
Definition: macros.h:2
void ap_set_content_type(request_rec *r, const char *ct)
const char * ap_get_protocol(conn_rec *c)
apr_status_t ap_get_protocol_upgrades(conn_rec *c, request_rec *r, server_rec *s, int report_all, const apr_array_header_t **pupgrades)
Definition: http_protocol.h:229
void ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r)
void ap_method_list_remove(ap_method_list_t *l, const char *method)
ap_condition_e ap_condition_if_modified_since(request_rec *r, apr_table_t *headers)
const char const char * uri
Definition: mod_dav.h:631
apr_status_t ap_content_length_filter(ap_filter_t *, apr_bucket_brigade *)
int log_transaction(request_rec *r)
Definition: apr_buckets.h:258
int ap_method_number_of(const char *method)
int protocol_switch(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
int post_read_request(request_rec *r)
Structure to store things which are per connection.
Definition: httpd.h:1183
int ap_parse_request_line(request_rec *r)
void ap_method_registry_init(apr_pool_t *p)
void ap_send_error_response(request_rec *r, int recursive_error)
char * ap_make_etag_ex(request_rec *r, etag_rec *er)
void ap_note_digest_auth_failure(request_rec *r)
const char * ap_select_protocol(conn_rec *c, request_rec *r, server_rec *s, const apr_array_header_t *choices)
apr_status_t ap_get_basic_auth_components(const request_rec *r, const char **username, const char **password)
const char * vlist_validator
Definition: http_protocol.h:177
int int ap_rflush(request_rec *r)
Definition: apr_mmap.h:62
#define AP_DECLARE_HOOK(ret, name, args)
Definition: ap_hooks.h:74
void ap_method_list_add(ap_method_list_t *l, const char *method)
apr_int64_t apr_time_t
Definition: apr_time.h:45
void ap_set_last_modified(request_rec *r)
apr_file_t * fd
Definition: http_protocol.h:185
apr_bucket_brigade * bb
Definition: mod_dav.h:555
HTTP Daemon routines.
AP_DECLARE_DATA ap_filter_rec_t * ap_old_write_func
void ap_setup_make_content_type(apr_pool_t *pool)
apr_port_t default_port(const request_rec *r)
A structure to store information for each virtual server.
Definition: httpd.h:1370
int ap_map_http_request_error(apr_status_t rv, int status)
int note_auth_failure(request_rec *r, const char *auth_type)
Definition: apr_buckets.h:224
ap_condition_e ap_condition_if_unmodified_since(request_rec *r, apr_table_t *headers)
apr_time_t request_time
Definition: http_protocol.h:179
dav_error * src
Definition: mod_dav.h:186
ap_condition_e
Definition: http_protocol.h:227
void ap_note_basic_auth_failure(request_rec *r)
int ap_rvputs(request_rec *r,...) AP_FN_ATTR_SENTINEL
const char * data
Definition: http_protocol.h:987
APR-UTIL Buckets/Bucket Brigades.
apr_status_t ap_rgetline(char **s, apr_size_t n, apr_size_t *read, request_rec *r, int flags, apr_bucket_brigade *bb)
apr_status_t ap_send_fd(apr_file_t *fd, request_rec *r, apr_off_t offset, apr_size_t length, apr_size_t *nbytes)
request_rec * ap_read_request(conn_rec *c)
void pre_read_request(request_rec *r, conn_rec *c)
void ap_clear_method_list(ap_method_list_t *l)
void ap_set_accept_ranges(request_rec *r)
int ap_vrprintf(request_rec *r, const char *fmt, va_list vlist)
apr_status_t ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b)
apr_size_t ap_send_mmap(apr_mmap_t *mm, request_rec *r, apr_size_t offset, apr_size_t length)
APR MMAP routines.
int ap_setup_client_block(request_rec *r, int read_policy)
#define APR_INLINE
Definition: apr.h:65
AP_DECLARE_DATA const apr_bucket_type_t ap_bucket_type_error
Definition: apr_buckets.h:534
apr_pool_t * p
const char * ap_make_content_type(request_rec *r, const char *type)
void ap_send_interim_response(request_rec *r, int send_headers)
ap_condition_e ap_condition_if_match(request_rec *r, apr_table_t *headers)
apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime)
A structure that represents the current request.
Definition: httpd.h:860
Apache filter library.
void ap_set_etag_fd(request_rec *r, apr_file_t *fd)
Structure for handling HTTP methods.
Definition: httpd.h:662
int ap_rputc(int c, request_rec *r)
#define AP_DECLARE_DATA
Definition: macros.h:15
dav_buffer const char * str
Definition: mod_dav.h:464
apr_bucket * ap_bucket_error_make(apr_bucket *b, int error, const char *buf, apr_pool_t *p)
int status
Definition: mod_dav.h:141
struct apr_table_t apr_table_t
Definition: apr_tables.h:56
#define __attribute__(__x)
Definition: apr.h:63
const char * http_scheme(const request_rec *r)
const char * protocol_get(const conn_rec *c)
Definition: apr_buckets.h:131
struct apr_pool_t apr_pool_t
Definition: apr_pools.h:60
apr_bucket * ap_bucket_error_create(int error, const char *buf, apr_pool_t *p, apr_bucket_alloc_t *list)
apr_status_t ap_byterange_filter(ap_filter_t *f, apr_bucket_brigade *b)
int apr_status_t
Definition: apr_errno.h:44
int ap_rprintf(request_rec *r, const char *fmt,...) __attribute__((format(printf
int ap_method_in_list(ap_method_list_t *l, const char *method)
int ap_rwrite(const void *buf, int nbyte, request_rec *r)
request_rec * r
Definition: mod_dav.h:518
int ap_method_register(apr_pool_t *p, const char *methname)
apr_uint16_t apr_port_t
Definition: apr_network_io.h:257
char * ap_make_etag(request_rec *r, int force_weak)
int ap_get_basic_auth_pw(request_rec *r, const char **pw)
void ap_get_mime_headers(request_rec *r)
apr_finfo_t * finfo
Definition: http_protocol.h:181
dav_resource int dav_locktoken dav_response int flags
Definition: mod_dav.h:1452
int ap_check_request_header(request_rec *r)
const char * ap_get_status_line(int status)
Definition: http_protocol.h:228
int ap_meets_conditions(request_rec *r)
apr_status_t ap_http_header_filter(ap_filter_t *f, apr_bucket_brigade *b)
void ap_parse_uri(request_rec *r, const char *uri)
apr_bucket_refcount refcount
Definition: http_protocol.h:983
ap_condition_e ap_condition_if_range(request_rec *r, apr_table_t *headers)
off_t apr_off_t
Definition: apr.h:395
Definition: apr_file_info.h:174
APR Portability Routines.
ap_condition_e ap_condition_if_none_match(request_rec *r, apr_table_t *headers)
Definition: http_protocol.h:231
void ap_finalize_request_protocol(request_rec *r)