Main Page | Modules | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages | Examples

http_protocol.c File Reference

#include "apr.h"
#include "apr_strings.h"
#include "apr_buckets.h"
#include "apr_lib.h"
#include "apr_signal.h"
#include "apr_want.h"
#include "util_filter.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_main.h"
#include "http_request.h"
#include "http_vhost.h"
#include "http_log.h"
#include "apr_date.h"
#include "util_charset.h"
#include "util_ebcdic.h"
#include "util_time.h"
#include "mod_core.h"

Include dependency graph for http_protocol.c:

Go to the source code of this file.

Defines

#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#define CORE_PRIVATE
#define LEVEL_200   3
#define LEVEL_300   11
#define LEVEL_400   19
#define LEVEL_500   46
#define METHOD_NUMBER_FIRST   (M_INVALID + 1)
#define METHOD_NUMBER_LAST   62
#define UNKNOWN_METHOD   (-1)
#define HEX_DIGITS   "0123456789abcdef"
#define ETAG_WEAK   "W/"
#define CHARS_PER_UNSIGNED_LONG   (sizeof(unsigned long) * 2)
#define BYTERANGE_FMT   "%" APR_OFF_T_FMT "-%" APR_OFF_T_FMT "/%" APR_OFF_T_FMT
#define PARTITION_ERR_FMT
#define MIN_LENGTH(len1, len2)   ((len1 > len2) ? len2 : len1)

Typedefs

typedef http_filter_ctx http_ctx_t
typedef header_struct header_struct
typedef header_filter_ctx header_filter_ctx
typedef byterange_ctx byterange_ctx

Functions

 APR_HOOK_STRUCT ()
 AP_DECLARE (int)
static void register_one_method (apr_pool_t *p, const char *methname, int methnum)
static apr_status_t ap_method_registry_destroy (void *notused)
 AP_DECLARE (void)
static int lookup_builtin_method (const char *method, apr_size_t len)
 AP_DECLARE (const char *)
static long get_chunk_size (char *)
apr_status_t ap_http_filter (ap_filter_t *f, apr_bucket_brigade *b, ap_input_mode_t mode, apr_read_type_e block, apr_off_t readbytes)
static int form_header_field (header_struct *h, const char *fieldname, const char *fieldval)
static apr_status_t send_all_header_fields (header_struct *h, const request_rec *r)
static void basic_http_header_check (request_rec *r, const char **protocol)
static void basic_http_header (request_rec *r, apr_bucket_brigade *bb, const char *protocol)
static void terminate_header (apr_bucket_brigade *bb)
static char * make_allow (request_rec *r)
 AP_DECLARE_NONSTD (int)
static int uniq_field_values (void *d, const char *key, const char *val)
static void fixup_vary (request_rec *r)
 AP_CORE_DECLARE_NONSTD (apr_status_t)
 AP_DECLARE (long)
static const char * add_optional_notes (request_rec *r, const char *prefix, const char *key, const char *suffix)
static const char * get_canned_error_string (int status, request_rec *r, const char *location)
 AP_DECLARE (ap_method_list_t *)
 AP_DECLARE_NONSTD (void)
static char * etag_ulong_to_hex (char *next, unsigned long u)
 AP_DECLARE (char *)
static int parse_byterange (char *range, apr_off_t clength, apr_off_t *start, apr_off_t *end)
static int ap_set_byterange (request_rec *r)
static int use_range_x (request_rec *r)

Variables

static const char *const status_lines [RESPONSE_CODES]
static apr_hash_tmethods_registry = NULL
static int cur_method_number = METHOD_NUMBER_FIRST


Define Documentation

#define APR_WANT_MEMFUNC
 

Definition at line 32 of file http_protocol.c.

#define APR_WANT_STDIO
 

Definition at line 30 of file http_protocol.c.

#define APR_WANT_STRFUNC
 

Definition at line 31 of file http_protocol.c.

#define BYTERANGE_FMT   "%" APR_OFF_T_FMT "-%" APR_OFF_T_FMT "/%" APR_OFF_T_FMT
 

Definition at line 2849 of file http_protocol.c.

Referenced by AP_CORE_DECLARE_NONSTD().

#define CHARS_PER_UNSIGNED_LONG   (sizeof(unsigned long) * 2)
 

