]> granicus.if.org Git - apache/blob - include/http_core.h
Allow SetHandler+UDS+fcgi to take advantage of dedicated workers including
[apache] / include / http_core.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file  http_core.h
19  * @brief CORE HTTP Daemon
20  *
21  * @defgroup APACHE_CORE_HTTPD Core HTTP Daemon
22  * @ingroup  APACHE_CORE
23  * @{
24  */
25
26 #ifndef APACHE_HTTP_CORE_H
27 #define APACHE_HTTP_CORE_H
28
29 #include "apr.h"
30 #include "apr_hash.h"
31 #include "apr_optional.h"
32 #include "util_filter.h"
33 #include "ap_expr.h"
34 #include "apr_tables.h"
35
36 #include "http_config.h"
37
38 #if APR_HAVE_STRUCT_RLIMIT
39 #include <sys/time.h>
40 #include <sys/resource.h>
41 #endif
42
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /* ****************************************************************
49  *
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.
53  *
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).
58  */
59
60 /**
61  * @defgroup APACHE_CORE_HTTPD_ACESSORS Acessors
62  *
63  * @brief File/Directory Accessor directives
64  *
65  * @{
66  */
67
68 /** No directives */
69 #define OPT_NONE 0
70 /** Indexes directive */
71 #define OPT_INDEXES 1
72 /** SSI is enabled without exec= permission  */
73 #define OPT_INCLUDES 2
74 /**  FollowSymLinks directive */
75 #define OPT_SYM_LINKS 4
76 /**  ExecCGI directive */
77 #define OPT_EXECCGI 8
78 /**  directive unset */
79 #define OPT_UNSET 16
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 */
85 #define OPT_MULTI 128
86 /**  All directives */
87 #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_INC_WITH_EXEC|OPT_SYM_LINKS|OPT_EXECCGI)
88 /** @} */
89
90 /**
91  * @defgroup get_remote_host Remote Host Resolution
92  * @ingroup APACHE_CORE_HTTPD
93  * @{
94  */
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.
98  */
99 #define REMOTE_HOST (0)
100
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.
104  */
105 #define REMOTE_NAME (1)
106
107 /** REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
108  * never forced.
109  */
110 #define REMOTE_NOLOOKUP (2)
111
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.
116  */
117 #define REMOTE_DOUBLE_REV (3)
118
119 /** @} // get_remote_host */
120
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
127
128 /** Make sure we don't write less than 8000 bytes at any one time.
129  */
130 #define AP_MIN_BYTES_TO_WRITE  8000
131
132 /** default maximum of internal redirects */
133 # define AP_DEFAULT_MAX_INTERNAL_REDIRECTS 10
134
135 /** default maximum subrequest nesting level */
136 # define AP_DEFAULT_MAX_SUBREQ_DEPTH 10
137
138 /**
139  * Retrieve the value of Options for this request
140  * @param r The current request
141  * @return the Options bitmask
142  */
143 AP_DECLARE(int) ap_allow_options(request_rec *r);
144
145 /**
146  * Retrieve the value of the AllowOverride for this request
147  * @param r The current request
148  * @return the overrides bitmask
149  */
150 AP_DECLARE(int) ap_allow_overrides(request_rec *r);
151
152 /**
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
158  */
159 AP_DECLARE(const char *) ap_document_root(request_rec *r);
160
161 /**
162  * Lookup the remote client's DNS name or IP address
163  * @ingroup get_remote_host
164  * @param conn The current connection
165  * @param dir_config The directory config vector from the request
166  * @param type The type of lookup to perform.  One of:
167  * <pre>
168  *     REMOTE_HOST returns the hostname, or NULL if the hostname
169  *                 lookup fails.  It will force a DNS lookup according to the
170  *                 HostnameLookups setting.
171  *     REMOTE_NAME returns the hostname, or the dotted quad if the
172  *                 hostname lookup fails.  It will force a DNS lookup according
173  *                 to the HostnameLookups setting.
174  *     REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
175  *                     never forced.
176  *     REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
177  *                   a double reverse lookup, regardless of the HostnameLookups
178  *                   setting.  The result is the (double reverse checked)
179  *                   hostname, or NULL if any of the lookups fail.
180  * </pre>
181  * @param str_is_ip unless NULL is passed, this will be set to non-zero on output when an IP address
182  *        string is returned
183  * @return The remote hostname
184  */
185 AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip);
186
187 /**
188  * Retrieve the login name of the remote user.  Undef if it could not be
189  * determined
190  * @param r The current request
191  * @return The user logged in to the client machine
192  */
193 AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r);
194
195 /* Used for constructing self-referencing URLs, and things like SERVER_PORT,
196  * and SERVER_NAME.
197  */
198 /**
199  * build a fully qualified URL from the uri and information in the request rec
200  * @param p The pool to allocate the URL from
201  * @param uri The path to the requested file
202  * @param r The current request
203  * @return A fully qualified URL
204  */
205 AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r);
206
207 /**
208  * Get the current server name from the request
209  * @param r The current request
210  * @return the server name
211  */
212 AP_DECLARE(const char *) ap_get_server_name(request_rec *r);
213
214 /**
215  * Get the current server name from the request for the purposes
216  * of using in a URL.  If the server name is an IPv6 literal
217  * address, it will be returned in URL format (e.g., "[fe80::1]").
218  * @param r The current request
219  * @return the server name
220  */
221 AP_DECLARE(const char *) ap_get_server_name_for_url(request_rec *r);
222
223 /**
224  * Get the current server port
225  * @param r The current request
226  * @return The server's port
227  */
228 AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r);
229
230 /**
231  * Return the limit on bytes in request msg body
232  * @param r The current request
233  * @return the maximum number of bytes in the request msg body
234  */
235 AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r);
236
237 /**
238  * Return the limit on bytes in XML request msg body
239  * @param r The current request
240  * @return the maximum number of bytes in XML request msg body
241  */
242 AP_DECLARE(apr_size_t) ap_get_limit_xml_body(const request_rec *r);
243
244 /**
245  * Install a custom response handler for a given status
246  * @param r The current request
247  * @param status The status for which the custom response should be used
248  * @param string The custom response.  This can be a static string, a file
249  *               or a URL
250  */
251 AP_DECLARE(void) ap_custom_response(request_rec *r, int status, const char *string);
252
253 /**
254  * Check if the current request is beyond the configured max. number of redirects or subrequests
255  * @param r The current request
256  * @return true (is exceeded) or false
257  */
258 AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r);
259
260 /**
261  * Check for a definition from the server command line
262  * @param name The define to check for
263  * @return 1 if defined, 0 otherwise
264  */
265 AP_DECLARE(int) ap_exists_config_define(const char *name);
266 /* FIXME! See STATUS about how */
267 AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r);
268
269 /* Authentication stuff.  This is one of the places where compatibility
270  * with the old config files *really* hurts; they don't discriminate at
271  * all between different authentication schemes, meaning that we need
272  * to maintain common state for all of them in the core, and make it
273  * available to the other modules through interfaces.
274  */
275
276 /** @see require_line */
277 typedef struct require_line require_line;
278
279 /**
280  * @brief A structure to keep track of authorization requirements
281 */
282 struct require_line {
283     /** Where the require line is in the config file. */
284     apr_int64_t method_mask;
285     /** The complete string from the command line */
286     char *requirement;
287 };
288
289 /**
290  * Return the type of authorization required for this request
291  * @param r The current request
292  * @return The authorization required
293  */
294 AP_DECLARE(const char *) ap_auth_type(request_rec *r);
295
296 /**
297  * Return the current Authorization realm
298  * @param r The current request
299  * @return The current authorization realm
300  */
301 AP_DECLARE(const char *) ap_auth_name(request_rec *r);
302
303 /**
304  * How the requires lines must be met.
305  * @param r The current request
306  * @return How the requirements must be met.  One of:
307  * <pre>
308  *      SATISFY_ANY    -- any of the requirements must be met.
309  *      SATISFY_ALL    -- all of the requirements must be met.
310  *      SATISFY_NOSPEC -- There are no applicable satisfy lines
311  * </pre>
312  */
313 AP_DECLARE(int) ap_satisfies(request_rec *r);
314
315 /**
316  * Core is also unlike other modules in being implemented in more than
317  * one file... so, data structures are declared here, even though most of
318  * the code that cares really is in http_core.c.  Also, another accessor.
319  */
320 AP_DECLARE_DATA extern module core_module;
321
322 /**
323  * Accessor for core_module's specific data. Equivalent to
324  * ap_get_module_config(cv, &core_module) but more efficient.
325  * @param cv The vector in which the modules configuration is stored.
326  *        usually r->per_dir_config or s->module_config
327  * @return The module-specific data
328  */
329 AP_DECLARE(void *) ap_get_core_module_config(const ap_conf_vector_t *cv);
330
331 /**
332  * Accessor to set core_module's specific data. Equivalent to
333  * ap_set_module_config(cv, &core_module, val) but more efficient.
334  * @param cv The vector in which the modules configuration is stored.
335  *        usually r->per_dir_config or s->module_config
336  * @param val The module-specific data to set
337  */
338 AP_DECLARE(void) ap_set_core_module_config(ap_conf_vector_t *cv, void *val);
339
340 /** Get the socket from the core network filter. This should be used instead of
341  * accessing the core connection config directly.
342  * @param c The connection record
343  * @return The socket
344  */
345 AP_DECLARE(apr_socket_t *) ap_get_conn_socket(conn_rec *c);
346
347 #ifndef AP_DEBUG
348 #define AP_CORE_MODULE_INDEX  0
349 #define ap_get_core_module_config(v) \
350     (((void **)(v))[AP_CORE_MODULE_INDEX])
351 #define ap_set_core_module_config(v, val) \
352     ((((void **)(v))[AP_CORE_MODULE_INDEX]) = (val))
353 #else
354 #define AP_CORE_MODULE_INDEX  (AP_DEBUG_ASSERT(core_module.module_index == 0), 0)
355 #endif
356
357 /**
358  * @brief  Per-request configuration
359 */
360 typedef struct {
361     /** bucket brigade used by getline for look-ahead and
362      * ap_get_client_block for holding left-over request body */
363     struct apr_bucket_brigade *bb;
364
365     /** an array of per-request working data elements, accessed
366      * by ID using ap_get_request_note()
367      * (Use ap_register_request_note() during initialization
368      * to add elements)
369      */
370     void **notes;
371
372     /** Custom response strings registered via ap_custom_response(),
373      * or NULL; check per-dir config if nothing found here
374      */
375     char **response_code_strings; /* from ap_custom_response(), not from
376                                    * ErrorDocument
377                                    */
378
379     /** per-request document root of the server. This allows mass vhosting
380      * modules better compatibility with some scripts. Normally the
381      * context_* info should be used instead */
382     const char *document_root;
383
384     /*
385      * more fine-grained context information which is set by modules like
386      * mod_alias and mod_userdir
387      */
388     /** the context root directory on disk for the current resource,
389      *  without trailing slash
390      */
391     const char *context_document_root;
392     /** the URI prefix that corresponds to the context_document_root directory,
393      *  without trailing slash
394      */
395     const char *context_prefix;
396
397     /** There is a script processor installed on the output filter chain,
398      * so it needs the default_handler to deliver a (script) file into
399      * the chain so it can process it. Normally, default_handler only
400      * serves files on a GET request (assuming the file is actual content),
401      * since other methods are not content-retrieval. This flag overrides
402      * that behavior, stating that the "content" is actually a script and
403      * won't actually be delivered as the response for the non-GET method.
404      */
405     int deliver_script;
406
407     /** Should addition of charset= be suppressed for this request?
408      */
409     int suppress_charset;
410 } core_request_config;
411
412 /* Standard entries that are guaranteed to be accessible via
413  * ap_get_request_note() for each request (additional entries
414  * can be added with ap_register_request_note())
415  */
416 #define AP_NOTE_DIRECTORY_WALK 0
417 #define AP_NOTE_LOCATION_WALK  1
418 #define AP_NOTE_FILE_WALK      2
419 #define AP_NOTE_IF_WALK        3
420 #define AP_NUM_STD_NOTES       4
421
422 /**
423  * Reserve an element in the core_request_config->notes array
424  * for some application-specific data
425  * @return An integer key that can be passed to ap_get_request_note()
426  *         during request processing to access this element for the
427  *         current request.
428  */
429 AP_DECLARE(apr_size_t) ap_register_request_note(void);
430
431 /**
432  * Retrieve a pointer to an element in the core_request_config->notes array
433  * @param r The request
434  * @param note_num  A key for the element: either a value obtained from
435  *        ap_register_request_note() or one of the predefined AP_NOTE_*
436  *        values.
437  * @return NULL if the note_num is invalid, otherwise a pointer to the
438  *         requested note element.
439  * @remark At the start of a request, each note element is NULL.  The
440  *         handle provided by ap_get_request_note() is a pointer-to-pointer
441  *         so that the caller can point the element to some app-specific
442  *         data structure.  The caller should guarantee that any such
443  *         structure will last as long as the request itself.
444  */
445 AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num);
446
447
448 typedef unsigned char allow_options_t;
449 typedef unsigned int overrides_t;
450
451 /*
452  * Bits of info that go into making an ETag for a file
453  * document.  Why a long?  Because char historically
454  * proved too short for Options, and int can be different
455  * sizes on different platforms.
456  */
457 typedef unsigned long etag_components_t;
458
459 #define ETAG_UNSET 0
460 #define ETAG_NONE  (1 << 0)
461 #define ETAG_MTIME (1 << 1)
462 #define ETAG_INODE (1 << 2)
463 #define ETAG_SIZE  (1 << 3)
464 #define ETAG_ALL   (ETAG_MTIME | ETAG_INODE | ETAG_SIZE)
465 /* This is the default value used */
466 #define ETAG_BACKWARD (ETAG_MTIME | ETAG_SIZE)
467
468 /**
469  * @brief Server Signature Enumeration
470  */
471 typedef enum {
472     srv_sig_unset,
473     srv_sig_off,
474     srv_sig_on,
475     srv_sig_withmail
476 } server_signature_e;
477
478 /**
479  * @brief Per-directory configuration
480  */
481 typedef struct {
482     /** path of the directory/regex/etc. see also d_is_fnmatch/absolute below */
483     char *d;
484     /** the number of slashes in d */
485     unsigned d_components;
486
487     /** If (opts & OPT_UNSET) then no absolute assignment to options has
488      * been made.
489      * invariant: (opts_add & opts_remove) == 0
490      * Which said another way means that the last relative (options + or -)
491      * assignment made to each bit is recorded in exactly one of opts_add
492      * or opts_remove.
493      */
494     allow_options_t opts;
495     allow_options_t opts_add;
496     allow_options_t opts_remove;
497     overrides_t override;
498     allow_options_t override_opts;
499
500     /* Custom response config. These can contain text or a URL to redirect to.
501      * if response_code_strings is NULL then there are none in the config,
502      * if it's not null then it's allocated to sizeof(char*)*RESPONSE_CODES.
503      * This lets us do quick merges in merge_core_dir_configs().
504      */
505
506     char **response_code_strings; /* from ErrorDocument, not from
507                                    * ap_custom_response() */
508
509     /* Hostname resolution etc */
510 #define HOSTNAME_LOOKUP_OFF     0
511 #define HOSTNAME_LOOKUP_ON      1
512 #define HOSTNAME_LOOKUP_DOUBLE  2
513 #define HOSTNAME_LOOKUP_UNSET   3
514     unsigned int hostname_lookups : 4;
515
516     unsigned int content_md5 : 2;  /* calculate Content-MD5? */
517
518 #define USE_CANONICAL_NAME_OFF   (0)
519 #define USE_CANONICAL_NAME_ON    (1)
520 #define USE_CANONICAL_NAME_DNS   (2)
521 #define USE_CANONICAL_NAME_UNSET (3)
522     unsigned use_canonical_name : 2;
523
524     /* since is_fnmatch(conf->d) was being called so frequently in
525      * directory_walk() and its relatives, this field was created and
526      * is set to the result of that call.
527      */
528     unsigned d_is_fnmatch : 1;
529
530     /* should we force a charset on any outgoing parameterless content-type?
531      * if so, which charset?
532      */
533 #define ADD_DEFAULT_CHARSET_OFF   (0)
534 #define ADD_DEFAULT_CHARSET_ON    (1)
535 #define ADD_DEFAULT_CHARSET_UNSET (2)
536     unsigned add_default_charset : 2;
537     const char *add_default_charset_name;
538
539     /* System Resource Control */
540 #ifdef RLIMIT_CPU
541     struct rlimit *limit_cpu;
542 #endif
543 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
544     struct rlimit *limit_mem;
545 #endif
546 #ifdef RLIMIT_NPROC
547     struct rlimit *limit_nproc;
548 #endif
549     apr_off_t limit_req_body;      /* limit on bytes in request msg body */
550     long limit_xml_body;           /* limit on bytes in XML request msg body */
551
552     /* logging options */
553
554     server_signature_e server_signature;
555
556     /* Access control */
557     apr_array_header_t *sec_file;
558     apr_array_header_t *sec_if;
559     ap_regex_t *r;
560
561     const char *mime_type;       /* forced with ForceType  */
562     const char *handler;         /* forced with SetHandler */
563     const char *output_filters;  /* forced with SetOutputFilters */
564     const char *input_filters;   /* forced with SetInputFilters */
565     int accept_path_info;        /* forced with AcceptPathInfo */
566
567     /*
568      * What attributes/data should be included in ETag generation?
569      */
570     etag_components_t etag_bits;
571     etag_components_t etag_add;
572     etag_components_t etag_remove;
573
574     /*
575      * Run-time performance tuning
576      */
577 #define ENABLE_MMAP_OFF    (0)
578 #define ENABLE_MMAP_ON     (1)
579 #define ENABLE_MMAP_UNSET  (2)
580     unsigned int enable_mmap : 2;  /* whether files in this dir can be mmap'ed */
581
582 #define ENABLE_SENDFILE_OFF    (0)
583 #define ENABLE_SENDFILE_ON     (1)
584 #define ENABLE_SENDFILE_UNSET  (2)
585     unsigned int enable_sendfile : 2;  /* files in this dir can be sendfile'ed */
586
587 #define USE_CANONICAL_PHYS_PORT_OFF   (0)
588 #define USE_CANONICAL_PHYS_PORT_ON    (1)
589 #define USE_CANONICAL_PHYS_PORT_UNSET (2)
590     unsigned int use_canonical_phys_port : 2;
591
592     unsigned int allow_encoded_slashes : 1; /* URLs may contain %2f w/o being
593                                              * pitched indiscriminately */
594     unsigned int decode_encoded_slashes : 1; /* whether to decode encoded slashes in URLs */
595
596 #define AP_CONDITION_IF        1
597 #define AP_CONDITION_ELSE      2
598 #define AP_CONDITION_ELSEIF    (AP_CONDITION_ELSE|AP_CONDITION_IF)
599     unsigned int condition_ifelse : 2; /* is this an <If>, <ElseIf>, or <Else> */
600
601     ap_expr_info_t *condition;   /* Conditionally merge <If> sections */
602
603     /** per-dir log config */
604     struct ap_logconf *log;
605
606     /** Table of directives allowed per AllowOverrideList */
607     apr_table_t *override_list;
608
609 #define AP_MAXRANGES_UNSET     -1
610 #define AP_MAXRANGES_DEFAULT   -2
611 #define AP_MAXRANGES_UNLIMITED -3
612 #define AP_MAXRANGES_NORANGES   0
613     /** Number of Ranges before returning HTTP_OK. **/
614     int max_ranges;
615     /** Max number of Range overlaps (merges) allowed **/
616     int max_overlaps;
617     /** Max number of Range reversals (eg: 200-300, 100-125) allowed **/
618     int max_reversals;
619
620     unsigned int allow_encoded_slashes_set : 1;
621     unsigned int decode_encoded_slashes_set : 1;
622     unsigned int d_is_directory : 1;
623
624     /** Named back references */
625     apr_array_header_t *refs;
626
627 #define AP_CGI_PASS_AUTH_OFF     (0)
628 #define AP_CGI_PASS_AUTH_ON      (1)
629 #define AP_CGI_PASS_AUTH_UNSET   (2)
630     /** CGIPassAuth: Whether HTTP authorization headers will be passed to
631      * scripts as CGI variables; affects all modules calling
632      * ap_add_common_vars(), as well as any others using this field as 
633      * advice
634      */
635     unsigned int cgi_pass_auth : 2;
636 } core_dir_config;
637
638 /* macro to implement off by default behaviour */
639 #define AP_SENDFILE_ENABLED(x) \
640     ((x) == ENABLE_SENDFILE_ON ? APR_SENDFILE_ENABLED : 0)
641
642 /* Per-server core configuration */
643
644 typedef struct {
645
646     char *gprof_dir;
647
648     /* Name translations --- we want the core to be able to do *something*
649      * so it's at least a minimally functional web server on its own (and
650      * can be tested that way).  But let's keep it to the bare minimum:
651      */
652     const char *ap_document_root;
653
654     /* Access control */
655
656     char *access_name;
657     apr_array_header_t *sec_dir;
658     apr_array_header_t *sec_url;
659
660     /* recursion backstopper */
661     int redirect_limit; /* maximum number of internal redirects */
662     int subreq_limit;   /* maximum nesting level of subrequests */
663
664     const char *protocol;
665     apr_table_t *accf_map;
666
667     /* array of ap_errorlog_format_item for error log format string */
668     apr_array_header_t *error_log_format;
669     /*
670      * two arrays of arrays of ap_errorlog_format_item for additional information
671      * logged to the error log once per connection/request
672      */
673     apr_array_header_t *error_log_conn;
674     apr_array_header_t *error_log_req;
675
676     /* TRACE control */
677 #define AP_TRACE_UNSET    -1
678 #define AP_TRACE_DISABLE   0
679 #define AP_TRACE_ENABLE    1
680 #define AP_TRACE_EXTENDED  2
681     int trace_enable;
682 #define AP_MERGE_TRAILERS_UNSET    0
683 #define AP_MERGE_TRAILERS_ENABLE   1
684 #define AP_MERGE_TRAILERS_DISABLE  2
685     int merge_trailers;
686
687     apr_array_header_t *conn_log_level;
688
689 #define AP_HTTP09_UNSET   0
690 #define AP_HTTP09_ENABLE  1
691 #define AP_HTTP09_DISABLE 2
692     char http09_enable;
693
694 #define AP_HTTP_CONFORMANCE_UNSET     0
695 #define AP_HTTP_CONFORMANCE_LIBERAL   1
696 #define AP_HTTP_CONFORMANCE_STRICT    2
697 #define AP_HTTP_CONFORMANCE_LOGONLY   4
698     char http_conformance;
699
700 #define AP_HTTP_CL_HEAD_ZERO_UNSET    0
701 #define AP_HTTP_CL_HEAD_ZERO_ENABLE   1
702 #define AP_HTTP_CL_HEAD_ZERO_DISABLE  2
703     int http_cl_head_zero;
704
705 #define AP_HTTP_EXPECT_STRICT_UNSET    0
706 #define AP_HTTP_EXPECT_STRICT_ENABLE   1
707 #define AP_HTTP_EXPECT_STRICT_DISABLE  2
708     int http_expect_strict;
709 } core_server_config;
710
711 /* for AddOutputFiltersByType in core.c */
712 void ap_add_output_filters_by_type(request_rec *r);
713
714 /* for http_config.c */
715 void ap_core_reorder_directories(apr_pool_t *, server_rec *);
716
717 /* for mod_perl */
718 AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config);
719 AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config);
720 AP_CORE_DECLARE(void) ap_add_file_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
721 AP_CORE_DECLARE(const char *) ap_add_if_conf(apr_pool_t *p, core_dir_config *conf, void *url_config);
722 AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg);
723
724 /* Core filters; not exported. */
725 apr_status_t ap_core_input_filter(ap_filter_t *f, apr_bucket_brigade *b,
726                                   ap_input_mode_t mode, apr_read_type_e block,
727                                   apr_off_t readbytes);
728 apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *b);
729
730
731 AP_DECLARE(const char*) ap_get_server_protocol(server_rec* s);
732 AP_DECLARE(void) ap_set_server_protocol(server_rec* s, const char* proto);
733
734 typedef struct core_output_filter_ctx core_output_filter_ctx_t;
735 typedef struct core_filter_ctx        core_ctx_t;
736
737 typedef struct core_net_rec {
738     /** Connection to the client */
739     apr_socket_t *client_socket;
740
741     /** connection record */
742     conn_rec *c;
743
744     core_output_filter_ctx_t *out_ctx;
745     core_ctx_t *in_ctx;
746 } core_net_rec;
747
748 /**
749  * Insert the network bucket into the core input filter's input brigade.
750  * This hook is intended for MPMs or protocol modules that need to do special
751  * socket setup.
752  * @param c The connection
753  * @param bb The brigade to insert the bucket into
754  * @param socket The socket to put into a bucket
755  * @return AP_DECLINED if the current function does not handle this connection,
756  *         APR_SUCCESS or an error otherwise.
757  */
758 AP_DECLARE_HOOK(apr_status_t, insert_network_bucket,
759                 (conn_rec *c, apr_bucket_brigade *bb, apr_socket_t *socket))
760
761 /* ----------------------------------------------------------------------
762  *
763  * Runtime status/management
764  */
765
766 typedef enum {
767     ap_mgmt_type_string,
768     ap_mgmt_type_long,
769     ap_mgmt_type_hash
770 } ap_mgmt_type_e;
771
772 typedef union {
773     const char *s_value;
774     long i_value;
775     apr_hash_t *h_value;
776 } ap_mgmt_value;
777
778 typedef struct {
779     const char *description;
780     const char *name;
781     ap_mgmt_type_e vtype;
782     ap_mgmt_value v;
783 } ap_mgmt_item_t;
784
785 /* Handles for core filters */
786 AP_DECLARE_DATA extern ap_filter_rec_t *ap_subreq_core_filter_handle;
787 AP_DECLARE_DATA extern ap_filter_rec_t *ap_core_output_filter_handle;
788 AP_DECLARE_DATA extern ap_filter_rec_t *ap_content_length_filter_handle;
789 AP_DECLARE_DATA extern ap_filter_rec_t *ap_core_input_filter_handle;
790
791 /**
792  * This hook provdes a way for modules to provide metrics/statistics about
793  * their operational status.
794  *
795  * @param p A pool to use to create entries in the hash table
796  * @param val The name of the parameter(s) that is wanted. This is
797  *            tree-structured would be in the form ('*' is all the tree,
798  *            'module.*' all of the module , 'module.foo.*', or
799  *            'module.foo.bar' )
800  * @param ht The hash table to store the results. Keys are item names, and
801  *           the values point to ap_mgmt_item_t structures.
802  * @ingroup hooks
803  */
804 AP_DECLARE_HOOK(int, get_mgmt_items,
805                 (apr_pool_t *p, const char * val, apr_hash_t *ht))
806
807 /* ---------------------------------------------------------------------- */
808
809 /* ----------------------------------------------------------------------
810  *
811  * I/O logging with mod_logio
812  */
813
814 APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_out,
815                         (conn_rec *c, apr_off_t bytes));
816
817 APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_in,
818                         (conn_rec *c, apr_off_t bytes));
819
820 APR_DECLARE_OPTIONAL_FN(apr_off_t, ap_logio_get_last_bytes, (conn_rec *c));
821
822 /* ----------------------------------------------------------------------
823  *
824  * Error log formats
825  */
826
827 /**
828  * The info structure passed to callback functions of errorlog handlers.
829  * Not all information is available in all contexts. In particular, all
830  * pointers may be NULL.
831  */
832 typedef struct ap_errorlog_info {
833     /** current server_rec.
834      *  Should be preferred over c->base_server and r->server
835      */
836     const server_rec *s;
837
838     /** current conn_rec.
839      *  Should be preferred over r->connection
840      */
841     const conn_rec *c;
842
843     /** current request_rec. */
844     const request_rec *r;
845     /** r->main if r is a subrequest, otherwise equal to r */
846     const request_rec *rmain;
847
848     /** pool passed to ap_log_perror, NULL otherwise */
849     apr_pool_t *pool;
850
851     /** name of source file where the log message was produced, NULL if N/A. */
852     const char *file;
853     /** line number in the source file, 0 if N/A */
854     int line;
855
856     /** module index of module that produced the log message, APLOG_NO_MODULE if N/A. */
857     int module_index;
858     /** log level of error message (flags like APLOG_STARTUP have been removed), -1 if N/A */
859     int level;
860
861     /** apr error status related to the log message, 0 if no error */
862     apr_status_t status;
863
864     /** 1 if logging using provider, 0 otherwise */
865     int using_provider;
866     /** 1 if APLOG_STARTUP was set for the log message, 0 otherwise */
867     int startup;
868
869     /** message format */
870     const char *format;
871 } ap_errorlog_info;
872
873 #define AP_ERRORLOG_PROVIDER_GROUP "error_log_writer"
874 #define AP_ERRORLOG_PROVIDER_VERSION "0"
875 #define AP_ERRORLOG_DEFAULT_PROVIDER "file"
876
877 /** add APR_EOL_STR to the end of log message */
878 #define AP_ERRORLOG_PROVIDER_ADD_EOL_STR       1
879
880 typedef struct ap_errorlog_provider ap_errorlog_provider;
881
882 struct ap_errorlog_provider {
883     /** Initializes the error log writer.
884      * @param p The pool to create any storage from
885      * @param s Server for which the logger is initialized
886      * @return Pointer to handle passed later to writer() function
887      * @note On success, the provider must return non-NULL, even if
888      * the handle is not necessary when the writer() function is
889      * called.  On failure, the provider should log a startup error
890      * message and return NULL to abort httpd startup.
891      */
892     void * (*init)(apr_pool_t *p, server_rec *s);
893
894     /** Logs the error message to external error log.
895      * @param info Context of the error message
896      * @param handle Handle created by init() function
897      * @param errstr Error message
898      * @param len Length of the error message
899      */
900     apr_status_t (*writer)(const ap_errorlog_info *info, void *handle,
901                            const char *errstr, apr_size_t len);
902
903     /** Checks syntax of ErrorLog directive argument.
904      * @param cmd The config directive
905      * @param arg ErrorLog directive argument (or the empty string if
906      * no argument was provided)
907      * @return Error message or NULL on success
908      * @remark The argument will be stored in the error_fname field
909      * of server_rec for access later.
910      */
911     const char * (*parse_errorlog_arg)(cmd_parms *cmd, const char *arg);
912
913     /** a combination of the AP_ERRORLOG_PROVIDER_* flags */
914     unsigned int flags;
915 };
916
917 /**
918  * callback function prototype for a external errorlog handler
919  * @note To avoid unbounded memory usage, these functions must not allocate
920  * memory from the server, connection, or request pools. If an errorlog
921  * handler absolutely needs a pool to pass to other functions, it must create
922  * and destroy a sub-pool.
923  */
924 typedef int ap_errorlog_handler_fn_t(const ap_errorlog_info *info,
925                                      const char *arg, char *buf, int buflen);
926
927 /**
928  * Register external errorlog handler
929  * @param p config pool to use
930  * @param tag the new format specifier (i.e. the letter after the %)
931  * @param handler the handler function
932  * @param flags flags (reserved, set to 0)
933  */
934 AP_DECLARE(void) ap_register_errorlog_handler(apr_pool_t *p, char *tag,
935                                               ap_errorlog_handler_fn_t *handler,
936                                               int flags);
937
938 typedef struct ap_errorlog_handler {
939     ap_errorlog_handler_fn_t *func;
940     int flags; /* for future extensions */
941 } ap_errorlog_handler;
942
943   /** item starts a new field */
944 #define AP_ERRORLOG_FLAG_FIELD_SEP       1
945   /** item is the actual error message */
946 #define AP_ERRORLOG_FLAG_MESSAGE         2
947   /** skip whole line if item is zero-length */
948 #define AP_ERRORLOG_FLAG_REQUIRED        4
949   /** log zero-length item as '-' */
950 #define AP_ERRORLOG_FLAG_NULL_AS_HYPHEN  8
951
952 typedef struct {
953     /** ap_errorlog_handler function */
954     ap_errorlog_handler_fn_t *func;
955     /** argument passed to item in {} */
956     const char *arg;
957     /** a combination of the AP_ERRORLOG_* flags */
958     unsigned int flags;
959     /** only log item if the message's log level is higher than this */
960     unsigned int min_loglevel;
961 } ap_errorlog_format_item;
962
963 /**
964  * hook method to log error messages
965  * @ingroup hooks
966  * @param info pointer to ap_errorlog_info struct which contains all
967  *        the details
968  * @param errstr the (unformatted) message to log
969  * @warning Allocating from the usual pools (pool, info->c->pool, info->p->pool)
970  *          must be avoided because it can cause memory leaks.
971  *          Use a subpool if necessary.
972  */
973 AP_DECLARE_HOOK(void, error_log, (const ap_errorlog_info *info,
974                                   const char *errstr))
975
976 AP_CORE_DECLARE(void) ap_register_log_hooks(apr_pool_t *p);
977 AP_CORE_DECLARE(void) ap_register_config_hooks(apr_pool_t *p);
978
979 /* ----------------------------------------------------------------------
980  *
981  * ident lookups with mod_ident
982  */
983
984 APR_DECLARE_OPTIONAL_FN(const char *, ap_ident_lookup,
985                         (request_rec *r));
986
987 /* ----------------------------------------------------------------------
988  *
989  * authorization values with mod_authz_core
990  */
991
992 APR_DECLARE_OPTIONAL_FN(int, authz_some_auth_required, (request_rec *r));
993 APR_DECLARE_OPTIONAL_FN(const char *, authn_ap_auth_type, (request_rec *r));
994 APR_DECLARE_OPTIONAL_FN(const char *, authn_ap_auth_name, (request_rec *r));
995
996 /* ----------------------------------------------------------------------
997  *
998  * authorization values with mod_access_compat
999  */
1000
1001 APR_DECLARE_OPTIONAL_FN(int, access_compat_ap_satisfies, (request_rec *r));
1002
1003 /* ---------------------------------------------------------------------- */
1004
1005 /** Query the server for some state information
1006  * @param query_code Which information is requested
1007  * @return the requested state information
1008  */
1009 AP_DECLARE(int) ap_state_query(int query_code);
1010
1011 /*
1012  * possible values for query_code in ap_state_query()
1013  */
1014
1015   /** current status of the server */
1016 #define AP_SQ_MAIN_STATE        0
1017   /** are we going to serve requests or are we just testing/dumping config */
1018 #define AP_SQ_RUN_MODE          1
1019     /** generation of the top-level apache parent */
1020 #define AP_SQ_CONFIG_GEN        2
1021
1022 /*
1023  * return values for ap_state_query()
1024  */
1025
1026   /** return value for unknown query_code */
1027 #define AP_SQ_NOT_SUPPORTED       -1
1028
1029 /* values returned for AP_SQ_MAIN_STATE */
1030   /** before the config preflight */
1031 #define AP_SQ_MS_INITIAL_STARTUP   1
1032   /** initial configuration run for setting up log config, etc. */
1033 #define AP_SQ_MS_CREATE_PRE_CONFIG 2
1034   /** tearing down configuration */
1035 #define AP_SQ_MS_DESTROY_CONFIG    3
1036   /** normal configuration run */
1037 #define AP_SQ_MS_CREATE_CONFIG     4
1038   /** running the MPM */
1039 #define AP_SQ_MS_RUN_MPM           5
1040   /** cleaning up for exit */
1041 #define AP_SQ_MS_EXITING           6
1042
1043 /* values returned for AP_SQ_RUN_MODE */
1044   /** command line not yet parsed */
1045 #define AP_SQ_RM_UNKNOWN           1
1046   /** normal operation (server requests or signal server) */
1047 #define AP_SQ_RM_NORMAL            2
1048   /** config test only */
1049 #define AP_SQ_RM_CONFIG_TEST       3
1050   /** only dump some parts of the config */
1051 #define AP_SQ_RM_CONFIG_DUMP       4
1052
1053
1054 /* ---------------------------------------------------------------------- */
1055
1056 /** Create a slave connection
1057  * @param c The connection to create the slave connection from/for
1058  * @return The slave connection
1059  */
1060 AP_CORE_DECLARE(conn_rec *) ap_create_slave_connection(conn_rec *c);
1061
1062 #ifdef __cplusplus
1063 }
1064 #endif
1065
1066 #endif  /* !APACHE_HTTP_CORE_H */
1067 /** @} */