]> granicus.if.org Git - apache/blob - include/http_core.h
*) include/httpd.h: Add a brigade for temporary uses in the core input filter context.
[apache] / include / http_core.h
1 /* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
2  * applicable.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * 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 #ifndef APACHE_HTTP_CORE_H
18 #define APACHE_HTTP_CORE_H
19
20 #include "apr.h"
21 #include "apr_hash.h"
22 #include "apr_optional.h"
23 #include "util_filter.h"
24
25 #if APR_HAVE_STRUCT_RLIMIT
26 #include <sys/time.h>
27 #include <sys/resource.h>
28 #endif
29
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /**
36  * @package CORE HTTP Daemon
37  */
38
39 /* ****************************************************************
40  *
41  * The most basic server code is encapsulated in a single module
42  * known as the core, which is just *barely* functional enough to
43  * serve documents, though not terribly well.
44  *
45  * Largely for NCSA back-compatibility reasons, the core needs to
46  * make pieces of its config structures available to other modules.
47  * The accessors are declared here, along with the interpretation
48  * of one of them (allow_options).
49  */
50
51 #define OPT_NONE 0
52 #define OPT_INDEXES 1
53 #define OPT_INCLUDES 2
54 #define OPT_SYM_LINKS 4
55 #define OPT_EXECCGI 8
56 #define OPT_UNSET 16
57 #define OPT_INCNOEXEC 32
58 #define OPT_SYM_OWNER 64
59 #define OPT_MULTI 128
60 #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS|OPT_EXECCGI)
61
62 /* options for get_remote_host() */
63 /* REMOTE_HOST returns the hostname, or NULL if the hostname
64  * lookup fails.  It will force a DNS lookup according to the
65  * HostnameLookups setting.
66  */
67 #define REMOTE_HOST (0)
68
69 /* REMOTE_NAME returns the hostname, or the dotted quad if the
70  * hostname lookup fails.  It will force a DNS lookup according
71  * to the HostnameLookups setting.
72  */
73 #define REMOTE_NAME (1)
74
75 /* REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
76  * never forced.
77  */
78 #define REMOTE_NOLOOKUP (2)
79
80 /* REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
81  * a double reverse lookup, regardless of the HostnameLookups
82  * setting.  The result is the (double reverse checked) hostname,
83  * or NULL if any of the lookups fail.
84  */
85 #define REMOTE_DOUBLE_REV (3)
86
87 #define SATISFY_ALL 0
88 #define SATISFY_ANY 1
89 #define SATISFY_NOSPEC 2
90
91 /* Make sure we don't write less than 8000 bytes at any one time.
92  */
93 #define AP_MIN_BYTES_TO_WRITE  8000
94
95 /* default maximum of internal redirects */
96 # define AP_DEFAULT_MAX_INTERNAL_REDIRECTS 10
97
98 /* default maximum subrequest nesting level */
99 # define AP_DEFAULT_MAX_SUBREQ_DEPTH 10
100
101 /**
102  * Retrieve the value of Options for this request
103  * @param r The current request
104  * @return the Options bitmask
105  * @deffunc int ap_allow_options(request_rec *r)
106  */
107 AP_DECLARE(int) ap_allow_options(request_rec *r);
108
109 /**
110  * Retrieve the value of the AllowOverride for this request
111  * @param r The current request
112  * @return the overrides bitmask
113  * @deffunc int ap_allow_overrides(request_rec *r)
114  */
115 AP_DECLARE(int) ap_allow_overrides(request_rec *r);
116
117 /**
118  * Retrieve the value of the DefaultType directive, or text/plain if not set
119  * @param r The current request
120  * @return The default type
121  * @deffunc const char *ap_default_type(request_rec *r)
122  */
123 AP_DECLARE(const char *) ap_default_type(request_rec *r);     
124
125 /**
126  * Retrieve the document root for this server
127  * @param r The current request
128  * @warning Don't use this!  If your request went through a Userdir, or 
129  * something like that, it'll screw you.  But it's back-compatible...
130  * @return The document root
131  * @deffunc const char *ap_document_root(request_rec *r)
132  */
133 AP_DECLARE(const char *) ap_document_root(request_rec *r);
134
135 /**
136  * Lookup the remote client's DNS name or IP address
137  * @param conn The current connection
138  * @param dir_config The directory config vector from the request
139  * @param type The type of lookup to perform.  One of:
140  * <pre>
141  *     REMOTE_HOST returns the hostname, or NULL if the hostname
142  *                 lookup fails.  It will force a DNS lookup according to the
143  *                 HostnameLookups setting.
144  *     REMOTE_NAME returns the hostname, or the dotted quad if the
145  *                 hostname lookup fails.  It will force a DNS lookup according
146  *                 to the HostnameLookups setting.
147  *     REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
148  *                     never forced.
149  *     REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
150  *                   a double reverse lookup, regardless of the HostnameLookups
151  *                   setting.  The result is the (double reverse checked) 
152  *                   hostname, or NULL if any of the lookups fail.
153  * </pre>
154  * @param str_is_ip unless NULL is passed, this will be set to non-zero on output when an IP address 
155  *        string is returned
156  * @return The remote hostname
157  * @deffunc const char *ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip)
158  */
159 AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type, int *str_is_ip);
160
161 /**
162  * Retrieve the login name of the remote user.  Undef if it could not be
163  * determined
164  * @param r The current request
165  * @return The user logged in to the client machine
166  * @deffunc const char *ap_get_remote_logname(request_rec *r)
167  */
168 AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r);
169
170 /* Used for constructing self-referencing URLs, and things like SERVER_PORT,
171  * and SERVER_NAME.
172  */
173 /**
174  * build a fully qualified URL from the uri and information in the request rec
175  * @param p The pool to allocate the URL from
176  * @param uri The path to the requested file
177  * @param r The current request
178  * @return A fully qualified URL
179  * @deffunc char *ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r)
180  */
181 AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r);
182
183 /**
184  * Get the current server name from the request
185  * @param r The current request
186  * @return the server name
187  * @deffunc const char *ap_get_server_name(request_rec *r)
188  */
189 AP_DECLARE(const char *) ap_get_server_name(request_rec *r);
190
191 /**
192  * Get the current server port
193  * @param The current request
194  * @return The server's port
195  * @deffunc apr_port_t ap_get_server_port(const request_rec *r)
196  */
197 AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r);
198
199 /**
200  * Return the limit on bytes in request msg body 
201  * @param r The current request
202  * @return the maximum number of bytes in the request msg body
203  * @deffunc apr_off_t ap_get_limit_req_body(const request_rec *r)
204  */
205 AP_DECLARE(apr_off_t) ap_get_limit_req_body(const request_rec *r);
206
207 /**
208  * Return the limit on bytes in XML request msg body
209  * @param r The current request
210  * @return the maximum number of bytes in XML request msg body
211  * @deffunc size_t ap_get_limit_xml_body(const request_rec *r)
212  */
213 AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r);
214
215 /**
216  * Install a custom response handler for a given status
217  * @param r The current request
218  * @param status The status for which the custom response should be used
219  * @param string The custom response.  This can be a static string, a file
220  *               or a URL
221  */
222 AP_DECLARE(void) ap_custom_response(request_rec *r, int status, const char *string);
223
224 /**
225  * Check if the current request is beyond the configured max. number of redirects or subrequests
226  * @param r The current request
227  * @return true (is exceeded) or false
228  * @deffunc int ap_is_recursion_limit_exceeded(const request_rec *r)
229  */
230 AP_DECLARE(int) ap_is_recursion_limit_exceeded(const request_rec *r);
231
232 /**
233  * Check for a definition from the server command line
234  * @param name The define to check for
235  * @return 1 if defined, 0 otherwise
236  * @deffunc int ap_exists_config_define(const char *name)
237  */
238 AP_DECLARE(int) ap_exists_config_define(const char *name);
239 /* FIXME! See STATUS about how */
240 AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r);
241
242 /* Authentication stuff.  This is one of the places where compatibility
243  * with the old config files *really* hurts; they don't discriminate at
244  * all between different authentication schemes, meaning that we need
245  * to maintain common state for all of them in the core, and make it
246  * available to the other modules through interfaces.
247  */
248 typedef struct require_line require_line;
249
250 /** A structure to keep track of authorization requirements */
251 struct require_line {
252     /** Where the require line is in the config file. */
253     apr_int64_t method_mask;
254     /** The complete string from the command line */
255     char *requirement;
256 };
257      
258 /**
259  * Return the type of authorization required for this request
260  * @param r The current request
261  * @return The authorization required
262  * @deffunc const char *ap_auth_type(request_rec *r)
263  */
264 AP_DECLARE(const char *) ap_auth_type(request_rec *r);
265
266 /**
267  * Return the current Authorization realm
268  * @param r The current request
269  * @return The current authorization realm
270  * @deffunc const char *ap_auth_name(request_rec *r)
271  */
272 AP_DECLARE(const char *) ap_auth_name(request_rec *r);     
273
274 /**
275  * How the requires lines must be met.
276  * @param r The current request
277  * @return How the requirements must be met.  One of:
278  * <pre>
279  *      SATISFY_ANY    -- any of the requirements must be met.
280  *      SATISFY_ALL    -- all of the requirements must be met.
281  *      SATISFY_NOSPEC -- There are no applicable satisfy lines
282  * </pre>
283  * @deffunc int ap_satisfies(request_rec *r)
284  */
285 AP_DECLARE(int) ap_satisfies(request_rec *r);
286
287 /**
288  * Retrieve information about all of the requires directives for this request
289  * @param r The current request
290  * @return An array of all requires directives for this request
291  * @deffunc const apr_array_header_t *ap_requires(request_rec *r)
292  */
293 AP_DECLARE(const apr_array_header_t *) ap_requires(request_rec *r);    
294
295 #ifdef CORE_PRIVATE
296
297 /*
298  * Core is also unlike other modules in being implemented in more than
299  * one file... so, data structures are declared here, even though most of
300  * the code that cares really is in http_core.c.  Also, another accessor.
301  */
302
303 AP_DECLARE_DATA extern module core_module;
304
305 /* Per-request configuration */
306
307 typedef struct {
308     /* bucket brigade used by getline for look-ahead and 
309      * ap_get_client_block for holding left-over request body */
310     struct apr_bucket_brigade *bb;
311
312     /* an array of per-request working data elements, accessed
313      * by ID using ap_get_request_note()
314      * (Use ap_register_request_note() during initialization
315      * to add elements)
316      */
317     void **notes;
318
319     /* There is a script processor installed on the output filter chain,
320      * so it needs the default_handler to deliver a (script) file into
321      * the chain so it can process it. Normally, default_handler only
322      * serves files on a GET request (assuming the file is actual content),
323      * since other methods are not content-retrieval. This flag overrides
324      * that behavior, stating that the "content" is actually a script and
325      * won't actually be delivered as the response for the non-GET method.
326      */
327     int deliver_script;
328
329     /* Custom response strings registered via ap_custom_response(),
330      * or NULL; check per-dir config if nothing found here
331      */
332     char **response_code_strings; /* from ap_custom_response(), not from
333                                    * ErrorDocument
334                                    */
335 } core_request_config;
336
337 /* Standard entries that are guaranteed to be accessible via
338  * ap_get_request_note() for each request (additional entries
339  * can be added with ap_register_request_note())
340  */
341 #define AP_NOTE_DIRECTORY_WALK 0
342 #define AP_NOTE_LOCATION_WALK  1
343 #define AP_NOTE_FILE_WALK      2
344 #define AP_NUM_STD_NOTES       3
345
346 /**
347  * Reserve an element in the core_request_config->notes array
348  * for some application-specific data
349  * @return An integer key that can be passed to ap_get_request_note()
350  *         during request processing to access this element for the
351  *         current request.
352  */
353 AP_DECLARE(apr_size_t) ap_register_request_note(void);
354
355 /**
356  * Retrieve a pointer to an element in the core_request_config->notes array
357  * @param r The request
358  * @param note_num  A key for the element: either a value obtained from
359  *        ap_register_request_note() or one of the predefined AP_NOTE_*
360  *        values.
361  * @return NULL if the note_num is invalid, otherwise a pointer to the
362  *         requested note element.
363  * @remark At the start of a request, each note element is NULL.  The
364  *         handle provided by ap_get_request_note() is a pointer-to-pointer
365  *         so that the caller can point the element to some app-specific
366  *         data structure.  The caller should guarantee that any such
367  *         structure will last as long as the request itself.
368  */
369 AP_DECLARE(void **) ap_get_request_note(request_rec *r, apr_size_t note_num);
370
371 /* Per-directory configuration */
372
373 typedef unsigned char allow_options_t;
374 typedef unsigned char overrides_t;
375
376 /*
377  * Bits of info that go into making an ETag for a file
378  * document.  Why a long?  Because char historically
379  * proved too short for Options, and int can be different
380  * sizes on different platforms.
381  */
382 typedef unsigned long etag_components_t;
383
384 #define ETAG_UNSET 0
385 #define ETAG_NONE  (1 << 0)
386 #define ETAG_MTIME (1 << 1)
387 #define ETAG_INODE (1 << 2)
388 #define ETAG_SIZE  (1 << 3)
389 #define ETAG_BACKWARD (ETAG_MTIME | ETAG_INODE | ETAG_SIZE)
390 #define ETAG_ALL   (ETAG_MTIME | ETAG_INODE | ETAG_SIZE)
391
392 typedef enum {
393     srv_sig_unset,
394     srv_sig_off,
395     srv_sig_on,
396     srv_sig_withmail
397 } server_signature_e;
398
399 typedef struct {
400     /* path of the directory/regex/etc. see also d_is_fnmatch/absolute below */
401     char *d;
402     /* the number of slashes in d */
403     unsigned d_components;
404
405     /* If (opts & OPT_UNSET) then no absolute assignment to options has
406      * been made.
407      * invariant: (opts_add & opts_remove) == 0
408      * Which said another way means that the last relative (options + or -)
409      * assignment made to each bit is recorded in exactly one of opts_add
410      * or opts_remove.
411      */
412     allow_options_t opts;
413     allow_options_t opts_add;
414     allow_options_t opts_remove;
415     overrides_t override;
416     allow_options_t override_opts;
417     
418     /* MIME typing --- the core doesn't do anything at all with this,
419      * but it does know what to slap on a request for a document which
420      * goes untyped by other mechanisms before it slips out the door...
421      */
422     
423     char *ap_default_type;
424   
425     /* Authentication stuff.  Groan... */
426     
427     int *satisfy; /* for every method one */
428     char *ap_auth_type;
429     char *ap_auth_name;
430     apr_array_header_t *ap_requires;
431
432     /* Custom response config. These can contain text or a URL to redirect to.
433      * if response_code_strings is NULL then there are none in the config,
434      * if it's not null then it's allocated to sizeof(char*)*RESPONSE_CODES.
435      * This lets us do quick merges in merge_core_dir_configs().
436      */
437   
438     char **response_code_strings; /* from ErrorDocument, not from
439                                    * ap_custom_response() */
440
441     /* Hostname resolution etc */
442 #define HOSTNAME_LOOKUP_OFF     0
443 #define HOSTNAME_LOOKUP_ON      1
444 #define HOSTNAME_LOOKUP_DOUBLE  2
445 #define HOSTNAME_LOOKUP_UNSET   3
446     unsigned int hostname_lookups : 4;
447
448     signed int content_md5 : 2;  /* calculate Content-MD5? */
449
450 #define USE_CANONICAL_NAME_OFF   (0)
451 #define USE_CANONICAL_NAME_ON    (1)
452 #define USE_CANONICAL_NAME_DNS   (2)
453 #define USE_CANONICAL_NAME_UNSET (3)
454     unsigned use_canonical_name : 2;
455
456     /* since is_fnmatch(conf->d) was being called so frequently in
457      * directory_walk() and its relatives, this field was created and
458      * is set to the result of that call.
459      */
460     unsigned d_is_fnmatch : 1;
461
462     /* should we force a charset on any outgoing parameterless content-type?
463      * if so, which charset?
464      */
465 #define ADD_DEFAULT_CHARSET_OFF   (0)
466 #define ADD_DEFAULT_CHARSET_ON    (1)
467 #define ADD_DEFAULT_CHARSET_UNSET (2)
468     unsigned add_default_charset : 2;
469     const char *add_default_charset_name;
470
471     /* System Resource Control */
472 #ifdef RLIMIT_CPU
473     struct rlimit *limit_cpu;
474 #endif
475 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
476     struct rlimit *limit_mem;
477 #endif
478 #ifdef RLIMIT_NPROC
479     struct rlimit *limit_nproc;
480 #endif
481     apr_off_t limit_req_body;      /* limit on bytes in request msg body */
482     long limit_xml_body;           /* limit on bytes in XML request msg body */
483
484     /* logging options */
485
486     server_signature_e server_signature;
487
488     int loglevel;
489     
490     /* Access control */
491     apr_array_header_t *sec_file;
492     ap_regex_t *r;
493
494     const char *mime_type;       /* forced with ForceType  */
495     const char *handler;         /* forced with SetHandler */
496     const char *output_filters;  /* forced with SetOutputFilters */
497     const char *input_filters;   /* forced with SetInputFilters */
498     int accept_path_info;        /* forced with AcceptPathInfo */
499
500     apr_hash_t *ct_output_filters; /* added with AddOutputFilterByType */
501
502     /*
503      * What attributes/data should be included in ETag generation?
504      */
505     etag_components_t etag_bits;
506     etag_components_t etag_add;
507     etag_components_t etag_remove;
508
509     /*
510      * Run-time performance tuning
511      */
512 #define ENABLE_MMAP_OFF    (0)
513 #define ENABLE_MMAP_ON     (1)
514 #define ENABLE_MMAP_UNSET  (2)
515     unsigned int enable_mmap : 2;  /* whether files in this dir can be mmap'ed */
516
517 #define ENABLE_SENDFILE_OFF    (0)
518 #define ENABLE_SENDFILE_ON     (1)
519 #define ENABLE_SENDFILE_UNSET  (2)
520     unsigned int enable_sendfile : 2;  /* files in this dir can be mmap'ed */
521     unsigned int allow_encoded_slashes : 1; /* URLs may contain %2f w/o being
522                                              * pitched indiscriminately */
523 } core_dir_config;
524
525 /* Per-server core configuration */
526
527 typedef struct {
528   
529 #ifdef GPROF
530     char *gprof_dir;
531 #endif
532
533     /* Name translations --- we want the core to be able to do *something*
534      * so it's at least a minimally functional web server on its own (and
535      * can be tested that way).  But let's keep it to the bare minimum:
536      */
537     const char *ap_document_root;
538   
539     /* Access control */
540
541     char *access_name;
542     apr_array_header_t *sec_dir;
543     apr_array_header_t *sec_url;
544
545     /* recursion backstopper */
546     int redirect_limit; /* maximum number of internal redirects */
547     int subreq_limit;   /* maximum nesting level of subrequests */
548 } core_server_config;
549
550 /* for AddOutputFiltersByType in core.c */
551 void ap_add_output_filters_by_type(request_rec *r);
552
553 /* for http_config.c */
554 void ap_core_reorder_directories(apr_pool_t *, server_rec *);
555
556 /* for mod_perl */
557 AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config);
558 AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config);
559 AP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config *conf, void *url_config);
560 AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg);
561
562 /* Core filters; not exported. */
563 int ap_net_time_filter(ap_filter_t *f, apr_bucket_brigade *b,
564                        ap_input_mode_t mode, apr_read_type_e block,
565                        apr_off_t readbytes);
566 int ap_core_input_filter(ap_filter_t *f, apr_bucket_brigade *b,
567                          ap_input_mode_t mode, apr_read_type_e block,
568                          apr_off_t readbytes);
569 apr_status_t ap_core_output_filter(ap_filter_t *f, apr_bucket_brigade *b);
570
571 #endif /* CORE_PRIVATE */
572
573
574 /* ----------------------------------------------------------------------
575  *
576  * Runtime status/management
577  */
578
579 typedef enum {
580     ap_mgmt_type_string,
581     ap_mgmt_type_long,
582     ap_mgmt_type_hash
583 } ap_mgmt_type_e;
584
585 typedef union {
586     const char *s_value;
587     long i_value;
588     apr_hash_t *h_value;
589 } ap_mgmt_value;
590
591 typedef struct {
592     const char *description;
593     const char *name;
594     ap_mgmt_type_e vtype;
595     ap_mgmt_value v;
596 } ap_mgmt_item_t;
597
598 /* Handles for core filters */
599 extern AP_DECLARE_DATA ap_filter_rec_t *ap_subreq_core_filter_handle;
600 extern AP_DECLARE_DATA ap_filter_rec_t *ap_core_output_filter_handle;
601 extern AP_DECLARE_DATA ap_filter_rec_t *ap_content_length_filter_handle;
602 extern AP_DECLARE_DATA ap_filter_rec_t *ap_net_time_filter_handle;
603 extern AP_DECLARE_DATA ap_filter_rec_t *ap_core_input_filter_handle;
604
605 /**
606  * This hook provdes a way for modules to provide metrics/statistics about
607  * their operational status.
608  *
609  * @param p A pool to use to create entries in the hash table
610  * @param val The name of the parameter(s) that is wanted. This is
611  *            tree-structured would be in the form ('*' is all the tree,
612  *            'module.*' all of the module , 'module.foo.*', or
613  *            'module.foo.bar' )
614  * @param ht The hash table to store the results. Keys are item names, and
615  *           the values point to ap_mgmt_item_t structures.
616  * @ingroup hooks
617  */
618 AP_DECLARE_HOOK(int, get_mgmt_items,
619                 (apr_pool_t *p, const char * val, apr_hash_t *ht))
620
621 /* ---------------------------------------------------------------------- */
622
623 /* ----------------------------------------------------------------------
624  *
625  * I/O logging with mod_logio
626  */
627
628 APR_DECLARE_OPTIONAL_FN(void, ap_logio_add_bytes_out,
629                         (conn_rec *c, apr_off_t bytes));
630
631 /* ----------------------------------------------------------------------
632  *
633  * ident lookups with mod_ident
634  */
635
636 APR_DECLARE_OPTIONAL_FN(const char *, ap_ident_lookup,
637                         (request_rec *r));
638
639 /* ---------------------------------------------------------------------- */
640
641 #ifdef __cplusplus
642 }
643 #endif
644
645 #endif  /* !APACHE_HTTP_CORE_H */