Apache HTTPD
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
36extern "C" {
37#endif
38
44AP_DECLARE_HOOK(void,insert_error_filter,(request_rec *r))
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
105
106/* Finish up stuff after a request */
107
114
124AP_DECLARE(void) ap_send_error_response(request_rec *r, int recursive_error);
125
126/* Set last modified header line from the lastmod date of the associated file.
127 * Also, set content length.
128 *
129 * May return an error status, typically HTTP_NOT_MODIFIED (that when the
130 * permit_cache argument is set to one).
131 */
132
139
146
155
168 const char *type);
169
175
177typedef struct etag_rec etag_rec;
178
196
205AP_DECLARE(char *) ap_make_etag(request_rec *r, int force_weak);
206
214
220
227
233
240
250 apr_table_t *headers);
251
262 apr_table_t *headers);
263
274 apr_table_t *headers);
275
286 apr_table_t *headers);
287
298 apr_table_t *headers);
299
309
310/* Other ways to send stuff at the client. All of these keep track
311 * of bytes_sent automatically. This indirection is intended to make
312 * it a little more painless to slide things like HTTP-NG packetization
313 * underneath the main body of the code later. In the meantime, it lets
314 * us centralize a bit of accounting (bytes_sent).
315 *
316 * These also return the number of bytes written by the call.
317 * They should only be called with a timeout registered, for obvious reaasons.
318 * (Ditto the send_header stuff).
319 */
320
331 apr_size_t length, apr_size_t *nbytes);
332
333#if APR_HAS_MMAP
342AP_DECLARE(apr_size_t) ap_send_mmap(apr_mmap_t *mm,
343 request_rec *r,
344 apr_size_t offset,
345 apr_size_t length);
346#endif
347
348
357AP_DECLARE(int) ap_method_register(apr_pool_t *p, const char *methname);
358
365
370#define AP_METHOD_CHECK_ALLOWED(mask, methname) \
371 ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
372
383
384
393
403
413
422 const char *method);
423
431
439AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct);
440
450AP_DECLARE(void) ap_set_content_type_ex(request_rec *r, const char *ct, int trusted);
451
457
458
459/* Hmmm... could macrofy these for now, and maybe forever, though the
460 * definitions of the macros would get a whole lot hairier.
461 */
462
469AP_DECLARE(int) ap_rputc(int c, request_rec *r);
470
478AP_DECLARE(int) ap_rwrite(const void *buf, int nbyte, request_rec *r);
479
487static APR_INLINE int ap_rputs(const char *str, request_rec *r)
488{
489 apr_size_t len;
490
491 len = strlen(str);
492
493 for (;;) {
494 if (len <= INT_MAX) {
495 return ap_rwrite(str, (int)len, r);
496 }
497 else {
498 int rc;
499
500 rc = ap_rwrite(str, INT_MAX, r);
501 if (rc < 0) {
502 return rc;
503 }
504 else {
505 str += INT_MAX;
506 len -= INT_MAX;
507 }
508 }
509 }
510}
511
520
528AP_DECLARE(int) ap_vrprintf(request_rec *r, const char *fmt, va_list vlist);
529
538 __attribute__((format(printf,2,3)));
539
546
554
562AP_DECLARE(const char *) ap_get_status_line(int status);
563
574
575/* Reading a block of data from the client connection (e.g., POST arg) */
576
588AP_DECLARE(int) ap_setup_client_block(request_rec *r, int read_policy);
589
599
609AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz);
610
627
639
646
651
656
664AP_DECLARE_HOOK(int, note_auth_failure, (request_rec *r, const char *auth_type))
665
682AP_DECLARE(int) ap_get_basic_auth_pw(request_rec *r, const char **pw);
683
684#define AP_GET_BASIC_AUTH_PW_NOTE "AP_GET_BASIC_AUTH_PW_NOTE"
685
700 const char **username,
701 const char **password);
702
712AP_CORE_DECLARE(void) ap_parse_uri(request_rec *r, const char *uri);
713
714#define AP_GETLINE_FOLD 1 /* Whether to merge continuation lines */
715#define AP_GETLINE_CRLF 2 /* Whether line ends must be in the form CR LF */
716#define AP_GETLINE_NOSPC_EOL 4 /* Whether to consume up to and including the
717 end of line on APR_ENOSPC */
718
731AP_DECLARE(int) ap_getline(char *s, int n, request_rec *r, int flags);
732
757#if APR_CHARSET_EBCDIC
758AP_DECLARE(apr_status_t) ap_rgetline(char **s, apr_size_t n,
759 apr_size_t *read,
760 request_rec *r, int flags,
762#else /* ASCII box */
763#define ap_rgetline(s, n, read, r, fold, bb) \
764 ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
765#endif
766
768AP_DECLARE(apr_status_t) ap_rgetline_core(char **s, apr_size_t n,
769 apr_size_t *read,
770 request_rec *r, int flags,
772
779AP_DECLARE(int) ap_method_number_of(const char *method);
780
788AP_DECLARE(const char *) ap_method_name_of(apr_pool_t *p, int methnum);
789
790
791/* Hooks */
792/*
793 * pre_read_request --- run right before read_request_line(),
794 * and not run during any subrequests.
795 */
803AP_DECLARE_HOOK(void,pre_read_request,(request_rec *r, conn_rec *c))
804
805/*
806 * post_read_request --- run right after read_request or internal_redirect,
807 * and not run during any subrequests.
808 */
816AP_DECLARE_HOOK(int,post_read_request,(request_rec *r))
817
818
824AP_DECLARE_HOOK(int,log_transaction,(request_rec *r))
825
826
832AP_DECLARE_HOOK(const char *,http_scheme,(const request_rec *r))
833
834
839AP_DECLARE_HOOK(apr_port_t,default_port,(const request_rec *r))
840
842#define AP_PROTOCOL_HTTP1 "http/1.1"
843
882AP_DECLARE_HOOK(int,protocol_propose,(conn_rec *c, request_rec *r,
883 server_rec *s,
884 const apr_array_header_t *offers,
885 apr_array_header_t *proposals))
886
887
914AP_DECLARE_HOOK(int,protocol_switch,(conn_rec *c, request_rec *r,
916 const char *protocol))
917
918
933AP_DECLARE_HOOK(const char *,protocol_get,(const conn_rec *c))
934
935
956 server_rec *s, int report_all,
957 const apr_array_header_t **pupgrades);
958
979 server_rec *s,
980 const apr_array_header_t *choices);
981
1001 server_rec *s,
1002 const char *protocol);
1003
1019AP_DECLARE(const char *) ap_get_protocol(conn_rec *c);
1020
1040 server_rec *s, const char *protocol);
1041
1043typedef struct ap_bucket_error ap_bucket_error;
1044
1054struct ap_bucket_error {
1058 int status;
1060 const char *data;
1061};
1062
1065
1071#define AP_BUCKET_IS_ERROR(e) (e->type == &ap_bucket_type_error)
1072
1082 const char *buf, apr_pool_t *p);
1083
1093 apr_pool_t *p,
1095
1101
1108
1115
1122
1123
1124
1125#ifdef __cplusplus
1126}
1127#endif
1128
1129#endif /* !APACHE_HTTP_PROTOCOL_H */
#define AP_DECLARE_DATA
Definition ap_config.h:89
#define AP_DECLARE_NONSTD(type)
Definition ap_config.h:77
#define AP_FN_ATTR_SENTINEL
Definition ap_config.h:185
#define AP_DECLARE(type)
Definition ap_config.h:67
#define AP_DECLARE_HOOK(ret, name, args)
Definition ap_hooks.h:74
int n
Definition ap_regex.h:278
const char apr_size_t len
Definition ap_regex.h:187
APR-UTIL Buckets/Bucket Brigades.
APR MMAP routines.
APR Portability Routines.
request_rec * r
#define AP_CORE_DECLARE
Definition httpd.h:381
const unsigned char * buf
Definition util_md5.h:50
int int ap_rflush(request_rec *r)
Definition protocol.c:2253
int ap_method_number_of(const char *method)
int ap_parse_request_line(request_rec *r)
Definition protocol.c:721
ap_condition_e
void ap_set_etag(request_rec *r)
Definition http_etag.c:367
void ap_method_registry_init(apr_pool_t *p)
void ap_finalize_sub_req_protocol(request_rec *sub_r)
Definition protocol.c:1710
void ap_setup_make_content_type(apr_pool_t *pool)
Definition protocol.c:87
int ap_rvputs(request_rec *r,...)
Definition protocol.c:2220
void ap_set_accept_ranges(request_rec *r)
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 protocol.c:2403
int ap_map_http_request_error(apr_status_t rv, int status)
int ap_meets_conditions(request_rec *r)
ap_condition_e ap_condition_if_modified_since(request_rec *r, apr_table_t *headers)
int ap_method_register(apr_pool_t *p, const char *methname)
void ap_method_list_remove(ap_method_list_t *l, const char *method)
ap_method_list_t * ap_make_method_list(apr_pool_t *p, int nelts)
void ap_set_etag_fd(request_rec *r, apr_file_t *fd)
Definition http_etag.c:391
void ap_method_list_add(ap_method_list_t *l, const char *method)
void ap_send_interim_response(request_rec *r, int send_headers)
Definition protocol.c:2316
void ap_parse_uri(request_rec *r, const char *uri)
Definition protocol.c:580
apr_time_t ap_rationalize_mtime(request_rec *r, apr_time_t mtime)
Definition protocol.c:174
void ap_note_digest_auth_failure(request_rec *r)
Definition protocol.c:1753
void ap_send_error_response(request_rec *r, int recursive_error)
void ap_finalize_request_protocol(request_rec *r)
Definition protocol.c:1723
void ap_note_auth_failure(request_rec *r)
Definition protocol.c:1736
#define ap_rgetline(s, n, read, r, fold, bb)
int ap_get_basic_auth_pw(request_rec *r, const char **pw)
Definition protocol.c:1758
void ap_note_basic_auth_failure(request_rec *r)
Definition protocol.c:1748
apr_status_t ap_http_header_filter(ap_filter_t *f, apr_bucket_brigade *b)
int ap_set_keepalive(request_rec *r)
void ap_set_sub_req_protocol(request_rec *rnew, const request_rec *r)
Definition protocol.c:1655
ap_condition_e ap_condition_if_range(request_rec *r, apr_table_t *headers)
int ap_rprintf(request_rec *r, const char *fmt,...) __attribute__((format(printf
ap_condition_e ap_condition_if_unmodified_since(request_rec *r, apr_table_t *headers)
const char * ap_get_status_line_ex(apr_pool_t *p, int status)
int ap_should_client_block(request_rec *r)
apr_status_t ap_get_basic_auth_components(const request_rec *r, const char **username, const char **password)
Definition protocol.c:1802
int ap_index_of_response(int status)
request_rec * ap_create_request(conn_rec *c)
Definition protocol.c:1356
int ap_post_read_request(request_rec *r)
Definition protocol.c:1608
void ap_set_content_length(request_rec *r, apr_off_t length)
Definition protocol.c:160
apr_status_t ap_switch_protocol(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
Definition protocol.c:2532
request_rec * ap_read_request(conn_rec *c)
Definition protocol.c:1423
const char * ap_get_protocol(conn_rec *c)
Definition protocol.c:2397
apr_bucket * ap_bucket_error_make(apr_bucket *b, int error, const char *buf, apr_pool_t *p)
const char * ap_select_protocol(conn_rec *c, request_rec *r, server_rec *s, const apr_array_header_t *choices)
Definition protocol.c:2444
static APR_INLINE int ap_rputs(const char *str, request_rec *r)
int ap_method_in_list(ap_method_list_t *l, const char *method)
int ap_rputc(int c, request_rec *r)
Definition protocol.c:2117
void ap_set_last_modified(request_rec *r)
Definition protocol.c:2280
const char * ap_make_content_type(request_rec *r, const char *type)
Definition protocol.c:110
void ap_set_content_type_ex(request_rec *r, const char *ct, int trusted)
void ap_clear_method_list(ap_method_list_t *l)
void ap_get_mime_headers_core(request_rec *r, apr_bucket_brigade *bb)
Definition protocol.c:1089
void ap_set_content_type(request_rec *r, const char *ct)
apr_status_t ap_byterange_filter(ap_filter_t *f, apr_bucket_brigade *b)
const char * ap_method_name_of(apr_pool_t *p, int methnum)
int ap_check_request_header(request_rec *r)
Definition protocol.c:1000
int ap_getline(char *s, int n, request_rec *r, int flags)
Definition protocol.c:545
void ap_copy_method_list(ap_method_list_t *dest, ap_method_list_t *src)
ap_condition_e ap_condition_if_match(request_rec *r, apr_table_t *headers)
ap_condition_e ap_condition_if_none_match(request_rec *r, apr_table_t *headers)
char * ap_make_etag_ex(request_rec *r, etag_rec *er)
Definition http_etag.c:214
apr_status_t ap_content_length_filter(ap_filter_t *, apr_bucket_brigade *)
Definition protocol.c:1861
const apr_bucket_type_t ap_bucket_type_error
int ap_rwrite(const void *buf, int nbyte, request_rec *r)
Definition protocol.c:2131
long ap_get_client_block(request_rec *r, char *buffer, apr_size_t bufsiz)
const char * ap_get_status_line(int status)
int ap_setup_client_block(request_rec *r, int read_policy)
int ap_is_allowed_protocol(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
Definition protocol.c:2564
int ap_discard_request_body(request_rec *r)
apr_status_t ap_rgetline_core(char **s, apr_size_t n, apr_size_t *read, request_rec *r, int flags, apr_bucket_brigade *bb)
Definition protocol.c:216
int ap_vrprintf(request_rec *r, const char *fmt, va_list vlist)
Definition protocol.c:2176
ap_filter_rec_t * ap_old_write_func
Definition protocol.c:75
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)
Definition protocol.c:1991
apr_status_t ap_old_write_filter(ap_filter_t *f, apr_bucket_brigade *b)
Definition protocol.c:2039
void ap_get_mime_headers(request_rec *r)
Definition protocol.c:1348
char * ap_make_etag(request_rec *r, int force_weak)
Definition http_etag.c:353
apr_bucket * ap_bucket_error_create(int error, const char *buf, apr_pool_t *p, apr_bucket_alloc_t *list)
@ AP_CONDITION_NONE
@ AP_CONDITION_STRONG
@ AP_CONDITION_WEAK
@ AP_CONDITION_NOMATCH
apr_file_t * f
apr_brigade_flush void const char apr_size_t nbyte
apr_file_t * fd
int apr_off_t * length
apr_pool_t const char apr_dbd_t const char ** error
Definition apr_dbd.h:143
const char * src
Definition apr_encode.h:167
const char apr_ssize_t int flags
Definition apr_encode.h:168
apr_redis_t * rc
Definition apr_redis.h:173
const char * uri
Definition apr_uri.h:159
const char int apr_pool_t * pool
Definition apr_cstr.h:84
const apr_array_header_t * list
Definition apr_cstr.h:105
int apr_status_t
Definition apr_errno.h:44
void apr_size_t * nbytes
apr_seek_where_t apr_off_t * offset
const char * format
int type
apr_time_t mtime
char * buffer
apr_vformatter_buff_t const char * fmt
Definition apr_lib.h:175
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_uint16_t apr_port_t
int int int protocol
apr_uint32_t apr_pool_t apr_uint32_t apr_pollset_method_e method
Definition apr_poll.h:195
apr_pool_t * b
Definition apr_pools.h:529
const char apr_status_t(*) apr_pool_t *poo __attribute__)((nonnull(2, 4)))
Definition apr_pools.h:567
const char * s
Definition apr_strings.h:95
int nelts
Definition apr_tables.h:122
const char const char * password
const char * username
int int status
apr_int64_t apr_time_t
Definition apr_time.h:45
static const char * http_scheme(const request_rec *r)
Definition http_core.c:113
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
static int send_headers(request_rec *r, proxy_conn_rec *conn)
A bucket referring to an HTTP error.
const char * data
apr_bucket_refcount refcount
This structure is used for recording information about the registered filters. It associates a name w...
The representation of a filter chain.
Structure for handling HTTP methods.
Definition httpd.h:643
Structure to store things which are per connection.
Definition httpd.h:1152
A structure with the ingredients for a file based etag.
const char * pathname
apr_time_t request_time
apr_file_t * fd
const char * vlist_validator
apr_finfo_t * finfo
A structure that represents the current request.
Definition httpd.h:845
A structure to store information for each virtual server.
Definition httpd.h:1322
#define str
Apache filter library.