Main Page | Modules | Namespace List | Class List | Directories | File List | Class Members | File Members | Related Pages | Examples

http_protocol.h File Reference

#include "httpd.h"
#include "apr_hooks.h"
#include "apr_portable.h"
#include "apr_mmap.h"
#include "apr_buckets.h"
#include "util_filter.h"

Go to the source code of this file.

Classes

struct  ap_bucket_error
 A bucket referring to an HTTP error. More...
#define AP_METHOD_CHECK_ALLOWED(mask, methname)   ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
#define ap_rgetline(s, n, read, r, fold, bb)   ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
#define AP_BUCKET_IS_ERROR(e)   (e->type == &ap_bucket_type_error)
 AP_DECLARE_HOOK (void, insert_error_filter,(request_rec *r)) AP_DECLARE_DATA extern ap_filter_rec_t *ap_old_write_func
request_recap_read_request (conn_rec *c)
 AP_DECLARE (void) ap_get_mime_headers(request_rec *r)
 AP_DECLARE_NONSTD (int) ap_rvputs(request_rec *r
const char __attribute__ ((format(printf, 2, 3)))
 AP_CORE_DECLARE (void) ap_parse_uri(request_rec *r
apr_bucket_brigadebb
int recursive_error
apr_off_t length
apr_time_t mtime
const char * type
int force_weak
request_recr
request_rec apr_off_t offset
request_rec apr_off_t apr_size_t
apr_size_t * 
nbytes
const char * methname
int nelts
ap_method_list_tsrc
const char * method
const char * ct
int nbyte
const char * fmt
const char va_list vlist
int read_policy
char * buffer
char apr_size_t bufsiz
const char ** pw
const char * uri
int n
int request_rec int fold
apr_size_t apr_size_t * read
int methnum
 log_transaction
request_rec *r default_port
typedefrequest_rec *r const
request_rec *r struct ap_bucket_error 
ap_bucket_error
AP_DECLARE_DATA const apr_bucket_type_t ap_bucket_type_error
int error
int const char * buf
int const char apr_pool_tp
const char apr_pool_t apr_bucket_alloc_tlist
apr_bucket_brigadeb
int send_headers


Define Documentation

#define AP_BUCKET_IS_ERROR e   )     (e->type == &ap_bucket_type_error)
 

Determine if a bucket is an error bucket

Parameters:
e The bucket to inspect
Returns:
true or false

Definition at line 623 of file http_protocol.h.

Referenced by AP_CORE_DECLARE_NONSTD(), ap_http_chunk_filter(), and ap_http_outerror_filter().

#define AP_METHOD_CHECK_ALLOWED mask,
methname   )     ((mask) & (AP_METHOD_BIT << ap_method_number_of((methname))))
 

This is a convenience macro to ease with checking a mask against a method name.

Definition at line 241 of file http_protocol.h.

#define ap_rgetline s,
n,
read,
r,
fold,
bb   )     ap_rgetline_core((s), (n), (read), (r), (fold), (bb))
 

Get the next line of input for the request

Note: on ASCII boxes, ap_rgetline is a macro which simply calls ap_rgetline_core to get the line of input.

on EBCDIC boxes, ap_rgetline is a wrapper function which translates ASCII protocol lines to the local EBCDIC code page after getting the line of input.

Parameters:
s Pointer to the pointer to the buffer into which the line should be read; if *s==NULL, a buffer of the necessary size to hold the data will be allocated from the request pool
n The size of the buffer
read The length of the line.
r The request
fold Whether to merge continuation lines
bb Working brigade to use when reading buckets
Returns:
APR_SUCCESS, if successful APR_ENOSPC, if the line is too big to fit in the buffer Other errors where appropriate

Definition at line 529 of file http_protocol.h.

Referenced by ap_proxygetline(), and read_request_line().


Function Documentation

const char __attribute__ (format(printf, 2, 3))   ) 
 

AP_CORE_DECLARE void   ) 
 

parse_uri: break apart the uri

Warning:
Side Effects:
  • sets r->args to rest after '?' (or NULL if no '?')
  • sets r->uri to request uri (without r->args part)
  • sets r->hostname (if not set already) from request (scheme://host:port)
Parameters:
r The current request
uri The uri to break apart

Definition at line 543 of file core.c.

References AP_CORE_DECLARE, ap_get_module_config, core_module, and sconf.

00544 {
00545     core_server_config *sconf = ap_get_module_config(s->module_config,
00546                                                      &core_module);
00547     void **new_space = (void **)apr_array_push(sconf->sec_url);
00548 
00549     *new_space = url_config;
00550 }

request_rec* ap_read_request conn_rec c  ) 
 

Read a request and fill in the fields.