Definition at line 2616 of file http_protocol.c.

Referenced by AP_DECLARE().

#define CORE_PRIVATE
 

Definition at line 35 of file http_protocol.c.

#define ETAG_WEAK   "W/"
 

Definition at line 2615 of file http_protocol.c.

Referenced by AP_DECLARE().

#define HEX_DIGITS   "0123456789abcdef"
 

Definition at line 2595 of file http_protocol.c.

Referenced by etag_ulong_to_hex().

#define LEVEL_200   3
 

#define LEVEL_300   11
 

#define LEVEL_400   19
 

#define LEVEL_500   46
 

#define METHOD_NUMBER_FIRST   (M_INVALID + 1)
 

Referenced by ap_method_registry_destroy().

#define METHOD_NUMBER_LAST   62
 

Referenced by AP_DECLARE().

#define MIN_LENGTH len1,
len2   )     ((len1 > len2) ? len2 : len1)
 

#define PARTITION_ERR_FMT
 

Value:

"apr_brigade_partition() failed " \
                          "[%" APR_OFF_T_FMT ",%" APR_OFF_T_FMT "]"

Definition at line 2850 of file http_protocol.c.

Referenced by AP_CORE_DECLARE_NONSTD().

#define UNKNOWN_METHOD   (-1)
 

Definition at line 480 of file http_protocol.c.

Referenced by lookup_builtin_method().


Typedef Documentation

typedef struct byterange_ctx byterange_ctx
 

typedef struct header_filter_ctx header_filter_ctx
 

typedef struct header_struct header_struct
 

typedef struct http_filter_ctx http_ctx_t
 


Function Documentation

static const char* add_optional_notes request_rec r,
const char *  prefix,
const char *  key,
const char *  suffix
[static]
 

Definition at line 2009 of file http_protocol.c.

References NULL, and result.

Referenced by get_canned_error_string().

AP_CORE_DECLARE_NONSTD apr_status_t   ) 
 

Definition at line 1514 of file http_protocol.c.

References ap_bucket_type_error, AP_CORE_DECLARE_NONSTD, AP_DEBUG_ASSERT, AP_FILTER_ERROR, APR_BRIGADE_FOREACH, apr_pcalloc, APR_RFC822_DATE_LEN, request_rec::assbackwards, basic_http_header(), basic_http_header_check(), header_struct::bb, conn_rec::bucket_alloc, c, request_rec::chunked, request_rec::connection, request_rec::content_encoding, request_rec::content_languages, request_rec::content_type, ctx, apr_bucket::data, e, apr_array_header_t::elts, request_rec::err_headers_out, fixup_vary(), form_header_field(), h, request_rec::header_only, request_rec::headers_out, header_filter_ctx::headers_sent, HTTP_NOT_MODIFIED, HTTP_VERSION, request_rec::main, request_rec::no_cache, request_rec::notes, NULL, OK, header_struct::pool, request_rec::pool, request_rec::proto_num, protocol, request_rec::request_time, send_all_header_fields(), request_rec::sent_bodyct, request_rec::status, ap_bucket_error::status, request_rec::subprocess_env, terminate_header(), and apr_bucket::type.

Here is the call graph for this function:

AP_DECLARE char *   ) 
 

Definition at line 2624 of file http_protocol.c.

References AP_DECLARE, ap_get_module_config, APR_USEC_PER_SEC, CHARS_PER_UNSIGNED_LONG, core_module, etag_ulong_to_hex(), ETAG_WEAK, apr_finfo_t::filetype, request_rec::finfo, apr_finfo_t::inode, request_rec::mtime, request_rec::notes, NULL, request_rec::per_dir_config, request_rec::pool, request_rec::request_time, and apr_finfo_t::size.

Here is the call graph for this function:

AP_DECLARE ap_method_list_t  ) 
 

Definition at line 2425 of file http_protocol.c.

References AP_DECLARE, ap_method_list_t::method_list, ap_method_list_t::method_mask, and ml.

AP_DECLARE long   ) 
 

Definition at line 1859 of file http_protocol.c.

References AP_CONN_CLOSE, AP_DEBUG_ASSERT, AP_DECLARE, AP_MODE_READBYTES, APR_BLOCK_READ, APR_BRIGADE_EMPTY, APR_BRIGADE_LAST, APR_BUCKET_IS_EOS, APR_SUCCESS, bb, and NULL.

