1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
59 #ifndef APACHE_HTTP_CORE_H
60 #define APACHE_HTTP_CORE_H
64 #include "apr_optional.h"
65 #include "util_filter.h"
67 #if APR_HAVE_STRUCT_RLIMIT
69 #include <sys/resource.h>
78 * @package CORE HTTP Daemon
81 /* ****************************************************************
83 * The most basic server code is encapsulated in a single module
84 * known as the core, which is just *barely* functional enough to
85 * serve documents, though not terribly well.
87 * Largely for NCSA back-compatibility reasons, the core needs to
88 * make pieces of its config structures available to other modules.
89 * The accessors are declared here, along with the interpretation
90 * of one of them (allow_options).
95 #define OPT_INCLUDES 2
96 #define OPT_SYM_LINKS 4
99 #define OPT_INCNOEXEC 32
100 #define OPT_SYM_OWNER 64
101 #define OPT_MULTI 128
102 #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS|OPT_EXECCGI)
104 /* options for get_remote_host() */
105 /* REMOTE_HOST returns the hostname, or NULL if the hostname
106 * lookup fails. It will force a DNS lookup according to the
107 * HostnameLookups setting.
109 #define REMOTE_HOST (0)
111 /* REMOTE_NAME returns the hostname, or the dotted quad if the
112 * hostname lookup fails. It will force a DNS lookup according
113 * to the HostnameLookups setting.
115 #define REMOTE_NAME (1)
117 /* REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
120 #define REMOTE_NOLOOKUP (2)
122 /* REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
123 * a double reverse lookup, regardless of the HostnameLookups
124 * setting. The result is the (double reverse checked) hostname,
125 * or NULL if any of the lookups fail.
127 #define REMOTE_DOUBLE_REV (3)
129 #define SATISFY_ALL 0
130 #define SATISFY_ANY 1
131 #define SATISFY_NOSPEC 2
133 /* Make sure we don't write less than 8000 bytes at any one time.
135 #define AP_MIN_BYTES_TO_WRITE 8000
137 /* default maximum of internal redirects */
138 # define AP_DEFAULT_MAX_INTERNAL_REDIRECTS 10
140 /* default maximum subrequest nesting level */
141 # define AP_DEFAULT_MAX_SUBREQ_DEPTH 10
144 * Retrieve the value of Options for this request
145 * @param r The current request
146 * @return the Options bitmask
147 * @deffunc int ap_allow_options(request_rec *r)
149 AP_DECLARE(int) ap_allow_options(request_rec *r);
152 * Retrieve the value of the AllowOverride for this request
153 * @param r The current request
154 * @return the overrides bitmask
155 * @deffunc int ap_allow_overrides(request_rec *r)
157 AP_DECLARE(int) ap_allow_overrides(request_rec *r);
160 * Retrieve the value of the DefaultType directive, or text/plain if not set
161 * @param r The current request
162 * @return The default type
163 * @deffunc const char *ap_default_type(request_rec *r)
165 AP_DECLARE(const char *) ap_default_type(request_rec *r);
168 * Retrieve the document root for this server
169 * @param r The current request
170 * @warning Don't use this! If your request went through a Userdir, or
171 * something like that, it'll screw you. But it's back-compatible...
172 * @return The document root
173 * @deffunc const char *ap_document_root(request_rec *r)
175 AP_DECLARE(const char *) ap_document_root(request_rec *r);
178 * Lookup the remote client's DNS name or IP address
179 * @param conn The current connection
180 * @param dir_config The directory config vector from the request
181 * @param type The type of lookup to perform. One of:
183 * REMOTE_HOST returns the hostname, or NULL if the hostname
184 * lookup fails. It will force a DNS lookup according to the
185 * HostnameLookups setting.
186 * REMOTE_NAME returns the hostname, or the dotted quad if the
187 * hostname lookup fails. It will force a DNS lookup according
188 * to the HostnameLookups setting.
189 * REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
191 * REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
192 * a double reverse lookup, regardless of the HostnameLookups
193 * setting. The result is the (double reverse checked)
194 * hostname, or NULL if any of the lookups fail.
196 * @param str_is_ip unless NULL is passed, this will be set to non-zero on output when an IP address
198 * @return The remote hostname
199 * @deffunc const char *ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip)
201 AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip);
204 * Retrieve the login name of the remote user. Undef if it could not be
206 * @param r The current request
207 * @return The user logged in to the client machine
208 * @deffunc const char *ap_get_remote_logname(request_rec *r)
210 AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r);
212 /* Used for constructing self-referencing URLs, and things like SERVER_PORT,
216 * build a fully qualified URL from the uri and information in the request rec
217 * @param p The pool to allocate the URL from
218 * @param uri The path to the requested file
219 * @param r The current request
220 * @return A fully qualified URL
221 * @deffunc char *ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r)
223 AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r);
226 * Get the current server name from the request
227 * @param r The current request
228 * @return the server name
229 * @deffunc const char *ap_get_server_name(request_rec *r)
231 AP_DECLARE(const char *) ap_get_server_name(request_rec *r);
234 * Get the current server port
235 * @param The current request
236 * @return The server's port
237 * @deffunc apr_port_t ap_get_server_port(const request_rec *r)
239 AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r);
242 * Return the limit on bytes in request msg body
243 * @param r The current request
244 * @return the maximum number of bytes in the request msg body
245 * @deffunc apr_off_t ap_get_limit_req_body(const request_rec *r)
247 AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r);
250 * Return the limit on bytes in XML request msg body
251 * @param r The current request
252 * @return the maximum number of bytes in XML request msg body
253 * @deffunc size_t ap_get_limit_xml_body(const request_rec *r)
255 AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r);
258 * Install a custom response handler for a given status
259 * @param r The current request
260 * @param status The status for which the custom response should be used
261 * @param string The custom response. This can be a static string, a file
264 AP_DECLARE(void) ap_custom_response(request_rec *r, int status, const char *string);
267 * Check if the current request is beyond the configured max. number of redirects or subrequests
268 * @param r The current request
269 * @return true (is exceeded) or false
270 * @deffunc int ap_is_recursion_limit_exceeded(const request_rec *r)
272 AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r);
275 * Check for a definition from the server command line
276 * @param name The define to check for
277 * @return 1 if defined, 0 otherwise
278 * @deffunc int ap_exists_config_define(const char *name)
280 AP_DECLARE(int) ap_exists_config_define(const char *name);
281 /* FIXME! See STATUS about how */
282 AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r);
284 /* Authentication stuff. This is one of the places where compatibility
285 * with the old config files *really* hurts; they don't discriminate at
286 * all between different authentication schemes, meaning that we need
287 * to maintain common state for all of them in the core, and make it
288 * available to the other modules through interfaces.
290 typedef struct require_line require_line;
292 /** A structure to keep track of authorization requirements */
293 struct require_line {
294 /** Where the require line is in the config file. */
295 apr_int64_t method_mask;
296 /** The complete string from the command line */
301 * Return the type of authorization required for this request
302 * @param r The current request
303 * @return The authorization required
304 * @deffunc const char *ap_auth_type(request_rec *r)
306 AP_DECLARE(const char *) ap_auth_type(request_rec *r);
309 * Return the current Authorization realm
310 * @param r The current request
311 * @return The current authorization realm
312 * @deffunc const char *ap_auth_name(request_rec *r)
314 AP_DECLARE(const char *) ap_auth_name(request_rec *r);
317 * How the requires lines must be met.
318 * @param r The current request
319 * @return How the requirements must be met. One of:
321 * SATISFY_ANY -- any of the requirements must be met.
322 * SATISFY_ALL -- all of the requirements must be met.
323 * SATISFY_NOSPEC -- There are no applicable satisfy lines
325 * @deffunc int ap_satisfies(request_rec *r)
327 AP_DECLARE(int) ap_satisfies(request_rec *r);
330 * Retrieve information about all of the requires directives for this request
331 * @param r The current request
332 * @return An array of all requires directives for this request
333 * @deffunc const apr_array_header_t *ap_requires(request_rec *r)
335 AP_DECLARE(const apr_array_header_t *) ap_requires(request_rec *r);
340 * Core is also unlike other modules in being implemented in more than
341 * one file... so, data structures are declared here, even though most of
342 * the code that cares really is in http_core.c. Also, another accessor.
345 AP_DECLARE_DATA extern module core_module;
347 /* Per-request configuration */
350 /* bucket brigade used by getline for look-ahead and
351 * ap_get_client_block for holding left-over request body */
352 struct apr_bucket_brigade *bb;
354 /* an array of per-request working data elements, accessed
355 * by ID using ap_get_request_note()
356 * (Use ap_register_request_note() during initialization
361 /* There is a script processor installed on the output filter chain,
362 * so it needs the default_handler to deliver a (script) file into
363 * the chain so it can process it. Normally, default_handler only
364 * serves files on a GET request (assuming the file is actual content),
365 * since other methods are not content-retrieval. This flag overrides
366 * that behavior, stating that the "content" is actually a script and
367 * won't actually be delivered as the response for the non-GET method.
370 } core_request_config;
372 /* Standard entries that are guaranteed to be accessible via
373 * ap_get_request_note() for each request (additional entries
374 * can be added with ap_register_request_note())
376 #define AP_NOTE_DIRECTORY_WALK 0
377 #define AP_NOTE_LOCATION_WALK 1
378 #define AP_NOTE_FILE_WALK 2
379 #define AP_NUM_STD_NOTES 3
382 * Reserve an element in the core_request_config->notes array
383 * for some application-specific data
384 * @return An integer key that can be passed to ap_get_request_note()
385 * during request processing to access this element for the
388 AP_DECLARE(apr_size_t) ap_register_request_note(void);
391 * Retrieve a pointer to an element in the core_request_config->notes array
392 * @param r The request
393 * @param note_num A key for the element: either a value obtained from
394 * ap_register_request_note() or one of the predefined AP_NOTE_*
396 * @return NULL if the note_num is invalid, otherwise a pointer to the
397 * requested note element.
398 * @remark At the start of a request, each note element is NULL. The
399 * handle provided by ap_get_request_note() is a pointer-to-pointer
400 * so that the caller can point the element to some app-specific
401 * data structure. The caller should guarantee that any such
402 * structure will last as long as the request itself.
404 AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num);
406 /* Per-directory configuration */
408 typedef unsigned char allow_options_t;
409 typedef unsigned char overrides_t;
412 * Bits of info that go into making an ETag for a file
413 * document. Why a long? Because char historically
414 * proved too short for Options, and int can be different
415 * sizes on different platforms.
417 typedef unsigned long etag_components_t;
420 #define ETAG_NONE (1 << 0)
421 #define ETAG_MTIME (1 << 1)
422 #define ETAG_INODE (1 << 2)
423 #define ETAG_SIZE (1 << 3)
424 #define ETAG_BACKWARD (ETAG_MTIME | ETAG_INODE | ETAG_SIZE)
425 #define ETAG_ALL (ETAG_MTIME | ETAG_INODE | ETAG_SIZE)
432 } server_signature_e;
435 /* path of the directory/regex/etc. see also d_is_fnmatch/absolute below */
437 /* the number of slashes in d */
438 unsigned d_components;
440 /* If (opts & OPT_UNSET) then no absolute assignment to options has
442 * invariant: (opts_add & opts_remove) == 0
443 * Which said another way means that the last relative (options + or -)
444 * assignment made to each bit is recorded in exactly one of opts_add
447 allow_options_t opts;
448 allow_options_t opts_add;
449 allow_options_t opts_remove;
450 overrides_t override;
452 /* MIME typing --- the core doesn't do anything at all with this,
453 * but it does know what to slap on a request for a document which
454 * goes untyped by other mechanisms before it slips out the door...
457 char *ap_default_type;
459 /* Authentication stuff. Groan... */
464 apr_array_header_t *ap_requires;
466 /* Custom response config. These can contain text or a URL to redirect to.
467 * if response_code_strings is NULL then there are none in the config,
468 * if it's not null then it's allocated to sizeof(char*)*RESPONSE_CODES.
469 * This lets us do quick merges in merge_core_dir_configs().
472 char **response_code_strings;
474 /* Hostname resolution etc */
475 #define HOSTNAME_LOOKUP_OFF 0
476 #define HOSTNAME_LOOKUP_ON 1
477 #define HOSTNAME_LOOKUP_DOUBLE 2
478 #define HOSTNAME_LOOKUP_UNSET 3
479 unsigned int hostname_lookups : 4;
481 signed int content_md5 : 2; /* calculate Content-MD5? */
483 #define USE_CANONICAL_NAME_OFF (0)
484 #define USE_CANONICAL_NAME_ON (1)
485 #define USE_CANONICAL_NAME_DNS (2)
486 #define USE_CANONICAL_NAME_UNSET (3)
487 unsigned use_canonical_name : 2;
489 /* since is_fnmatch(conf->d) was being called so frequently in
490 * directory_walk() and its relatives, this field was created and
491 * is set to the result of that call.
493 unsigned d_is_fnmatch : 1;
495 /* should we force a charset on any outgoing parameterless content-type?
496 * if so, which charset?
498 #define ADD_DEFAULT_CHARSET_OFF (0)
499 #define ADD_DEFAULT_CHARSET_ON (1)
500 #define ADD_DEFAULT_CHARSET_UNSET (2)
501 unsigned add_default_charset : 2;
502 const char *add_default_charset_name;
504 /* System Resource Control */
506 struct rlimit *limit_cpu;
508 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
509 struct rlimit *limit_mem;
512 struct rlimit *limit_nproc;
514 apr_off_t limit_req_body; /* limit on bytes in request msg body */
515 long limit_xml_body; /* limit on bytes in XML request msg body */
517 /* logging options */
519 server_signature_e server_signature;
524 apr_array_header_t *sec_file;
527 const char *mime_type; /* forced with ForceType */
528 const char *handler; /* forced with SetHandler */
529 const char *output_filters; /* forced with SetOutputFilters */
530 const char *input_filters; /* forced with SetInputFilters */
531 int accept_path_info; /* forced with AcceptPathInfo */
533 apr_hash_t *ct_output_filters; /* added with AddOutputFilterByType */
536 * What attributes/data should be included in ETag generation?
538 etag_components_t etag_bits;
539 etag_components_t etag_add;
540 etag_components_t etag_remove;
543 * Run-time performance tuning
545 #define ENABLE_MMAP_OFF (0)
546 #define ENABLE_MMAP_ON (1)
547 #define ENABLE_MMAP_UNSET (2)
548 unsigned int enable_mmap : 2; /* whether files in this dir can be mmap'ed */
550 #define ENABLE_SENDFILE_OFF (0)
551 #define ENABLE_SENDFILE_ON (1)
552 #define ENABLE_SENDFILE_UNSET (2)
553 unsigned int enable_sendfile : 2; /* files in this dir can be mmap'ed */
554 unsigned int allow_encoded_slashes : 1; /* URLs may contain %2f w/o being
555 * pitched indiscriminately */
558 /* Per-server core configuration */
566 /* Name translations --- we want the core to be able to do *something*
567 * so it's at least a minimally functional web server on its own (and
568 * can be tested that way). But let's keep it to the bare minimum:
570 const char *ap_document_root;
575 apr_array_header_t *sec_dir;
576 apr_array_header_t *sec_url;
578 /* recursion backstopper */
579 int redirect_limit; /* maximum number of internal redirects */
580 int subreq_limit; /* maximum nesting level of subrequests */
581 } core_server_config;
583 /* for AddOutputFiltersByType in core.c */
584 void ap_add_output_filters_by_type(request_rec *r);
586 /* for http_config.c */
587 void ap_core_reorder_directories(apr_pool_t *, server_rec *);
590 AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config);
591 AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config);
592 AP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config *conf, void *url_config);
593 AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg);
595 #endif /* CORE_PRIVATE */
598 /* ----------------------------------------------------------------------
600 * Runtime status/management
616 const char *description;
618 ap_mgmt_type_e vtype;
622 /* Handles for core filters */
623 extern AP_DECLARE_DATA ap_filter_rec_t *ap_subreq_core_filter_handle;
624 extern AP_DECLARE_DATA ap_filter_rec_t *ap_core_output_filter_handle;
625 extern AP_DECLARE_DATA ap_filter_rec_t *ap_content_length_filter_handle;
626 extern AP_DECLARE_DATA ap_filter_rec_t *ap_net_time_filter_handle;
627 extern AP_DECLARE_DATA ap_filter_rec_t *ap_core_input_filter_handle;
630 * This hook provdes a way for modules to provide metrics/statistics about
631 * their operational status.
633 * @param p A pool to use to create entries in the hash table
634 * @param val The name of the parameter(s) that is wanted. This is
635 * tree-structured would be in the form ('*' is all the tree,
636 * 'module.*' all of the module , 'module.foo.*', or
638 * @param ht The hash table to store the results. Keys are item names, and
639 * the values point to ap_mgmt_item_t structures.
642 AP_DECLARE_HOOK(int, get_mgmt_items,
643 (apr_pool_t *p, const char * val, apr_hash_t *ht))
645 /* ---------------------------------------------------------------------- */
647 /* ----------------------------------------------------------------------
649 * I/O logging with mod_logio
652 APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_out,
653 (conn_rec *c, apr_off_t bytes));
655 /* ----------------------------------------------------------------------
657 * ident lookups with mod_ident
660 APR_DECLARE_OPTIONAL_FN(const char *, ap_ident_lookup,
663 /* ---------------------------------------------------------------------- */
669 #endif /* !APACHE_HTTP_CORE_H */