Parameters:
c The current connection
Returns:
The new request_rec

Definition at line 837 of file protocol.c.

References request_rec::allowed_methods, request_rec::ap_auth_type, ap_get_module_config, ap_http_input_filter_handle, AP_REQ_DEFAULT_PATH_INFO, APLOG_ERR, APLOG_INFO, APLOG_MARK, apr_pcalloc, apr_pool_create, apr_socket_timeout_get(), apr_socket_timeout_set(), request_rec::assbackwards, conn_rec::base_server, conn_rec::bucket_alloc, conn_rec::conn_config, request_rec::connection, core_module, request_rec::err_headers_out, request_rec::expecting_100, request_rec::header_only, request_rec::headers_in, request_rec::headers_out, request_rec::hostname, HTTP_BAD_REQUEST, HTTP_EXPECTATION_FAILED, HTTP_OK, HTTP_REQUEST_TIME_OUT, HTTP_REQUEST_URI_TOO_LARGE, HTTP_VERSION, conn_rec::input_filters, request_rec::input_filters, server_rec::limit_req_line, server_rec::lookup_defaults, request_rec::notes, NULL, conn_rec::output_filters, request_rec::output_filters, p, request_rec::per_dir_config, conn_rec::pool, request_rec::pool, request_rec::proto_input_filters, request_rec::proto_num, request_rec::proto_output_filters, request_rec::read_body, request_rec::read_length, read_request_line(), request_rec::request_config, REQUEST_NO_BODY, conn_rec::sbh, request_rec::sent_bodyct, request_rec::server, SERVER_BUSY_LOG, request_rec::status, strcasecmp(), request_rec::subprocess_env, request_rec::the_request, server_rec::timeout, request_rec::uri, request_rec::used_path_info, and request_rec::user.

Referenced by ap_process_http_async_connection(), and ap_process_http_connection().

