1 /* $MirOS: src/usr.sbin/httpd/src/include/http_core.h,v 1.4 2008/03/19 23:07:19 tg Exp $ */ 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2000-2003 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" must 29 * not be used to endorse or promote products derived from this 30 * software without prior written permission. For written 31 * permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * nor may "Apache" appear in their name, without prior written 35 * permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>. 55 * 56 * Portions of this software are based upon public domain software 57 * originally written at the National Center for Supercomputing Applications, 58 * University of Illinois, Urbana-Champaign. 59 */ 60 61 #ifndef APACHE_HTTP_CORE_H 62 #define APACHE_HTTP_CORE_H 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 /***************************************************************** 69 * 70 * The most basic server code is encapsulated in a single module 71 * known as the core, which is just *barely* functional enough to 72 * serve documents, though not terribly well. 73 * 74 * Largely for NCSA back-compatibility reasons, the core needs to 75 * make pieces of its config structures available to other modules. 76 * The accessors are declared here, along with the interpretation 77 * of one of them (allow_options). 78 */ 79 80 #define OPT_NONE 0 81 #define OPT_INDEXES 1 82 #define OPT_INCLUDES 2 83 #define OPT_SYM_LINKS 4 84 #define OPT_EXECCGI 8 85 #define OPT_UNSET 16 86 #define OPT_INCNOEXEC 32 87 #define OPT_SYM_OWNER 64 88 #define OPT_MULTI 128 89 #define OPT_ALL (OPT_INDEXES|OPT_INCLUDES|OPT_SYM_LINKS|OPT_EXECCGI) 90 91 /* options for get_remote_host() */ 92 /* REMOTE_HOST returns the hostname, or NULL if the hostname 93 * lookup fails. It will force a DNS lookup according to the 94 * HostnameLookups setting. 95 */ 96 #define REMOTE_HOST (0) 97 98 /* REMOTE_NAME returns the hostname, or the dotted quad if the 99 * hostname lookup fails. It will force a DNS lookup according 100 * to the HostnameLookups setting. 101 */ 102 #define REMOTE_NAME (1) 103 104 /* REMOTE_NOLOOKUP is like REMOTE_NAME except that a DNS lookup is 105 * never forced. 106 */ 107 #define REMOTE_NOLOOKUP (2) 108 109 /* REMOTE_DOUBLE_REV will always force a DNS lookup, and also force 110 * a double reverse lookup, regardless of the HostnameLookups 111 * setting. The result is the (double reverse checked) hostname, 112 * or NULL if any of the lookups fail. 113 */ 114 #define REMOTE_DOUBLE_REV (3) 115 116 #define SATISFY_ALL 0 117 #define SATISFY_ANY 1 118 #define SATISFY_NOSPEC 2 119 120 /* default maximum of internal redirects */ 121 # define AP_DEFAULT_MAX_INTERNAL_REDIRECTS 20 122 123 /* default maximum subrequest nesting level */ 124 # define AP_DEFAULT_MAX_SUBREQ_DEPTH 20 125 126 API_EXPORT(int) ap_allow_options (request_rec *); 127 API_EXPORT(int) ap_allow_overrides (request_rec *); 128 API_EXPORT(const char *) ap_default_type (request_rec *); 129 API_EXPORT(const char *) ap_document_root (request_rec *); /* Don't use this! If your request went 130 * through a Userdir, or something like 131 * that, it'll screw you. But it's 132 * back-compatible... 133 */ 134 API_EXPORT(const char *) ap_get_remote_host(conn_rec *conn, void *dir_config, int type); 135 API_EXPORT(const char *) ap_get_remote_logname(request_rec *r); 136 137 /* Used for constructing self-referencing URLs, and things like SERVER_PORT, 138 * and SERVER_NAME. 139 */ 140 API_EXPORT(char *) ap_construct_url(pool *p, const char *uri, request_rec *r); 141 API_EXPORT(const char *) ap_get_server_name(request_rec *r); 142 API_EXPORT(unsigned) ap_get_server_port(const request_rec *r); 143 API_EXPORT(unsigned long) ap_get_limit_req_body(const request_rec *r); 144 API_EXPORT(void) ap_custom_response(request_rec *r, int status, char *string); 145 API_EXPORT(int) ap_exists_config_define(char *name); 146 147 /* Check if the current request is beyond the configured max. number of redirects or subrequests 148 * @param r The current request 149 * @return true (is exceeded) or false 150 */ 151 API_EXPORT(int) ap_is_recursion_limit_exceeded(const request_rec *r); 152 153 /* Authentication stuff. This is one of the places where compatibility 154 * with the old config files *really* hurts; they don't discriminate at 155 * all between different authentication schemes, meaning that we need 156 * to maintain common state for all of them in the core, and make it 157 * available to the other modules through interfaces. 158 */ 159 160 typedef struct { 161 int method_mask; 162 char *requirement; 163 } require_line; 164 165 API_EXPORT(const char *) ap_auth_type (request_rec *); 166 API_EXPORT(const char *) ap_auth_name (request_rec *); 167 API_EXPORT(const char *) ap_auth_nonce (request_rec *); 168 API_EXPORT(int) ap_satisfies (request_rec *r); 169 API_EXPORT(const array_header *) ap_requires (request_rec *); 170 171 #ifdef CORE_PRIVATE 172 173 /* 174 * Core is also unlike other modules in being implemented in more than 175 * one file... so, data structures are declared here, even though most of 176 * the code that cares really is in http_core.c. Also, another accessor. 177 */ 178 179 API_EXPORT(char *) ap_response_code_string (request_rec *r, int error_index); 180 181 extern API_VAR_EXPORT module core_module; 182 183 /* Per-directory configuration */ 184 185 typedef unsigned char allow_options_t; 186 typedef unsigned char overrides_t; 187 /* 188 * Bits of info that go into making an ETag for a file 189 * document. Why a long? Because char historically 190 * proved too short for Options, and int can be different 191 * sizes on different platforms. 192 */ 193 typedef unsigned long etag_components_t; 194 195 #define ETAG_UNSET 0 196 #define ETAG_NONE (1 << 0) 197 #define ETAG_MTIME (1 << 1) 198 #define ETAG_INODE (1 << 2) 199 #define ETAG_SIZE (1 << 3) 200 #define ETAG_BACKWARD (ETAG_MTIME | ETAG_INODE | ETAG_SIZE) 201 #define ETAG_ALL (ETAG_MTIME | ETAG_INODE | ETAG_SIZE) 202 203 typedef enum { 204 AP_FLAG_UNSET = 0, 205 AP_FLAG_ON = 1, 206 AP_FLAG_OFF = 2 207 } ap_flag_e; 208 209 typedef struct { 210 /* path of the directory/regex/etc. see also d_is_fnmatch below */ 211 char *d; 212 /* the number of slashes in d */ 213 unsigned d_components; 214 215 /* If (opts & OPT_UNSET) then no absolute assignment to options has 216 * been made. 217 * invariant: (opts_add & opts_remove) == 0 218 * Which said another way means that the last relative (options + or -) 219 * assignment made to each bit is recorded in exactly one of opts_add 220 * or opts_remove. 221 */ 222 allow_options_t opts; 223 allow_options_t opts_add; 224 allow_options_t opts_remove; 225 overrides_t override; 226 227 /* MIME typing --- the core doesn't do anything at all with this, 228 * but it does know what to slap on a request for a document which 229 * goes untyped by other mechanisms before it slips out the door... 230 */ 231 232 char *ap_default_type; 233 234 /* Authentication stuff. Groan... */ 235 236 int satisfy; 237 char *ap_auth_type; 238 char *ap_auth_name; 239 array_header *ap_requires; 240 241 /* Custom response config. These can contain text or a URL to redirect to. 242 * if response_code_strings is NULL then there are none in the config, 243 * if it's not null then it's allocated to sizeof(char*)*RESPONSE_CODES. 244 * This lets us do quick merges in merge_core_dir_configs(). 245 */ 246 247 char **response_code_strings; /* from ErrorDocument, not from 248 * ap_custom_response() 249 */ 250 251 /* Hostname resolution etc */ 252 #define HOSTNAME_LOOKUP_OFF 0 253 #define HOSTNAME_LOOKUP_ON 1 254 #define HOSTNAME_LOOKUP_DOUBLE 2 255 #define HOSTNAME_LOOKUP_UNSET 3 256 unsigned int hostname_lookups : 4; 257 258 signed int do_rfc1413 : 2; /* See if client is advertising a username? */ 259 260 signed int content_md5 : 2; /* calculate Content-MD5? */ 261 262 #define USE_CANONICAL_NAME_OFF (0) 263 #define USE_CANONICAL_NAME_ON (1) 264 #define USE_CANONICAL_NAME_DNS (2) 265 #define USE_CANONICAL_NAME_UNSET (3) 266 unsigned use_canonical_name : 2; 267 268 /* since is_fnmatch(conf->d) was being called so frequently in 269 * directory_walk() and its relatives, this field was created and 270 * is set to the result of that call. 271 */ 272 unsigned d_is_fnmatch : 1; 273 274 /* should we force a charset on any outgoing parameterless content-type? 275 * if so, which charset? 276 */ 277 #define ADD_DEFAULT_CHARSET_OFF (0) 278 #define ADD_DEFAULT_CHARSET_ON (1) 279 #define ADD_DEFAULT_CHARSET_UNSET (2) 280 unsigned add_default_charset : 2; 281 char *add_default_charset_name; 282 283 /* System Resource Control */ 284 struct rlimit *limit_cpu; 285 #ifdef RLIMIT_TIME 286 struct rlimit *limit_time; 287 #endif 288 struct rlimit *limit_mem; 289 struct rlimit *limit_nproc; 290 struct rlimit *limit_nofile; 291 unsigned long limit_req_body; /* limit on bytes in request msg body */ 292 293 /* logging options */ 294 enum { srv_sig_unset, srv_sig_off, srv_sig_on, 295 srv_sig_withmail } server_signature; 296 int loglevel; 297 298 /* Access control */ 299 array_header *sec; 300 regex_t *r; 301 302 303 /* 304 * What attributes/data should be included in ETag generation? 305 */ 306 etag_components_t etag_bits; 307 etag_components_t etag_add; 308 etag_components_t etag_remove; 309 310 /* 311 * Do we allow ISINDEX CGI scripts to pass their query argument as 312 * direct command line parameters or argv elements? 313 */ 314 ap_flag_e cgi_command_args; 315 316 /* Digest auth. */ 317 char *ap_auth_nonce; 318 319 } core_dir_config; 320 321 /* Per-server core configuration */ 322 323 typedef struct { 324 325 /* Name translations --- we want the core to be able to do *something* 326 * so it's at least a minimally functional web server on its own (and 327 * can be tested that way). But let's keep it to the bare minimum: 328 */ 329 char *ap_document_root; 330 331 /* Access control */ 332 333 char *access_name; 334 array_header *sec; 335 array_header *sec_url; 336 337 /* recursion backstopper */ 338 int recursion_limit_set; /* boolean */ 339 int redirect_limit; /* maximum number of internal redirects */ 340 int subreq_limit; /* maximum nesting level of subrequests */ 341 } core_server_config; 342 343 /* for http_config.c */ 344 CORE_EXPORT(void) ap_core_reorder_directories(pool *, server_rec *); 345 346 /* for mod_perl */ 347 CORE_EXPORT(void) ap_add_per_dir_conf (server_rec *s, void *dir_config); 348 CORE_EXPORT(void) ap_add_per_url_conf (server_rec *s, void *url_config); 349 CORE_EXPORT(void) ap_add_file_conf(core_dir_config *conf, void *url_config); 350 CORE_EXPORT_NONSTD(const char *) ap_limit_section (cmd_parms *cmd, void *dummy, const char *arg); 351 352 #endif 353 354 #ifdef __cplusplus 355 } 356 #endif 357 358 #endif /* !APACHE_HTTP_CORE_H */ 359