AP_DECLARE void   ) 
 

Add a component to the version string

Parameters:
pconf The pool to allocate the component from
component The string to add

Definition at line 408 of file http_protocol.c.

References AP_DECLARE, ap_method_registry_destroy(), M_BASELINE_CONTROL, M_CHECKIN, M_CHECKOUT, M_CONNECT, M_COPY, M_DELETE, M_GET, M_LABEL, M_LOCK, M_MERGE, M_MKACTIVITY, M_MKCOL, M_MKWORKSPACE, M_MOVE, M_OPTIONS, M_PATCH, M_POST, M_PROPFIND, M_PROPPATCH, M_PUT, M_REPORT, M_TRACE, M_UNCHECKOUT, M_UNLOCK, M_UPDATE, M_VERSION_CONTROL, NULL, and register_one_method().

Here is the call graph for this function:

AP_DECLARE int   ) 
 

Get XML post data and parse it

Parameters:
r The current request
pdoc The XML post data
Returns:
HTTP status code int ap_xml_parse_input(request_rec *r, apr_xml_doc **pdoc)

Definition at line 257 of file http_protocol.c.

References AP_DECLARE, ap_is_HTTP_SUCCESS, ap_strstr_c, APR_DATE_BAD, apr_time_sec, HTTP_NOT_MODIFIED, HTTP_PRECONDITION_FAILED, M_GET, mtime, NULL, and OK.

AP_DECLARE_NONSTD void   ) 
 

Definition at line 2457 of file http_protocol.c.

References AP_DECLARE_NONSTD, and vp.

AP_DECLARE_NONSTD int   ) 
 

Read headers strings from a script, ensuring that the output is valid. If the output is valid, then the headers are added to the headers out of the current request

Parameters:
r The current request
buffer Empty when calling the function. On output, if there was an error, the string that cause the error is stored here.
termch Pointer to the last character parsed.
termarg Pointer to an int to capture the last argument parsed.
args String arguments to parse consecutively for headers, a NULL argument terminates the list.
Returns:
HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise int ap_scan_script_header_err_core(request_rec *r, char *buffer, int (*getsfunc)(char *, int, void *), void *getsfunc_data)

Definition at line 1365 of file http_protocol.c.

apr_status_t ap_http_filter ap_filter_t f,
apr_bucket_brigade b,
ap_input_mode_t  mode,
apr_read_type_e  block,
apr_off_t  readbytes
 

Definition at line 725 of file http_protocol.c.

References AP_DEBUG_ASSERT, AP_MODE_GETLINE, AP_MODE_READBYTES, AP_SERVER_PROTOCOL, APLOG_ERR, APLOG_MARK, APR_BLOCK_READ, APR_BRIGADE_INSERT_HEAD, APR_BRIGADE_INSERT_TAIL, APR_SUCCESS, bb, conn_rec::bucket_alloc, ap_filter_t::c, CRLF, ctx, ap_filter_t::ctx, e, http_filter_ctx::eos_sent, request_rec::expecting_100, get_chunk_size(), request_rec::headers_in, HTTP_REQUEST_ENTITY_TOO_LARGE, HTTP_VERSION, http_filter_ctx::limit, http_filter_ctx::limit_used, line, ap_filter_t::next, NULL, request_rec::output_filters, conn_rec::output_filters, request_rec::pool, request_rec::proto_num, request_rec::proxyreq, PROXYREQ_RESPONSE, ap_filter_t::r, request_rec::remaining, http_filter_ctx::remaining, http_filter_ctx::state, status_lines, strcasecmp(), and totalread.

Referenced by register_hooks().

Here is the call graph for this function:

static apr_status_t ap_method_registry_destroy void *  notused  )  [static]
 

Definition at line 401 of file http_protocol.c.

References APR_SUCCESS, METHOD_NUMBER_FIRST, and NULL.

Referenced by AP_DECLARE().

static int ap_set_byterange request_rec r  )  [static]
 

Definition at line 3034 of file http_protocol.c.

References ap_strchr_c, request_rec::assbackwards, request_rec::headers_in, request_rec::headers_out, HTTP_OK, HTTP_PARTIAL_CONTENT, match(), request_rec::range, request_rec::status, and strncasecmp().