00838 {
00839     request_rec *r;
00840     apr_pool_t *p;
00841     const char *expect;
00842     int access_status;
00843     apr_bucket_brigade *tmp_bb;
00844     apr_socket_t *csd;
00845     apr_interval_time_t cur_timeout;
00846 
00847     apr_pool_create(&p, conn->pool);
00848     apr_pool_tag(p, "request");
00849     r = apr_pcalloc(p, sizeof(request_rec));
00850     r->pool            = p;
00851     r->connection      = conn;
00852     r->server          = conn->base_server;
00853 
00854     r->user            = NULL;
00855     r->ap_auth_type    = NULL;
00856 
00857     r->allowed_methods = ap_make_method_list(p, 2);
00858 
00859     r->headers_in      = apr_table_make(r->pool, 25);
00860     r->subprocess_env  = apr_table_make(r->pool, 25);
00861     r->headers_out     = apr_table_make(r->pool, 12);
00862     r->err_headers_out = apr_table_make(r->pool, 5);
00863     r->notes           = apr_table_make(r->pool, 5);
00864 
00865     r->request_config  = ap_create_request_config(r->pool);
00866     /* Must be set before we run create request hook */
00867 
00868     r->proto_output_filters = conn->output_filters;
00869     r->output_filters  = r->proto_output_filters;
00870     r->proto_input_filters = conn->input_filters;
00871     r->input_filters   = r->proto_input_filters;
00872     ap_run_create_request(r);
00873     r->per_dir_config  = r->server->lookup_defaults;
00874 
00875     r->sent_bodyct     = 0;                      /* bytect isn't for body */
00876 
00877     r->read_length     = 0;
00878     r->read_body       = REQUEST_NO_BODY;
00879 
00880     r->status          = HTTP_REQUEST_TIME_OUT;  /* Until we get a request */
00881     r->the_request     = NULL;
00882 
00883     /* Begin by presuming any module can make its own path_info assumptions,
00884      * until some module interjects and changes the value.
00885      */
00886     r->used_path_info = AP_REQ_DEFAULT_PATH_INFO;
00887 
00888     tmp_bb = apr_brigade_create(r->pool, r->connection->bucket_alloc);
00889 
00890     /* Get the request... */
00891     if (!read_request_line(r, tmp_bb)) {
00892         if (r->status == HTTP_REQUEST_URI_TOO_LARGE) {
00893             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
00894                           "request failed: URI too long (longer than %d)", r->server->limit_req_line);
00895             ap_send_error_response(r, 0);
00896             ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
00897             ap_run_log_transaction(r);
00898             apr_brigade_destroy(tmp_bb);
00899             return r;
00900         }
00901 
00902         apr_brigade_destroy(tmp_bb);
00903         return NULL;
00904     }
00905 
00906     /* We may have been in keep_alive_timeout mode, so toggle back
00907      * to the normal timeout mode as we fetch the header lines,
00908      * as necessary.
00909      */
00910     csd = ap_get_module_config(conn->conn_config, &core_module);
00911     apr_socket_timeout_get(csd, &cur_timeout);
00912     if (cur_timeout != conn->base_server->timeout) {
00913         apr_socket_timeout_set(csd, conn->base_server->timeout);
00914         cur_timeout = conn->base_server->timeout;
00915     }
00916 
00917     if (!r->assbackwards) {
00918         ap_get_mime_headers_core(r, tmp_bb);
00919         if (r->status != HTTP_REQUEST_TIME_OUT) {
00920             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
00921                           "request failed: error reading the headers");
00922             ap_send_error_response(r, 0);
00923             ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
00924             ap_run_log_transaction(r);
00925             apr_brigade_destroy(tmp_bb);
00926             return r;
00927         }
00928 
00929         if (apr_table_get(r->headers_in, "Transfer-Encoding")
00930             && apr_table_get(r->headers_in, "Content-Length")) {
00931             /* 2616 section 4.4, point 3: "if both Transfer-Encoding
00932              * and Content-Length are received, the latter MUST be
00933              * ignored"; so unset it here to prevent any confusion
00934              * later. */
00935             apr_table_unset(r->headers_in, "Content-Length");
00936         }
00937     }
00938     else {
00939         if (r->header_only) {
00940             /*
00941              * Client asked for headers only with HTTP/0.9, which doesn't send
00942              * headers! Have to dink things just to make sure the error message
00943              * comes through...
00944              */
00945             ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
00946                           "client sent invalid HTTP/0.9 request: HEAD %s",
00947                           r->uri);
00948             r->header_only = 0;
00949             r->status = HTTP_BAD_REQUEST;
00950             ap_send_error_response(r, 0);
00951             ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
00952             ap_run_log_transaction(r);
00953             apr_brigade_destroy(tmp_bb);
00954             return r;
00955         }
00956     }
00957 
00958     apr_brigade_destroy(tmp_bb);
00959 
00960     r->status = HTTP_OK;                         /* Until further notice. */
00961 
00962     /* update what we think the virtual host is based on the headers we've
00963      * now read. may update status.
00964      */
00965     ap_update_vhost_from_headers(r);
00966 
00967     /* Toggle to the Host:-based vhost's timeout mode to fetch the
00968      * request body and send the response body, if needed.
00969      */
00970     if (cur_timeout != r->server->timeout) {
00971         apr_socket_timeout_set(csd, r->server->timeout);
00972         cur_timeout = r->server->timeout;
00973     }
00974 
00975     /* we may have switched to another server */
00976     r->per_dir_config = r->server->lookup_defaults;
00977 
00978     if ((!r->hostname && (r->proto_num >= HTTP_VERSION(1, 1)))
00979         || ((r->proto_num == HTTP_VERSION(1, 1))
00980             && !apr_table_get(r->headers_in, "Host"))) {
00981         /*
00982          * Client sent us an HTTP/1.1 or later request without telling us the
00983          * hostname, either with a full URL or a Host: header. We therefore
00984          * need to (as per the 1.1 spec) send an error.  As a special case,
00985          * HTTP/1.1 mentions twice (S9, S14.23) that a request MUST contain
00986          * a Host: header, and the server MUST respond with 400 if it doesn't.
00987          */
00988         r->status = HTTP_BAD_REQUEST;
00989         ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
00990                       "client sent HTTP/1.1 request without hostname "
00991                       "(see RFC2616 section 14.23): %s", r->uri);
00992     }
00993 
00994     /*
00995      * Add the HTTP_IN filter here to ensure that ap_discard_request_body
00996      * called by ap_die and by ap_send_error_response works correctly on
00997      * status codes that do not cause the connection to be dropped and
00998      * in situations where the connection should be kept alive.
00999      */
01000 
01001     ap_add_input_filter_handle(ap_http_input_filter_handle,
01002                                NULL, r, r->connection);
01003 
01004     if (r->status != HTTP_OK) {
01005         ap_send_error_response(r, 0);
01006         ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
01007         ap_run_log_transaction(r);
01008         return r;
01009     }
01010 
01011     if ((access_status = ap_run_post_read_request(r))) {
01012         ap_die(access_status, r);
01013         ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
01014         ap_run_log_transaction(r);
01015         return NULL;
01016     }
01017 
01018     if (((expect = apr_table_get(r->headers_in, "Expect")) != NULL)
01019         && (expect[0] != '\0')) {
01020         /*
01021          * The Expect header field was added to HTTP/1.1 after RFC 2068
01022          * as a means to signal when a 100 response is desired and,
01023          * unfortunately, to signal a poor man's mandatory extension that
01024          * the server must understand or return 417 Expectation Failed.
01025          */
01026         if (strcasecmp(expect, "100-continue") == 0) {
01027             r->expecting_100 = 1;
01028         }
01029         else {
01030             r->status = HTTP_EXPECTATION_FAILED;
01031             ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
01032                           "client sent an unrecognized expectation value of "
01033                           "Expect: %s", expect);
01034             ap_send_error_response(r, 0);
01035             ap_update_child_status(conn->sbh, SERVER_BUSY_LOG, r);
01036             ap_run_log_transaction(r);
01037             return r;
01038         }
01039     }
01040 
01041     return r;
01042 }


