1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * originally written at the National Center for Supercomputing Applications,
56 * University of Illinois, Urbana-Champaign.
59 #ifndef APACHE_HTTP_CORE_H
60 #define APACHE_HTTP_CORE_H
64 #if APR_HAVE_STRUCT_RLIMIT
66 #include <sys/resource.h>
75 * @package CORE HTTP Daemon
78 /* ****************************************************************
80 * The most basic server code is encapsulated in a single module
81 * known as the core, which is just *barely* functional enough to
82 * serve documents, though not terribly well.
84 * Largely for NCSA back-compatibility reasons, the core needs to
85 * make pieces of its config structures available to other modules.
86 * The accessors are declared here, along with the interpretation
87 * of one of them (allow_options).
92 #define OPT_INCLUDES 2
93 #define OPT_SYM_LINKS 4
96 #define OPT_INCNOEXEC 32
97 #define OPT_SYM_OWNER 64
99 #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS|OPT_EXECCGI)
101 /* options for get_remote_host() */
102 /* REMOTE_HOST returns the hostname, or NULL if the hostname
103 * lookup fails. It will force a DNS lookup according to the
104 * HostnameLookups setting.
106 #define REMOTE_HOST (0)
108 /* REMOTE_NAME returns the hostname, or the dotted quad if the
109 * hostname lookup fails. It will force a DNS lookup according
110 * to the HostnameLookups setting.
112 #define REMOTE_NAME (1)
114 /* REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
117 #define REMOTE_NOLOOKUP (2)
119 /* REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
120 * a double reverse lookup, regardless of the HostnameLookups
121 * setting. The result is the (double reverse checked) hostname,
122 * or NULL if any of the lookups fail.
124 #define REMOTE_DOUBLE_REV (3)
126 #define SATISFY_ALL 0
127 #define SATISFY_ANY 1
128 #define SATISFY_NOSPEC 2
130 /* Make sure we don't write less than 9000 bytes at any one time.
132 #define AP_MIN_BYTES_TO_WRITE 9000
135 * Retrieve the value of Options for this request
136 * @param r The current request
137 * @return the Options bitmask
138 * @deffunc int ap_allow_options(request_rec *r)
140 AP_DECLARE(int) ap_allow_options(request_rec *r);
143 * Retrieve the value of the AllowOverride for this request
144 * @param r The current request
145 * @return the overrides bitmask
146 * @deffunc int ap_allow_overrides(request_rec *r)
148 AP_DECLARE(int) ap_allow_overrides(request_rec *r);
151 * Retrieve the value of the DefaultType directive, or text/plain if not set
152 * @param r The current request
153 * @return The default type
154 * @deffunc const char *ap_default_type(request_rec *r)
156 AP_DECLARE(const char *) ap_default_type(request_rec *r);
159 * Retrieve the document root for this server
160 * @param r The current request
161 * @warning Don't use this! If your request went through a Userdir, or
162 * something like that, it'll screw you. But it's back-compatible...
163 * @return The document root
164 * @deffunc const char *ap_document_root(request_rec *r)
166 AP_DECLARE(const char *) ap_document_root(request_rec *r);
169 * Lookup the remote client's DNS name or IP address
170 * @param conn The current connection
171 * @param dir_config The directory config vector from the request
172 * @param type The type of lookup to perform. One of:
174 * REMOTE_HOST returns the hostname, or NULL if the hostname
175 * lookup fails. It will force a DNS lookup according to the
176 * HostnameLookups setting.
177 * REMOTE_NAME returns the hostname, or the dotted quad if the
178 * hostname lookup fails. It will force a DNS lookup according
179 * to the HostnameLookups setting.
180 * REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
182 * REMOTE_DOUBLE_REV will always force a DNS lookup, and also force
183 * a double reverse lookup, regardless of the HostnameLookups
184 * setting. The result is the (double reverse checked)
185 * hostname, or NULL if any of the lookups fail.
187 * @return The remote hostname
188 * @deffunc const char *ap_get_remote_host(conn_rec *conn, void *dir_config, int type)
190 AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type);
193 * Retrieve the login name of the remote user. Undef if it could not be
195 * @param r The current request
196 * @return The user logged in to the client machine
197 * @deffunc const char *ap_get_remote_logname(request_rec *r)
199 AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r);
201 /* Used for constructing self-referencing URLs, and things like SERVER_PORT,
205 * build a fully qualified URL from the uri and information in the request rec
206 * @param p The pool to allocate the URL from
207 * @param uri The path to the requested file
208 * @param r The current request
209 * @return A fully qualified URL
210 * @deffunc char *ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r)
212 AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r);
215 * Get the current server name from the request
216 * @param r The current request
217 * @return the server name
218 * @deffunc const char *ap_get_server_name(request_rec *r)
220 AP_DECLARE(const char *) ap_get_server_name(request_rec *r);
223 * Get the current server port
224 * @param The current request
225 * @return The server's port
226 * @deffunc apr_port_t ap_get_server_port(const request_rec *r)
228 AP_DECLARE(apr_port_t) ap_get_server_port(const request_rec *r);
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 * @deffunc unsigned long ap_get_limit_req_body(const request_rec *r)
236 AP_DECLARE(unsigned long) ap_get_limit_req_body(const request_rec *r);
239 * Return the limit on bytes in XML request msg body
240 * @param r The current request
241 * @return the maximum number of bytes in XML request msg body
242 * @deffunc size_t ap_get_limit_xml_body(const request_rec *r)
244 AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r);
247 * Install a custom response handler for a given status
248 * @param r The current request
249 * @param status The status for which the custom response should be used
250 * @param string The custom response. This can be a static string, a file
252 * @deffunc void ap_custom_response(request_rec *r, int status, char *string)
254 AP_DECLARE(void) ap_custom_response(request_rec *r, int status, char *string);
257 * Check for a definition from the server command line
258 * @param name The define to check for
259 * @return 1 if defined, 0 otherwise
260 * @deffunc int ap_exists_config_define(const char *name)
262 AP_DECLARE(int) ap_exists_config_define(const char *name);
263 /* FIXME! See STATUS about how */
264 AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r);
266 /* Authentication stuff. This is one of the places where compatibility
267 * with the old config files *really* hurts; they don't discriminate at
268 * all between different authentication schemes, meaning that we need
269 * to maintain common state for all of them in the core, and make it
270 * available to the other modules through interfaces.
272 typedef struct require_line require_line;
274 /** A structure to keep track of authorization requirements */
275 struct require_line {
276 /** Where the require line is in the config file. */
278 /** The complete string from the command line */
283 * Return the type of authorization required for this request
284 * @param r The current request
285 * @return The authorization required
286 * @deffunc const char *ap_auth_type(request_rec *r)
288 AP_DECLARE(const char *) ap_auth_type(request_rec *r);
291 * Return the current Authorization realm
292 * @param r The current request
293 * @return The current authorization realm
294 * @deffunc const char *ap_auth_name(request_rec *r)
296 AP_DECLARE(const char *) ap_auth_name(request_rec *r);
299 * How the requires lines must be met.
300 * @param r The current request
301 * @return How the requirements must be met. One of:
303 * SATISFY_ANY -- any of the requirements must be met.
304 * SATISFY_ALL -- all of the requirements must be met.
305 * SATISFY_NOSPEC -- There are no applicable satisfy lines
307 * @deffunc int ap_satisfies(request_rec *r)
309 AP_DECLARE(int) ap_satisfies(request_rec *r);
312 * Retrieve information about all of the requires directives for this request
313 * @param r The current request
314 * @return An array of all requires directives for this request
315 * @deffunc const apr_array_header_t *ap_requires(request_rec *r)
317 AP_DECLARE(const apr_array_header_t *) ap_requires(request_rec *r);
321 * CGI Script stuff for Win32...
323 typedef enum { eFileTypeUNKNOWN, eFileTypeBIN, eFileTypeEXE16, eFileTypeEXE32,
324 eFileTypeSCRIPT } file_type_e;
325 typedef enum { INTERPRETER_SOURCE_UNSET, INTERPRETER_SOURCE_REGISTRY_STRICT,
326 INTERPRETER_SOURCE_REGISTRY, INTERPRETER_SOURCE_SHEBANG
327 } interpreter_source_e;
328 AP_DECLARE(file_type_e) ap_get_win32_interpreter(const request_rec *,
336 * Core is also unlike other modules in being implemented in more than
337 * one file... so, data structures are declared here, even though most of
338 * the code that cares really is in http_core.c. Also, another accessor.
341 AP_DECLARE_DATA extern module core_module;
343 /* Per-request configuration */
346 /* bucket brigade used by getline for look-ahead and
347 * ap_get_client_block for holding left-over request body */
348 struct apr_bucket_brigade *bb;
349 } core_request_config;
351 /* Per-directory configuration */
353 typedef unsigned char allow_options_t;
354 typedef unsigned char overrides_t;
361 } server_signature_e;
364 /* path of the directory/regex/etc. see also d_is_fnmatch below */
366 /* the number of slashes in d */
367 unsigned d_components;
369 /* If (opts & OPT_UNSET) then no absolute assignment to options has
371 * invariant: (opts_add & opts_remove) == 0
372 * Which said another way means that the last relative (options + or -)
373 * assignment made to each bit is recorded in exactly one of opts_add
376 allow_options_t opts;
377 allow_options_t opts_add;
378 allow_options_t opts_remove;
379 overrides_t override;
381 /* MIME typing --- the core doesn't do anything at all with this,
382 * but it does know what to slap on a request for a document which
383 * goes untyped by other mechanisms before it slips out the door...
386 char *ap_default_type;
388 /* Authentication stuff. Groan... */
393 apr_array_header_t *ap_requires;
395 /* Custom response config. These can contain text or a URL to redirect to.
396 * if response_code_strings is NULL then there are none in the config,
397 * if it's not null then it's allocated to sizeof(char*)*RESPONSE_CODES.
398 * This lets us do quick merges in merge_core_dir_configs().
401 char **response_code_strings;
403 /* Hostname resolution etc */
404 #define HOSTNAME_LOOKUP_OFF 0
405 #define HOSTNAME_LOOKUP_ON 1
406 #define HOSTNAME_LOOKUP_DOUBLE 2
407 #define HOSTNAME_LOOKUP_UNSET 3
408 unsigned int hostname_lookups : 4;
410 signed int do_rfc1413 : 2; /* See if client is advertising a username? */
412 signed int content_md5 : 2; /* calculate Content-MD5? */
414 #define USE_CANONICAL_NAME_OFF (0)
415 #define USE_CANONICAL_NAME_ON (1)
416 #define USE_CANONICAL_NAME_DNS (2)
417 #define USE_CANONICAL_NAME_UNSET (3)
418 unsigned use_canonical_name : 2;
420 /* since is_fnmatch(conf->d) was being called so frequently in
421 * directory_walk() and its relatives, this field was created and
422 * is set to the result of that call.
424 unsigned d_is_fnmatch : 1;
426 /* should we force a charset on any outgoing parameterless content-type?
427 * if so, which charset?
429 #define ADD_DEFAULT_CHARSET_OFF (0)
430 #define ADD_DEFAULT_CHARSET_ON (1)
431 #define ADD_DEFAULT_CHARSET_UNSET (2)
432 unsigned add_default_charset : 2;
433 const char *add_default_charset_name;
435 /* System Resource Control */
437 struct rlimit *limit_cpu;
439 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
440 struct rlimit *limit_mem;
443 struct rlimit *limit_nproc;
445 unsigned long limit_req_body; /* limit on bytes in request msg body */
446 long limit_xml_body; /* limit on bytes in XML request msg body */
448 /* logging options */
450 server_signature_e server_signature;
455 apr_array_header_t *sec;
459 /* Where to find interpreter to run scripts */
460 interpreter_source_e script_interpreter_source;
463 apr_array_header_t *output_filters;
464 apr_array_header_t *input_filters;
467 /* Per-server core configuration */
475 /* Name translations --- we want the core to be able to do *something*
476 * so it's at least a minimally functional web server on its own (and
477 * can be tested that way). But let's keep it to the bare minimum:
479 const char *ap_document_root;
484 apr_array_header_t *sec;
485 apr_array_header_t *sec_url;
486 } core_server_config;
488 /* for http_config.c */
489 void ap_core_reorder_directories(apr_pool_t *, server_rec *);
492 AP_CORE_DECLARE(void) ap_add_per_dir_conf(server_rec *s, void *dir_config);
493 AP_CORE_DECLARE(void) ap_add_per_url_conf(server_rec *s, void *url_config);
494 AP_CORE_DECLARE(void) ap_add_file_conf(core_dir_config *conf, void *url_config);
495 AP_CORE_DECLARE_NONSTD(const char *) ap_limit_section(cmd_parms *cmd, void *dummy, const char *arg);
503 #endif /* !APACHE_HTTP_CORE_H */