]> granicus.if.org Git - apache/blob - include/http_core.h
fix a warning in a call to apr_psprintf()
[apache] / include / http_core.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
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
17  *    distribution.
18  *
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.
25  *
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.
30  *
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.
34  *
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
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
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/>.
53  *
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.
57  */
58
59 #ifndef APACHE_HTTP_CORE_H
60 #define APACHE_HTTP_CORE_H
61
62 #include "apr.h"
63
64 #if APR_HAVE_STRUCT_RLIMIT
65 #include <sys/time.h>
66 #include <sys/resource.h>
67 #endif
68
69
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73
74 /**
75  * @package CORE HTTP Daemon
76  */
77
78 /* ****************************************************************
79  *
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.
83  *
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).
88  */
89
90 #define OPT_NONE 0
91 #define OPT_INDEXES 1
92 #define OPT_INCLUDES 2
93 #define OPT_SYM_LINKS 4
94 #define OPT_EXECCGI 8
95 #define OPT_UNSET 16
96 #define OPT_INCNOEXEC 32
97 #define OPT_SYM_OWNER 64
98 #define OPT_MULTI 128
99 #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS|OPT_EXECCGI)
100
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.
105  */
106 #define REMOTE_HOST (0)
107
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.
111  */
112 #define REMOTE_NAME (1)
113
114 /* REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is
115  * never forced.
116  */
117 #define REMOTE_NOLOOKUP (2)
118
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.
123  */
124 #define REMOTE_DOUBLE_REV (3)
125
126 #define SATISFY_ALL 0
127 #define SATISFY_ANY 1
128 #define SATISFY_NOSPEC 2
129
130 /* Make sure we don't write less than 9000 bytes at any one time.
131  */
132 #define AP_MIN_BYTES_TO_WRITE  9000
133
134 /**
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)
139  */
140 AP_DECLARE(int) ap_allow_options(request_rec *r);
141
142 /**
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)
147  */
148 AP_DECLARE(int) ap_allow_overrides(request_rec *r);
149
150 /**
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)
155  */
156 AP_DECLARE(const char *) ap_default_type(request_rec *r);     
157
158 /**
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)
165  */
166 AP_DECLARE(const char *) ap_document_root(request_rec *r);
167
168 /**
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:
173  * <PRE>
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
181  *                     never forced.
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.
186  * </PRE>
187  * @return The remote hostname
188  * @deffunc const char *ap_get_remote_host(conn_rec *conn, void *dir_config, int type)
189  */
190 AP_DECLARE(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type);
191
192 /**
193  * Retrieve the login name of the remote user.  Undef if it could not be
194  * determined
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)
198  */
199 AP_DECLARE(const char *) ap_get_remote_logname(request_rec *r);
200
201 /* Used for constructing self-referencing URLs, and things like SERVER_PORT,
202  * and SERVER_NAME.
203  */
204 /**
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)
211  */
212 AP_DECLARE(char *) ap_construct_url(apr_pool_t *p, const char *uri, request_rec *r);
213
214 /**
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)
219  */
220 AP_DECLARE(const char *) ap_get_server_name(request_rec *r);
221
222 /**
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)
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  * @deffunc unsigned long ap_get_limit_req_body(const request_rec *r)
235  */
236 AP_DECLARE(unsigned long) ap_get_limit_req_body(const request_rec *r);
237
238 /**
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)
243  */
244 AP_DECLARE(size_t) ap_get_limit_xml_body(const request_rec *r);
245
246 /**
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
251  *               or a URL
252  * @deffunc void ap_custom_response(request_rec *r, int status, char *string)
253  */
254 AP_DECLARE(void) ap_custom_response(request_rec *r, int status, char *string);
255
256 /**
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)
261  */
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);
265
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.
271  */
272 typedef struct require_line require_line;
273
274 /** A structure to keep track of authorization requirements */
275 struct require_line {
276     /** Where the require line is in the config file. */
277     int method_mask;
278     /** The complete string from the command line */
279     char *requirement;
280 };
281      
282 /**
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)
287  */
288 AP_DECLARE(const char *) ap_auth_type(request_rec *r);
289
290 /**
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)
295  */
296 AP_DECLARE(const char *) ap_auth_name(request_rec *r);     
297
298 /**
299  * How the requires lines must be met.
300  * @param r The current request
301  * @return How the requirements must be met.  One of:
302  * <PRE>
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
306  * </PRE>
307  * @deffunc int ap_satisfies(request_rec *r)
308  */
309 AP_DECLARE(int) ap_satisfies(request_rec *r);
310
311 /**
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)
316  */
317 AP_DECLARE(const apr_array_header_t *) ap_requires(request_rec *r);    
318
319 #if defined(WIN32)
320 /* 
321  * CGI Script stuff for Win32...
322  */
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 *, 
329                                                  char **interpreter,
330                                                  char **arguments);
331 #endif
332
333 #ifdef CORE_PRIVATE
334
335 /*
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.
339  */
340
341 AP_DECLARE_DATA extern module core_module;
342
343 /* Per-request configuration */
344
345 typedef struct {
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;
350
351 /* Per-directory configuration */
352
353 typedef unsigned char allow_options_t;
354 typedef unsigned char overrides_t;
355
356 typedef enum {
357     srv_sig_unset,
358     srv_sig_off,
359     srv_sig_on,
360     srv_sig_withmail
361 } server_signature_e;
362
363 typedef struct {
364     /* path of the directory/regex/etc.  see also d_is_fnmatch below */
365     char *d;
366     /* the number of slashes in d */
367     unsigned d_components;
368
369     /* If (opts & OPT_UNSET) then no absolute assignment to options has
370      * been made.
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
374      * or opts_remove.
375      */
376     allow_options_t opts;
377     allow_options_t opts_add;
378     allow_options_t opts_remove;
379     overrides_t override;
380     
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...
384      */
385     
386     char *ap_default_type;
387   
388     /* Authentication stuff.  Groan... */
389     
390     int satisfy;
391     char *ap_auth_type;
392     char *ap_auth_name;
393     apr_array_header_t *ap_requires;
394
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().
399      */
400   
401     char **response_code_strings;
402
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;
409
410     signed int do_rfc1413 : 2;   /* See if client is advertising a username? */
411
412     signed int content_md5 : 2;  /* calculate Content-MD5? */
413
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;
419
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.
423      */
424     unsigned d_is_fnmatch : 1;
425
426     /* should we force a charset on any outgoing parameterless content-type?
427      * if so, which charset?
428      */
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;
434
435     /* System Resource Control */
436 #ifdef RLIMIT_CPU
437     struct rlimit *limit_cpu;
438 #endif
439 #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM) || defined(RLIMIT_AS)
440     struct rlimit *limit_mem;
441 #endif
442 #ifdef RLIMIT_NPROC
443     struct rlimit *limit_nproc;
444 #endif
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 */
447
448     /* logging options */
449
450     server_signature_e server_signature;
451
452     int loglevel;
453     
454     /* Access control */
455     apr_array_header_t *sec;
456     regex_t *r;
457
458 #ifdef WIN32
459     /* Where to find interpreter to run scripts */
460     interpreter_source_e script_interpreter_source;
461 #endif    
462
463     apr_array_header_t *output_filters;
464     apr_array_header_t *input_filters;
465 } core_dir_config;
466
467 /* Per-server core configuration */
468
469 typedef struct {
470   
471 #ifdef GPROF
472     char *gprof_dir;
473 #endif
474
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:
478      */
479     const char *ap_document_root;
480   
481     /* Access control */
482
483     char *access_name;
484     apr_array_header_t *sec;
485     apr_array_header_t *sec_url;
486 } core_server_config;
487
488 /* for http_config.c */
489 void ap_core_reorder_directories(apr_pool_t *, server_rec *);
490
491 /* for mod_perl */
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);
496
497 #endif
498
499 #ifdef __cplusplus
500 }
501 #endif
502
503 #endif  /* !APACHE_HTTP_CORE_H */