Variable Documentation

typedefrequest_rec* r const request_rec* r struct ap_bucket_error ap_bucket_error
 

See also:
ap_bucket_type_error

Definition at line 595 of file http_protocol.h.

AP_DECLARE_DATA const apr_bucket_type_t ap_bucket_type_error
 

See also:
ap_bucket_type_error

Definition at line 67 of file error_bucket.c.

Referenced by AP_DECLARE().

apr_bucket_brigade apr_bucket_brigade * bb
 

Definition at line 559 of file util_filter.h.

Referenced by AP_DECLARE(), AP_DECLARE_NONSTD(), ap_http_filter(), ap_proxy_http_process_response(), APR_HOOK_STRUCT(), APR_OPTIONAL_FN_TYPE(), asis_handler(), bail_out_on_error(), cache_save_filter(), cgi_handler(), cgid_handler(), check_pipeline_flush(), dav_method_put(), dav_send_multistatus(), default_handler(), getsfunc_BRIGADE(), handle_map_file(), isapi_handler(), make_simple_brigade(), mmap_handler(), process_echo_connection(), proxy_ftp_handler(), send_downstream(), send_eos(), sendfile_handler(), ServerSupportFunction(), stream_reqbody_chunked(), stream_reqbody_cl(), test_bwrite(), test_create(), test_flatten(), test_insertfile(), test_manyfile(), test_partition(), test_simple(), test_split(), test_splits(), test_truncfile(), and WriteClient().

char* buffer
 

Definition at line 426 of file http_protocol.h.

char apr_size_t bufsiz
 

Definition at line 426 of file http_protocol.h.

Referenced by ap_proxy_ajp_request().

const char* ct
 

Definition at line 310 of file http_protocol.h.

Referenced by ap_set_byterange(), APR_DECLARE(), maybe_byte_reverse(), mime_post_config(), and modssl_session_get_time().

request_rec* r default_port
 

Definition at line 592 of file http_protocol.h.

int error
 

Definition at line 633 of file http_protocol.h.

Referenced by apr_socket_connect(), APU_DECLARE(), cmd_rewritelock(), cmd_rewriterule_setflag(), common(), DAV_DECLARE_NONSTD(), dav_method_lock(), include_config(), load_module(), main(), parse_expr(), prep(), prolog0(), prolog1(), prolog2(), ssl_io_filter_connect(), and start_ifversion().

const char* fmt
 

Definition at line 365 of file http_protocol.h.

apr_size_t apr_size_t request_rec int fold
 

Definition at line 534 of file http_protocol.h.

int force_weak
 

Definition at line 159 of file http_protocol.h.

log_transaction
 

Definition at line 577 of file http_protocol.h.

const char* methname
 

Definition at line 228 of file http_protocol.h.

int methnum
 

Definition at line 554 of file http_protocol.h.

Referenced by AP_CORE_DECLARE_NONSTD(), AP_DECLARE(), and set_script().

const char* method
 

Definition at line 293 of file http_protocol.h.

apr_time_t mtime
 

Definition at line 127 of file http_protocol.h.

Referenced by AP_DECLARE(), and proxy_ftp_handler().

const char** pw
 

Definition at line 476 of file http_protocol.h.

Referenced by add_password(), main(), and mkrecord().

const request_rec* r
 

Definition at line 659 of file http_protocol.h.

apr_size_t apr_size_t* read
 

Definition at line 534 of file http_protocol.h.

Referenced by APR_DECLARE(), apr_socket_recv(), file_read_buffered(), isapi_handler(), main(), read_connection(), ReadClient(), ServerSupportFunction(), and sock_read().

int read_policy
 

Definition at line 405 of file http_protocol.h.

int recursive_error
 

Definition at line 97 of file http_protocol.h.

Referenced by AP_DECLARE().

int send_headers
 

Definition at line 673 of file http_protocol.h.

const char* type
 

Definition at line 141 of file http_protocol.h.

const char* uri
 

Definition at line 487 of file http_protocol.h.

const char va_list vlist
 

Definition at line 356 of file http_protocol.h.


© sourcejam.com 2005-2008