Referenced by AP_CORE_DECLARE_NONSTD().

Here is the call graph for this function:

APR_HOOK_STRUCT  ) 
 

Definition at line 143 of file http_protocol.c.

References AP_CONN_CLOSE, AP_CONN_KEEPALIVE, ap_status_drops_connection, apr_time_sec, HTTP_NO_CONTENT, HTTP_NOT_MODIFIED, HTTP_VERSION, and left.

static void basic_http_header request_rec r,
apr_bucket_brigade bb,
const char *  protocol
[static]
 

Definition at line 1212 of file http_protocol.c.

References ap_xlate_proto_to_ascii, APR_RFC822_DATE_LEN, request_rec::assbackwards, header_struct::bb, CRLF, form_header_field(), h, request_rec::headers_out, NULL, header_struct::pool, request_rec::pool, request_rec::proxyreq, PROXYREQ_NONE, request_rec::request_time, server, and request_rec::status_line.

Referenced by AP_CORE_DECLARE_NONSTD(), and AP_DECLARE().

Here is the call graph for this function:

static void basic_http_header_check request_rec r,
const char **  protocol
[static]
 

Definition at line 1180 of file http_protocol.c.

References AP_CONN_CLOSE, AP_SERVER_PROTOCOL, request_rec::assbackwards, request_rec::connection, HTTP_VERSION, conn_rec::keepalive, request_rec::proto_num, request_rec::status, request_rec::status_line, status_lines, and request_rec::subprocess_env.

Referenced by AP_CORE_DECLARE_NONSTD(), and AP_DECLARE().

static char* etag_ulong_to_hex char *  next,
unsigned long  u
[static]
 

Definition at line 2596 of file http_protocol.c.

References HEX_DIGITS.

Referenced by AP_DECLARE().

static void fixup_vary request_rec r  )  [static]
 

Definition at line 1472 of file http_protocol.c.

References request_rec::headers_out, NULL, request_rec::pool, and uniq_field_values().

Referenced by AP_CORE_DECLARE_NONSTD().

Here is the call graph for this function:

static int form_header_field header_struct h,
const char *  fieldname,
const char *  fieldval
[static]
 

Definition at line 1078 of file http_protocol.c.

References ap_xlate_proto_to_ascii, header_struct::bb, CR, CRLF, LF, NULL, and header_struct::pool.

Referenced by AP_CORE_DECLARE_NONSTD(), AP_DECLARE_NONSTD(), and basic_http_header().

static const char* get_canned_error_string int  status,
request_rec r,
const char *  location
[static]
 

Definition at line 2029 of file http_protocol.c.

References add_optional_notes(), CRLF, h1, request_rec::headers_in, HTTP_BAD_GATEWAY, HTTP_BAD_REQUEST, HTTP_EXPECTATION_FAILED, HTTP_FAILED_DEPENDENCY, HTTP_FORBIDDEN, HTTP_GATEWAY_TIME_OUT, HTTP_GONE, HTTP_INSUFFICIENT_STORAGE, HTTP_LENGTH_REQUIRED, HTTP_LOCKED, HTTP_METHOD_NOT_ALLOWED, HTTP_MOVED_PERMANENTLY, HTTP_MOVED_TEMPORARILY, HTTP_MULTIPLE_CHOICES, HTTP_NOT_ACCEPTABLE, HTTP_NOT_EXTENDED, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_PRECONDITION_FAILED, HTTP_PROXY_AUTHENTICATION_REQUIRED, HTTP_RANGE_NOT_SATISFIABLE, HTTP_REQUEST_ENTITY_TOO_LARGE, HTTP_REQUEST_TIME_OUT, HTTP_REQUEST_URI_TOO_LARGE, HTTP_SEE_OTHER, HTTP_SERVICE_UNAVAILABLE, HTTP_TEMPORARY_REDIRECT, HTTP_UNAUTHORIZED, HTTP_UNPROCESSABLE_ENTITY, HTTP_UNSUPPORTED_MEDIA_TYPE, HTTP_UPGRADE_REQUIRED, HTTP_USE_PROXY, HTTP_VARIANT_ALSO_VARIES, request_rec::method, request_rec::notes, NULL, p, request_rec::pool, request_rec::server, server_rec::server_admin, and request_rec::uri.

