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