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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @brief CORE HTTP Daemon
21 * @defgroup APACHE_CORE_HTTPD Core HTTP Daemon
22 * @ingroup APACHE_CORE
26 #ifndef APACHE_HTTP_CORE_H
27 #define APACHE_HTTP_CORE_H
31 #include "apr_optional.h"
32 #include "util_filter.h"
34 #include "apr_tables.h"
36 #include "http_config.h"
38 #if APR_HAVE_STRUCT_RLIMIT
40 #include <sys/resource.h>
48 /* ****************************************************************
50 * The most basic server code is encapsulated in a single module
51 * known as the core, which is just *barely* functional enough to
52 * serve documents, though not terribly well.
54 * Largely for NCSA back-compatibility reasons, the core needs to
55 * make pieces of its config structures available to other modules.
56 * The accessors are declared here, along with the interpretation
57 * of one of them (allow_options).
61 * @defgroup APACHE_CORE_HTTPD_ACESSORS Acessors
63 * @brief File/Directory Accessor directives
70 /** Indexes directive */
72 /** SSI is enabled without exec= permission */
73 #define OPT_INCLUDES 2
74 /** FollowSymLinks directive */
75 #define OPT_SYM_LINKS 4
76 /** ExecCGI directive */
78 /** directive unset */
80 /** SSI exec= permission is permitted, iff OPT_INCLUDES is also set */
81 #define OPT_INC_WITH_EXEC 32
82 /** SymLinksIfOwnerMatch directive */
83 #define OPT_SYM_OWNER 64
84 /** MultiViews directive */
87 #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_INC_WITH_EXEC|OPT_SYM_LINKS|OPT_EXECCGI)
91 * @defgroup get_remote_host Remote Host Resolution
92 * @ingroup APACHE_CORE_HTTPD
95 /** REMOTE_HOST returns the hostname, or NULL if the hostname
96 * lookup fails. It will force a DNS lookup according to the
97 * HostnameLookups setting.
99 #define REMOTE_HOST (0)
101 /** REMOTE_NAME returns the hostname, or the dotted quad if the
102 * hostname lookup fails. It will force a DNS lookup according
103 * to the HostnameLookups setting.
105 #define REMOTE_NAME (1)
107 /** REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
110 #define REMOTE_NOLOOKUP (2)
112 /** REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
113 * a double reverse lookup, regardless of the HostnameLookups
114 * setting. The result is the (double reverse checked) hostname,
115 * or NULL if any of the lookups fail.
117 #define REMOTE_DOUBLE_REV (3)
119 /** @} // get_remote_host */
121 /** all of the requirements must be met */
122 #define SATISFY_ALL 0
123 /** any of the requirements must be met */
124 #define SATISFY_ANY 1
125 /** There are no applicable satisfy lines */
126 #define SATISFY_NOSPEC 2
128 /** Make sure we don't write less than 8000 bytes at any one time.
130 #define AP_MIN_BYTES_TO_WRITE 8000
132 /** default maximum of internal redirects */
133 # define AP_DEFAULT_MAX_INTERNAL_REDIRECTS 10
135 /** default maximum subrequest nesting level */
136 # define AP_DEFAULT_MAX_SUBREQ_DEPTH 10
139 * Retrieve the value of Options for this request
140 * @param r The current request
141 * @return the Options bitmask
143 AP_DECLARE(int) ap_allow_options(request_rec *r);
146 * Retrieve the value of the AllowOverride for this request
147 * @param r The current request
148 * @return the overrides bitmask
150 AP_DECLARE(int) ap_allow_overrides(request_rec *r);
153 * Retrieve the document root for this server
154 * @param r The current request
155 * @warning Don't use this! If your request went through a Userdir, or
156 * something like that, it'll screw you. But it's back-compatible...
157 * @return The document root
159 AP_DECLARE(const char *) ap_document_root(request_rec *r);
162 * Lookup the remote user agent's DNS name or IP address
163 * @ingroup get_remote_host
164 * @param req The current request
165 * @param type The type of lookup to perform. One of:
167 * REMOTE_HOST returns the hostname, or NULL if the hostname
168 * lookup fails. It will force a DNS lookup according to the
169 * HostnameLookups setting.
170 * REMOTE_NAME returns the hostname, or the dotted quad if the
171 * hostname lookup fails. It will force a DNS lookup according
172 * to the HostnameLookups setting.
173 * REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
175 * REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
176 * a double reverse lookup, regardless of the HostnameLookups
177 * setting. The result is the (double reverse checked)
178 * hostname, or NULL if any of the lookups fail.
180 * @param str_is_ip unless NULL is passed, this will be set to non-zero on
181 * output when an IP address string is returned
182 * @return The remote hostname (based on the request useragent_ip)
184 AP_DECLARE(const char *) ap_get_useragent_host(request_rec *req, int type,
188 * Lookup the remote client's DNS name or IP address
189 * @ingroup get_remote_host
190 * @param conn The current connection
191 * @param dir_config The directory config vector from the request
192 * @param type The type of lookup to perform. One of:
194 * REMOTE_HOST returns the hostname, or NULL if the hostname
195 * lookup fails. It will force a DNS lookup according to the
196 * HostnameLookups setting.
197 * REMOTE_NAME returns the hostname, or the dotted quad if the
198 * hostname lookup fails. It will force a DNS lookup according
199 * to the HostnameLookups setting.
200 * REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
202 * REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
203 * a double reverse lookup, regardless of the HostnameLookups
204 * setting. The result is the (double reverse checked)
205 * hostname, or NULL if any of the lookups fail.
207 * @param str_is_ip unless NULL is passed, this will be set to non-zero on output when an IP address
209 * @return The remote hostname (based on the connection client_ip)
211 AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip);
214 * Retrieve the login name of the remote user. Undef if it could not be
216 * @param r The current request
217 * @return The user logged in to the client machine
219 AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r);
221 /* Used for constructing self-referencing URLs, and things like SERVER_PORT,
225 * build a fully qualified URL from the uri and information in the request rec
226 * @param p The pool to allocate the URL from
227 * @param uri The path to the requested file
228 * @param r The current request
229 * @return A fully qualified URL
231 AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r);
234 * Get the current server name from the request
235 * @param r The current request
236 * @return the server name
238 AP_DECLARE(const char *) ap_get_server_name(request_rec *r);
241 * Get the current server name from the request for the purposes
242 * of using in a URL. If the server name is an IPv6 literal
243 * address, it will be returned in URL format (e.g., "[fe80::1]").
244 * @param r The current request
245 * @return the server name
247 AP_DECLARE(const char *) ap_get_server_name_for_url(request_rec *r);
250 * Get the current server port
251 * @param r The current request
252 * @return The server's port
254 AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r);
257 * Get the size of read buffers
258 * @param r The current request
259 * @return The read buffers size
261 AP_DECLARE(apr_size_t) ap_get_read_buf_size(const request_rec *r);
264 * Return the limit on bytes in request msg body
265 * @param r The current request
266 * @return the maximum number of bytes in the request msg body
268 AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r);
271 * Return the limit on bytes in XML request msg body
272 * @param r The current request
273 * @return the maximum number of bytes in XML request msg body
275 AP_DECLARE(apr_size_t) ap_get_limit_xml_body(const request_rec *r);
278 * Install a custom response handler for a given status
279 * @param r The current request
280 * @param status The status for which the custom response should be used
281 * @param string The custom response. This can be a static string, a file
284 AP_DECLARE(void) ap_custom_response(request_rec *r, int status, const char *string);
287 * Check if the current request is beyond the configured max. number of redirects or subrequests
288 * @param r The current request
289 * @return true (is exceeded) or false
291 AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r);
294 * Check for a definition from the server command line
295 * @param name The define to check for
296 * @return 1 if defined, 0 otherwise
298 AP_DECLARE(int) ap_exists_config_define(const char *name);
299 /* FIXME! See STATUS about how */
300 AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r);
302 /* Authentication stuff. This is one of the places where compatibility
303 * with the old config files *really* hurts; they don't discriminate at
304 * all between different authentication schemes, meaning that we need
305 * to maintain common state for all of them in the core, and make it
306 * available to the other modules through interfaces.
309 /** @see require_line */
310 typedef struct require_line require_line;
313 * @brief A structure to keep track of authorization requirements
315 struct require_line {
316 /** Where the require line is in the config file. */
317 apr_int64_t method_mask;
318 /** The complete string from the command line */
323 * Return the type of authorization required for this request
324 * @param r The current request
325 * @return The authorization required
327 AP_DECLARE(const char *) ap_auth_type(request_rec *r);
330 * Return the current Authorization realm
331 * @param r The current request
332 * @return The current authorization realm
334 AP_DECLARE(const char *) ap_auth_name(request_rec *r);
337 * How the requires lines must be met.
338 * @param r The current request
339 * @return How the requirements must be met. One of:
341 * SATISFY_ANY -- any of the requirements must be met.
342 * SATISFY_ALL -- all of the requirements must be met.
343 * SATISFY_NOSPEC -- There are no applicable satisfy lines
346 AP_DECLARE(int) ap_satisfies(request_rec *r);
349 * Core is also unlike other modules in being implemented in more than
350 * one file... so, data structures are declared here, even though most of
351 * the code that cares really is in http_core.c. Also, another accessor.
353 AP_DECLARE_DATA extern module core_module;
356 * Accessor for core_module's specific data. Equivalent to
357 * ap_get_module_config(cv, &core_module) but more efficient.
358 * @param cv The vector in which the modules configuration is stored.
359 * usually r->per_dir_config or s->module_config
360 * @return The module-specific data
362 AP_DECLARE(void *) ap_get_core_module_config(const ap_conf_vector_t *cv);
365 * Accessor to set core_module's specific data. Equivalent to
366 * ap_set_module_config(cv, &core_module, val) but more efficient.
367 * @param cv The vector in which the modules configuration is stored.
368 * usually r->per_dir_config or s->module_config
369 * @param val The module-specific data to set
371 AP_DECLARE(void) ap_set_core_module_config(ap_conf_vector_t *cv, void *val);
373 /** Get the socket from the core network filter. This should be used instead of
374 * accessing the core connection config directly.
375 * @param c The connection record
378 AP_DECLARE(apr_socket_t *) ap_get_conn_socket(conn_rec *c);
381 #define AP_CORE_MODULE_INDEX 0
382 #define ap_get_core_module_config(v) \
383 (((void **)(v))[AP_CORE_MODULE_INDEX])
384 #define ap_set_core_module_config(v, val) \
385 ((((void **)(v))[AP_CORE_MODULE_INDEX]) = (val))
387 #define AP_CORE_MODULE_INDEX (AP_DEBUG_ASSERT(core_module.module_index == 0), 0)
391 * @brief Per-request configuration
394 /** bucket brigade used by getline for look-ahead and
395 * ap_get_client_block for holding left-over request body */
396 struct apr_bucket_brigade *bb;
398 /** an array of per-request working data elements, accessed
399 * by ID using ap_get_request_note()
400 * (Use ap_register_request_note() during initialization
405 /** Custom response strings registered via ap_custom_response(),
406 * or NULL; check per-dir config if nothing found here
408 char **response_code_strings; /* from ap_custom_response(), not from
412 /** per-request document root of the server. This allows mass vhosting
413 * modules better compatibility with some scripts. Normally the
414 * context_* info should be used instead */
415 const char *document_root;
418 * more fine-grained context information which is set by modules like
419 * mod_alias and mod_userdir
421 /** the context root directory on disk for the current resource,
422 * without trailing slash
424 const char *context_document_root;
425 /** the URI prefix that corresponds to the context_document_root directory,
426 * without trailing slash
428 const char *context_prefix;
430 /** There is a script processor installed on the output filter chain,
431 * so it needs the default_handler to deliver a (script) file into
432 * the chain so it can process it. Normally, default_handler only
433 * serves files on a GET request (assuming the file is actual content),
434 * since other methods are not content-retrieval. This flag overrides
435 * that behavior, stating that the "content" is actually a script and
436 * won't actually be delivered as the response for the non-GET method.
440 /** Should addition of charset= be suppressed for this request?
442 int suppress_charset;
443 } core_request_config;
445 /* Standard entries that are guaranteed to be accessible via
446 * ap_get_request_note() for each request (additional entries
447 * can be added with ap_register_request_note())
449 #define AP_NOTE_DIRECTORY_WALK 0
450 #define AP_NOTE_LOCATION_WALK 1
451 #define AP_NOTE_FILE_WALK 2
452 #define AP_NOTE_IF_WALK 3
453 #define AP_NUM_STD_NOTES 4
456 * Reserve an element in the core_request_config->notes array
457 * for some application-specific data
458 * @return An integer key that can be passed to ap_get_request_note()
459 * during request processing to access this element for the
462 AP_DECLARE(apr_size_t) ap_register_request_note(void);
465 * Retrieve a pointer to an element in the core_request_config->notes array
466 * @param r The request
467 * @param note_num A key for the element: either a value obtained from
468 * ap_register_request_note() or one of the predefined AP_NOTE_*
470 * @return NULL if the note_num is invalid, otherwise a pointer to the
471 * requested note element.
472 * @remark At the start of a request, each note element is NULL. The
473 * handle provided by ap_get_request_note() is a pointer-to-pointer
474 * so that the caller can point the element to some app-specific
475 * data structure. The caller should guarantee that any such
476 * structure will last as long as the request itself.
478 AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num);
481 typedef unsigned char allow_options_t;
482 typedef unsigned int overrides_t;
485 * Bits of info that go into making an ETag for a file
486 * document. Why a long? Because char historically
487 * proved too short for Options, and int can be different
488 * sizes on different platforms.
490 typedef unsigned long etag_components_t;
493 #define ETAG_NONE (1 << 0)
494 #define ETAG_MTIME (1 << 1)
495 #define ETAG_INODE (1 << 2)
496 #define ETAG_SIZE (1 << 3)
497 #define ETAG_ALL (ETAG_MTIME | ETAG_INODE | ETAG_SIZE)
498 /* This is the default value used */
499 #define ETAG_BACKWARD (ETAG_MTIME | ETAG_SIZE)
501 /* Generic ON/OFF/UNSET for unsigned int foo :2 */
502 #define AP_CORE_CONFIG_OFF (0)
503 #define AP_CORE_CONFIG_ON (1)
504 #define AP_CORE_CONFIG_UNSET (2)
506 /* Generic merge of flag */
507 #define AP_CORE_MERGE_FLAG(field, to, base, over) to->field = \
508 over->field != AP_CORE_CONFIG_UNSET \
513 * @brief Server Signature Enumeration
520 } server_signature_e;
523 * @brief Per-directory configuration
526 /** path of the directory/regex/etc. see also d_is_fnmatch/absolute below */
528 /** the number of slashes in d */
529 unsigned d_components;
531 /** If (opts & OPT_UNSET) then no absolute assignment to options has
533 * invariant: (opts_add & opts_remove) == 0
534 * Which said another way means that the last relative (options + or -)
535 * assignment made to each bit is recorded in exactly one of opts_add
538 allow_options_t opts;
539 allow_options_t opts_add;
540 allow_options_t opts_remove;
541 overrides_t override;
542 allow_options_t override_opts;
544 /* Used to be the custom response config. No longer used. */
545 char **response_code_strings; /* from ErrorDocument, not from
546 * ap_custom_response() */
548 /* Hostname resolution etc */
549 #define HOSTNAME_LOOKUP_OFF 0
550 #define HOSTNAME_LOOKUP_ON 1
551 #define HOSTNAME_LOOKUP_DOUBLE 2
552 #define HOSTNAME_LOOKUP_UNSET 3
553 unsigned int hostname_lookups : 4;
555 unsigned int content_md5 : 2; /* calculate Content-MD5? */
557 #define USE_CANONICAL_NAME_OFF (0)
558 #define USE_CANONICAL_NAME_ON (1)
559 #define USE_CANONICAL_NAME_DNS (2)
560 #define USE_CANONICAL_NAME_UNSET (3)
561 unsigned use_canonical_name : 2;
563 /* since is_fnmatch(conf->d) was being called so frequently in
564 * directory_walk() and its relatives, this field was created and
565 * is set to the result of that call.
567 unsigned d_is_fnmatch : 1;
569 /* should we force a charset on any outgoing parameterless content-type?
570 * if so, which charset?
572 #define ADD_DEFAULT_CHARSET_OFF (0)
573 #define ADD_DEFAULT_CHARSET_ON (1)
574 #define ADD_DEFAULT_CHARSET_UNSET (2)
575 unsigned add_default_charset : 2;
576 const char *add_default_charset_name;
578 /* System Resource Control */
580 struct rlimit *limit_cpu;
582 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
583 struct rlimit *limit_mem;
586 struct rlimit *limit_nproc;
588 apr_off_t limit_req_body; /* limit on bytes in request msg body */
589 long limit_xml_body; /* limit on bytes in XML request msg body */
591 /* logging options */
593 server_signature_e server_signature;
596 apr_array_header_t *sec_file;
597 apr_array_header_t *sec_if;
600 const char *mime_type; /* forced with ForceType */
601 const char *handler; /* forced by something other than SetHandler */
602 const char *output_filters; /* forced with SetOutputFilters */
603 const char *input_filters; /* forced with SetInputFilters */
604 int accept_path_info; /* forced with AcceptPathInfo */
607 * What attributes/data should be included in ETag generation?
609 etag_components_t etag_bits;
610 etag_components_t etag_add;
611 etag_components_t etag_remove;
614 * Run-time performance tuning
616 #define ENABLE_MMAP_OFF (0)
617 #define ENABLE_MMAP_ON (1)
618 #define ENABLE_MMAP_UNSET (2)
619 unsigned int enable_mmap : 2; /* whether files in this dir can be mmap'ed */
621 #define ENABLE_SENDFILE_OFF (0)
622 #define ENABLE_SENDFILE_ON (1)
623 #define ENABLE_SENDFILE_UNSET (2)
624 unsigned int enable_sendfile : 2; /* files in this dir can be sendfile'ed */
626 #define USE_CANONICAL_PHYS_PORT_OFF (0)
627 #define USE_CANONICAL_PHYS_PORT_ON (1)
628 #define USE_CANONICAL_PHYS_PORT_UNSET (2)
629 unsigned int use_canonical_phys_port : 2;
631 unsigned int allow_encoded_slashes : 1; /* URLs may contain %2f w/o being
632 * pitched indiscriminately */
633 unsigned int decode_encoded_slashes : 1; /* whether to decode encoded slashes in URLs */
635 #define AP_CONDITION_IF 1
636 #define AP_CONDITION_ELSE 2
637 #define AP_CONDITION_ELSEIF (AP_CONDITION_ELSE|AP_CONDITION_IF)
638 unsigned int condition_ifelse : 2; /* is this an <If>, <ElseIf>, or <Else> */
640 ap_expr_info_t *condition; /* Conditionally merge <If> sections */
642 /** per-dir log config */
643 struct ap_logconf *log;
645 /** Table of directives allowed per AllowOverrideList */
646 apr_table_t *override_list;
648 #define AP_MAXRANGES_UNSET -1
649 #define AP_MAXRANGES_DEFAULT -2
650 #define AP_MAXRANGES_UNLIMITED -3
651 #define AP_MAXRANGES_NORANGES 0
652 /** Number of Ranges before returning HTTP_OK. **/
654 /** Max number of Range overlaps (merges) allowed **/
656 /** Max number of Range reversals (eg: 200-300, 100-125) allowed **/
659 unsigned int allow_encoded_slashes_set : 1;
660 unsigned int decode_encoded_slashes_set : 1;
662 /** Named back references */
663 apr_array_header_t *refs;
665 #define AP_CGI_PASS_AUTH_OFF (0)
666 #define AP_CGI_PASS_AUTH_ON (1)
667 #define AP_CGI_PASS_AUTH_UNSET (2)
668 /** CGIPassAuth: Whether HTTP authorization headers will be passed to
669 * scripts as CGI variables; affects all modules calling
670 * ap_add_common_vars(), as well as any others using this field as
673 unsigned int cgi_pass_auth : 2;
675 /** Custom response config with expression support. The hash table
676 * contains compiled expressions keyed against the custom response
679 apr_hash_t *response_code_exprs;
681 unsigned int qualify_redirect_url :2;
682 ap_expr_info_t *expr_handler; /* forced with SetHandler */
684 /** Table of rules for building CGI variables, NULL if none configured */
685 apr_hash_t *cgi_var_rules;
687 apr_size_t read_buf_size;
690 /* macro to implement off by default behaviour */
691 #define AP_SENDFILE_ENABLED(x) \
692 ((x) == ENABLE_SENDFILE_ON ? APR_SENDFILE_ENABLED : 0)
694 /* Per-server core configuration */
700 /* Name translations --- we want the core to be able to do *something*
701 * so it's at least a minimally functional web server on its own (and
702 * can be tested that way). But let's keep it to the bare minimum:
704 const char *ap_document_root;
709 apr_array_header_t *sec_dir;
710 apr_array_header_t *sec_url;
712 /* recursion backstopper */
713 int redirect_limit; /* maximum number of internal redirects */
714 int subreq_limit; /* maximum nesting level of subrequests */
716 const char *protocol;
717 apr_table_t *accf_map;
719 /* array of ap_errorlog_format_item for error log format string */
720 apr_array_header_t *error_log_format;
722 * two arrays of arrays of ap_errorlog_format_item for additional information
723 * logged to the error log once per connection/request
725 apr_array_header_t *error_log_conn;
726 apr_array_header_t *error_log_req;
729 #define AP_TRACE_UNSET -1
730 #define AP_TRACE_DISABLE 0
731 #define AP_TRACE_ENABLE 1
732 #define AP_TRACE_EXTENDED 2
734 #define AP_MERGE_TRAILERS_UNSET 0
735 #define AP_MERGE_TRAILERS_ENABLE 1
736 #define AP_MERGE_TRAILERS_DISABLE 2
739 apr_array_header_t *conn_log_level;
741 #define AP_HTTP09_UNSET 0
742 #define AP_HTTP09_ENABLE 1
743 #define AP_HTTP09_DISABLE 2
746 #define AP_HTTP_CONFORMANCE_UNSET 0
747 #define AP_HTTP_CONFORMANCE_UNSAFE 1
748 #define AP_HTTP_CONFORMANCE_STRICT 2
749 char http_conformance;
751 #define AP_HTTP_METHODS_UNSET 0
752 #define AP_HTTP_METHODS_LENIENT 1
753 #define AP_HTTP_METHODS_REGISTERED 2
756 #define AP_HTTP_CL_HEAD_ZERO_UNSET 0
757 #define AP_HTTP_CL_HEAD_ZERO_ENABLE 1
758 #define AP_HTTP_CL_HEAD_ZERO_DISABLE 2
759 int http_cl_head_zero;
761 #define AP_HTTP_EXPECT_STRICT_UNSET 0
762 #define AP_HTTP_EXPECT_STRICT_ENABLE 1
763 #define AP_HTTP_EXPECT_STRICT_DISABLE 2
764 int http_expect_strict;
766 apr_array_header_t *protocols;
767 int protocols_honor_order;
769 unsigned int async_filter_set:1;
771 apr_size_t flush_max_threshold;
772 apr_int32_t flush_max_pipelined;
773 unsigned int strict_host_check;
774 } core_server_config;
776 /* for AddOutputFiltersByType in core.c */
777 void ap_add_output_filters_by_type(request_rec *r);
779 /* for http_config.c */
780 void ap_core_reorder_directories(apr_pool_t *, server_rec *);
783 AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config);
784 AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config);
785 AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
786 AP_CORE_DECLARE(const char *) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
787 AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg);
789 /* Core filters; not exported. */
790 apr_status_t ap_core_input_filter(ap_filter_t *f, apr_bucket_brigade *b,
791 ap_input_mode_t mode, apr_read_type_e block,
792 apr_off_t readbytes);
793 apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *b);
796 AP_DECLARE(const char*) ap_get_server_protocol(server_rec* s);
797 AP_DECLARE(void) ap_set_server_protocol(server_rec* s, const char* proto);
799 typedef struct core_output_filter_ctx core_output_filter_ctx_t;
800 typedef struct core_filter_ctx core_ctx_t;
802 typedef struct core_net_rec {
803 /** Connection to the client */
804 apr_socket_t *client_socket;
806 /** connection record */
809 core_output_filter_ctx_t *out_ctx;
814 * Insert the network bucket into the core input filter's input brigade.
815 * This hook is intended for MPMs or protocol modules that need to do special
817 * @param c The connection
818 * @param bb The brigade to insert the bucket into
819 * @param socket The socket to put into a bucket
820 * @return AP_DECLINED if the current function does not handle this connection,
821 * APR_SUCCESS or an error otherwise.
823 AP_DECLARE_HOOK(apr_status_t, insert_network_bucket,
824 (conn_rec *c, apr_bucket_brigade *bb, apr_socket_t *socket))
826 /* ----------------------------------------------------------------------
828 * Runtime status/management
844 const char *description;
846 ap_mgmt_type_e vtype;
850 /* Handles for core filters */
851 AP_DECLARE_DATA extern ap_filter_rec_t *ap_subreq_core_filter_handle;
852 AP_DECLARE_DATA extern ap_filter_rec_t *ap_core_output_filter_handle;
853 AP_DECLARE_DATA extern ap_filter_rec_t *ap_content_length_filter_handle;
854 AP_DECLARE_DATA extern ap_filter_rec_t *ap_core_input_filter_handle;
855 AP_DECLARE_DATA extern ap_filter_rec_t *ap_request_core_filter_handle;
858 * This hook provdes a way for modules to provide metrics/statistics about
859 * their operational status.
861 * @param p A pool to use to create entries in the hash table
862 * @param val The name of the parameter(s) that is wanted. This is
863 * tree-structured would be in the form ('*' is all the tree,
864 * 'module.*' all of the module , 'module.foo.*', or
866 * @param ht The hash table to store the results. Keys are item names, and
867 * the values point to ap_mgmt_item_t structures.
870 AP_DECLARE_HOOK(int, get_mgmt_items,
871 (apr_pool_t *p, const char * val, apr_hash_t *ht))
873 /* ---------------------------------------------------------------------- */
875 /* ----------------------------------------------------------------------
877 * I/O logging with mod_logio
880 APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_out,
881 (conn_rec *c, apr_off_t bytes));
883 APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_in,
884 (conn_rec *c, apr_off_t bytes));
886 APR_DECLARE_OPTIONAL_FN(apr_off_t, ap_logio_get_last_bytes, (conn_rec *c));
888 /* ----------------------------------------------------------------------
894 * The info structure passed to callback functions of errorlog handlers.
895 * Not all information is available in all contexts. In particular, all
896 * pointers may be NULL.
898 typedef struct ap_errorlog_info {
899 /** current server_rec.
900 * Should be preferred over c->base_server and r->server
904 /** current conn_rec.
905 * Should be preferred over r->connection
909 /** current request_rec. */
910 const request_rec *r;
911 /** r->main if r is a subrequest, otherwise equal to r */
912 const request_rec *rmain;
914 /** pool passed to ap_log_perror, NULL otherwise */
917 /** name of source file where the log message was produced, NULL if N/A. */
919 /** line number in the source file, 0 if N/A */
922 /** module index of module that produced the log message, APLOG_NO_MODULE if N/A. */
924 /** log level of error message (flags like APLOG_STARTUP have been removed), -1 if N/A */
927 /** apr error status related to the log message, 0 if no error */
930 /** 1 if logging using provider, 0 otherwise */
932 /** 1 if APLOG_STARTUP was set for the log message, 0 otherwise */
935 /** message format */
939 #define AP_ERRORLOG_PROVIDER_GROUP "error_log_writer"
940 #define AP_ERRORLOG_PROVIDER_VERSION "0"
941 #define AP_ERRORLOG_DEFAULT_PROVIDER "file"
943 /** add APR_EOL_STR to the end of log message */
944 #define AP_ERRORLOG_PROVIDER_ADD_EOL_STR 1
946 typedef struct ap_errorlog_provider ap_errorlog_provider;
948 struct ap_errorlog_provider {
949 /** Initializes the error log writer.
950 * @param p The pool to create any storage from
951 * @param s Server for which the logger is initialized
952 * @return Pointer to handle passed later to writer() function
953 * @note On success, the provider must return non-NULL, even if
954 * the handle is not necessary when the writer() function is
955 * called. On failure, the provider should log a startup error
956 * message and return NULL to abort httpd startup.
958 void * (*init)(apr_pool_t *p, server_rec *s);
960 /** Logs the error message to external error log.
961 * @param info Context of the error message
962 * @param handle Handle created by init() function
963 * @param errstr Error message
964 * @param len Length of the error message
966 apr_status_t (*writer)(const ap_errorlog_info *info, void *handle,
967 const char *errstr, apr_size_t len);
969 /** Checks syntax of ErrorLog directive argument.
970 * @param cmd The config directive
971 * @param arg ErrorLog directive argument (or the empty string if
972 * no argument was provided)
973 * @return Error message or NULL on success
974 * @remark The argument will be stored in the error_fname field
975 * of server_rec for access later.
977 const char * (*parse_errorlog_arg)(cmd_parms *cmd, const char *arg);
979 /** a combination of the AP_ERRORLOG_PROVIDER_* flags */
984 * callback function prototype for a external errorlog handler
985 * @note To avoid unbounded memory usage, these functions must not allocate
986 * memory from the server, connection, or request pools. If an errorlog
987 * handler absolutely needs a pool to pass to other functions, it must create
988 * and destroy a sub-pool.
990 typedef int ap_errorlog_handler_fn_t(const ap_errorlog_info *info,
991 const char *arg, char *buf, int buflen);
994 * Register external errorlog handler
995 * @param p config pool to use
996 * @param tag the new format specifier (i.e. the letter after the %)
997 * @param handler the handler function
998 * @param flags flags (reserved, set to 0)
1000 AP_DECLARE(void) ap_register_errorlog_handler(apr_pool_t *p, char *tag,
1001 ap_errorlog_handler_fn_t *handler,
1004 typedef struct ap_errorlog_handler {
1005 ap_errorlog_handler_fn_t *func;
1006 int flags; /* for future extensions */
1007 } ap_errorlog_handler;
1009 /** item starts a new field */
1010 #define AP_ERRORLOG_FLAG_FIELD_SEP 1
1011 /** item is the actual error message */
1012 #define AP_ERRORLOG_FLAG_MESSAGE 2
1013 /** skip whole line if item is zero-length */
1014 #define AP_ERRORLOG_FLAG_REQUIRED 4
1015 /** log zero-length item as '-' */
1016 #define AP_ERRORLOG_FLAG_NULL_AS_HYPHEN 8
1019 /** ap_errorlog_handler function */
1020 ap_errorlog_handler_fn_t *func;
1021 /** argument passed to item in {} */
1023 /** a combination of the AP_ERRORLOG_* flags */
1025 /** only log item if the message's log level is higher than this */
1026 unsigned int min_loglevel;
1027 } ap_errorlog_format_item;
1030 * hook method to log error messages
1032 * @param info pointer to ap_errorlog_info struct which contains all
1034 * @param errstr the (unformatted) message to log
1035 * @warning Allocating from the usual pools (pool, info->c->pool, info->p->pool)
1036 * must be avoided because it can cause memory leaks.
1037 * Use a subpool if necessary.
1039 AP_DECLARE_HOOK(void, error_log, (const ap_errorlog_info *info,
1040 const char *errstr))
1042 AP_CORE_DECLARE(void) ap_register_log_hooks(apr_pool_t *p);
1043 AP_CORE_DECLARE(void) ap_register_config_hooks(apr_pool_t *p);
1045 /* ----------------------------------------------------------------------
1047 * ident lookups with mod_ident
1050 APR_DECLARE_OPTIONAL_FN(const char *, ap_ident_lookup,
1053 /* ----------------------------------------------------------------------
1055 * authorization values with mod_authz_core
1058 APR_DECLARE_OPTIONAL_FN(int, authz_some_auth_required, (request_rec *r));
1059 APR_DECLARE_OPTIONAL_FN(const char *, authn_ap_auth_type, (request_rec *r));
1060 APR_DECLARE_OPTIONAL_FN(const char *, authn_ap_auth_name, (request_rec *r));
1062 /* ----------------------------------------------------------------------
1064 * authorization values with mod_access_compat
1067 APR_DECLARE_OPTIONAL_FN(int, access_compat_ap_satisfies, (request_rec *r));
1069 /* ---------------------------------------------------------------------- */
1071 /** Query the server for some state information
1072 * @param query_code Which information is requested
1073 * @return the requested state information
1075 AP_DECLARE(int) ap_state_query(int query_code);
1078 * possible values for query_code in ap_state_query()
1081 /** current status of the server */
1082 #define AP_SQ_MAIN_STATE 0
1083 /** are we going to serve requests or are we just testing/dumping config */
1084 #define AP_SQ_RUN_MODE 1
1085 /** generation of the top-level apache parent */
1086 #define AP_SQ_CONFIG_GEN 2
1089 * return values for ap_state_query()
1092 /** return value for unknown query_code */
1093 #define AP_SQ_NOT_SUPPORTED -1
1095 /* values returned for AP_SQ_MAIN_STATE */
1096 /** before the config preflight */
1097 #define AP_SQ_MS_INITIAL_STARTUP 1
1098 /** initial configuration run for setting up log config, etc. */
1099 #define AP_SQ_MS_CREATE_PRE_CONFIG 2
1100 /** tearing down configuration */
1101 #define AP_SQ_MS_DESTROY_CONFIG 3
1102 /** normal configuration run */
1103 #define AP_SQ_MS_CREATE_CONFIG 4
1104 /** running the MPM */
1105 #define AP_SQ_MS_RUN_MPM 5
1106 /** cleaning up for exit */
1107 #define AP_SQ_MS_EXITING 6
1109 /* values returned for AP_SQ_RUN_MODE */
1110 /** command line not yet parsed */
1111 #define AP_SQ_RM_UNKNOWN 1
1112 /** normal operation (server requests or signal server) */
1113 #define AP_SQ_RM_NORMAL 2
1114 /** config test only */
1115 #define AP_SQ_RM_CONFIG_TEST 3
1116 /** only dump some parts of the config */
1117 #define AP_SQ_RM_CONFIG_DUMP 4
1120 /* ---------------------------------------------------------------------- */
1122 /** Create a slave connection
1123 * @param c The connection to create the slave connection from/for
1124 * @return The slave connection
1126 AP_CORE_DECLARE(conn_rec *) ap_create_slave_connection(conn_rec *c);
1129 /** Macro to provide a default value if the pointer is not yet initialised
1131 #define AP_CORE_DEFAULT(X, Y, Z) (X ? X->Y : Z)
1137 #endif /* !APACHE_HTTP_CORE_H */