Here is the call graph for this function:

static long get_chunk_size char *  b  )  [static]
 

Parse a chunk extension, detect overflow. There are two error cases: 1) If the conversion would require too many bits, a -1 is returned. 2) If the conversion used the correct number of bits, but an overflow caused only the sign bit to flip, then that negative number is returned. In general, any negative number can be considered an overflow error.

Definition at line 1814 of file http_protocol.c.

References apr_isxdigit.

Referenced by ap_http_filter().

static int lookup_builtin_method const char *  method,
apr_size_t  len
[static]
 

Definition at line 482 of file http_protocol.c.

References M_BASELINE_CONTROL, M_CHECKIN, M_CHECKOUT, M_CONNECT, M_COPY, M_DELETE, M_GET, M_LABEL, M_LOCK, M_MERGE, M_MKACTIVITY, M_MKCOL, M_MKWORKSPACE, M_MOVE, M_OPTIONS, M_PATCH, M_POST, M_PROPFIND, M_PROPPATCH, M_PUT, M_REPORT, M_TRACE, M_UNCHECKOUT, M_UNLOCK, M_UPDATE, M_VERSION_CONTROL, and UNKNOWN_METHOD.

static char* make_allow request_rec r  )  [static]
 

Definition at line 1318 of file http_protocol.c.

References request_rec::allowed_methods, AP_METHOD_BIT, apr_array_header_t::elts, key, list, M_GET, M_INVALID, mask, ap_method_list_t::method_list, ap_method_list_t::method_mask, apr_array_header_t::nelts, NULL, request_rec::pool, and val.

static int parse_byterange char *  range,
apr_off_t  clength,
apr_off_t *  start,
apr_off_t *  end
[static]
 

Definition at line 2784 of file http_protocol.c.

Referenced by AP_CORE_DECLARE_NONSTD().

static void register_one_method apr_pool_t p,
const char *  methname,
int  methnum
[static]
 

Definition at line 389 of file http_protocol.c.

References APR_HASH_KEY_STRING.

Referenced by AP_DECLARE().

static apr_status_t send_all_header_fields header_struct h,
const request_rec r
[static]
 

Definition at line 1124 of file http_protocol.c.

References ap_xlate_proto_to_ascii, APR_SUCCESS, header_struct::bb, CRLF, apr_array_header_t::elts, request_rec::headers_out, apr_table_entry_t::key, apr_array_header_t::nelts, NULL, request_rec::pool, header_struct::pool, apr_table_entry_t::val, and vec.

Referenced by AP_CORE_DECLARE_NONSTD().

static void terminate_header apr_bucket_brigade bb  )  [static]
 

Definition at line 1296 of file http_protocol.c.

References ap_xlate_proto_to_ascii, buflen, CRLF, NULL, and void().

Referenced by AP_CORE_DECLARE_NONSTD().

Here is the call graph for this function:

static int uniq_field_values void *  d,
const char *  key,
const char *  val
[static]
 

Definition at line 1421 of file http_protocol.c.

References apr_isspace, e, apr_array_header_t::elts, apr_array_header_t::nelts, nelts, apr_array_header_t::pool, start, and strcasecmp().

Referenced by fixup_vary().

Here is the call graph for this function:

static int use_range_x request_rec r  )  [static]
 

Definition at line 2841 of file http_protocol.c.

References ap_strstr_c, and request_rec::headers_in.

Referenced by AP_CORE_DECLARE_NONSTD().


Variable Documentation

int cur_method_number = METHOD_NUMBER_FIRST [static]
 

Definition at line 386 of file http_protocol.c.

apr_hash_t* methods_registry = NULL [static]
 

Singleton registry of additional methods. This maps new method names such as "MYGET" to methnums, which are int offsets into bitmasks.

This follows the same technique as standard M_GET, M_POST, etc. These are dynamically assigned when modules are loaded and <limit get="" myget=""> directives are processed.

Definition at line 385 of file http_protocol.c.

const char* const status_lines[RESPONSE_CODES] [static]
 

Definition at line 74 of file http_protocol.c.

Referenced by AP_DECLARE(), ap_http_filter(), and basic_http_header_check().