1 /* $OpenBSD: http_config.h,v 1.12 2005/03/28 23:26:51 niallo 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_CONFIG_H 62 #define APACHE_HTTP_CONFIG_H 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 /* 69 * The central data structures around here... 70 */ 71 72 /* Command dispatch structures... */ 73 74 /* Note that for all of these except RAW_ARGS, the config routine is 75 * passed a freshly allocated string which can be modified or stored 76 * or whatever... it's only necessary to do pstrdup() stuff with 77 * RAW_ARGS. 78 */ 79 enum cmd_how { 80 RAW_ARGS, /* cmd_func parses command line itself */ 81 TAKE1, /* one argument only */ 82 TAKE2, /* two arguments only */ 83 ITERATE, /* one argument, occuring multiple times 84 * (e.g., IndexIgnore) 85 */ 86 ITERATE2, /* two arguments, 2nd occurs multiple times 87 * (e.g., AddIcon) 88 */ 89 FLAG, /* One of 'On' or 'Off' */ 90 NO_ARGS, /* No args at all, e.g. </Directory> */ 91 TAKE12, /* one or two arguments */ 92 TAKE3, /* three arguments only */ 93 TAKE23, /* two or three arguments */ 94 TAKE123, /* one, two or three arguments */ 95 TAKE13 /* one or three arguments */ 96 }; 97 98 typedef struct command_struct { 99 const char *name; /* Name of this command */ 100 const char *(*func) (); /* Function invoked */ 101 void *cmd_data; /* Extra data, for functions which 102 * implement multiple commands... 103 */ 104 int req_override; /* What overrides need to be allowed to 105 * enable this command. 106 */ 107 enum cmd_how args_how; /* What the command expects as arguments */ 108 109 const char *errmsg; /* 'usage' message, in case of syntax errors */ 110 } command_rec; 111 112 /* The allowed locations for a configuration directive are the union of 113 * those indicated by each set bit in the req_override mask. 114 * 115 * (req_override & RSRC_CONF) => *.conf outside <Directory> or <Location> 116 * (req_override & ACCESS_CONF) => *.conf inside <Directory> or <Location> 117 * (req_override & OR_AUTHCFG) => *.conf inside <Directory> or <Location> 118 * and .htaccess when AllowOverride AuthConfig 119 * (req_override & OR_LIMIT) => *.conf inside <Directory> or <Location> 120 * and .htaccess when AllowOverride Limit 121 * (req_override & OR_OPTIONS) => *.conf anywhere 122 * and .htaccess when AllowOverride Options 123 * (req_override & OR_FILEINFO) => *.conf anywhere 124 * and .htaccess when AllowOverride FileInfo 125 * (req_override & OR_INDEXES) => *.conf anywhere 126 * and .htaccess when AllowOverride Indexes 127 */ 128 #define OR_NONE 0 129 #define OR_LIMIT 1 130 #define OR_OPTIONS 2 131 #define OR_FILEINFO 4 132 #define OR_AUTHCFG 8 133 #define OR_INDEXES 16 134 #define OR_UNSET 32 135 #define ACCESS_CONF 64 136 #define RSRC_CONF 128 137 #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG|OR_INDEXES) 138 139 /* This can be returned by a function if they don't wish to handle 140 * a command. Make it something not likely someone will actually use 141 * as an error code. 142 */ 143 144 #define DECLINE_CMD "\a\b" 145 146 /* 147 * This structure is passed to a command which is being invoked, 148 * to carry a large variety of miscellaneous data which is all of 149 * use to *somebody*... 150 */ 151 152 typedef struct { 153 void *info; /* Argument to command from cmd_table */ 154 int override; /* Which allow-override bits are set */ 155 int limited; /* Which methods are <Limit>ed */ 156 157 /* Config file structure from pcfg_openfile() */ 158 configfile_t *config_file; 159 160 ap_pool *pool; /* Pool to allocate new storage in */ 161 struct pool *temp_pool; /* Pool for scratch memory; persists during 162 * configuration, but wiped before the first 163 * request is served... 164 */ 165 server_rec *server; /* Server_rec being configured for */ 166 char *path; /* If configuring for a directory, 167 * pathname of that directory. 168 * NOPE! That's what it meant previous to the 169 * existance of <Files>, <Location> and regex 170 * matching. Now the only usefulness that can 171 * be derived from this field is whether a command 172 * is being called in a server context (path == NULL) 173 * or being called in a dir context (path != NULL). 174 */ 175 const command_rec *cmd; /* configuration command */ 176 const char *end_token; /* end token required to end a nested section */ 177 void *context; /* per_dir_config vector passed 178 * to handle_command */ 179 } cmd_parms; 180 181 /* This structure records the existence of handlers in a module... */ 182 183 typedef struct { 184 const char *content_type; /* MUST be all lower case */ 185 int (*handler) (request_rec *); 186 } handler_rec; 187 188 /* 189 * Module structures. Just about everything is dispatched through 190 * these, directly or indirectly (through the command and handler 191 * tables). 192 */ 193 194 typedef struct module_struct { 195 int version; /* API version, *not* module version; 196 * check that module is compatible with this 197 * version of the server. 198 */ 199 int minor_version; /* API minor version. Provides API feature 200 * milestones. Not checked during module init 201 */ 202 int module_index; /* Index to this modules structures in 203 * config vectors. 204 */ 205 206 const char *name; 207 void *dynamic_load_handle; 208 209 struct module_struct *next; 210 211 unsigned long magic; /* Magic Cookie to identify a module structure; 212 * It's mainly important for the DSO facility 213 * (see also mod_so). 214 */ 215 216 /* init() occurs after config parsing, but before any children are 217 * forked. 218 * Modules should not rely on the order in which create_server_config 219 * and create_dir_config are called. 220 */ 221 void (*init) (server_rec *, pool *); 222 void *(*create_dir_config) (pool *p, char *dir); 223 void *(*merge_dir_config) (pool *p, void *base_conf, void *new_conf); 224 void *(*create_server_config) (pool *p, server_rec *s); 225 void *(*merge_server_config) (pool *p, void *base_conf, void *new_conf); 226 227 const command_rec *cmds; 228 const handler_rec *handlers; 229 230 /* Hooks for getting into the middle of server ops... 231 232 * translate_handler --- translate URI to filename 233 * access_checker --- check access by host address, etc. All of these 234 * run; if all decline, that's still OK. 235 * check_user_id --- get and validate user id from the HTTP request 236 * auth_checker --- see if the user (from check_user_id) is OK *here*. 237 * If all of *these* decline, the request is rejected 238 * (as a SERVER_ERROR, since the module which was 239 * supposed to handle this was configured wrong). 240 * type_checker --- Determine MIME type of the requested entity; 241 * sets content_type, _encoding and _language fields. 242 * logger --- log a transaction. 243 * post_read_request --- run right after read_request or 244 * internal_redirect, and not run during any subrequests. 245 */ 246 247 int (*translate_handler) (request_rec *); 248 int (*ap_check_user_id) (request_rec *); 249 int (*auth_checker) (request_rec *); 250 int (*access_checker) (request_rec *); 251 int (*type_checker) (request_rec *); 252 int (*fixer_upper) (request_rec *); 253 int (*logger) (request_rec *); 254 int (*header_parser) (request_rec *); 255 256 /* Regardless of the model the server uses for managing "units of 257 * execution", i.e. multi-process, multi-threaded, hybrids of those, 258 * there is the concept of a "heavy weight process". That is, a 259 * process with its own memory space, file spaces, etc. This method, 260 * child_init, is called once for each heavy-weight process before 261 * any requests are served. Note that no provision is made yet for 262 * initialization per light-weight process (i.e. thread). The 263 * parameters passed here are the same as those passed to the global 264 * init method above. 265 */ 266 void (*child_init) (server_rec *, pool *); 267 void (*child_exit) (server_rec *, pool *); 268 int (*post_read_request) (request_rec *); 269 270 /* 271 * ANSI C guarantees us that we can at least extend the module structure 272 * with additional hooks without the need to change all existing modules. 273 * Because: ``If there are fewer initializers in the list than members of 274 * the structure, the trailing members are initialized with 0.'' (The C 275 * Programming Language, 2nd Ed., A8.7 Initialization). So we just 276 * have to put our additional hooks here: 277 * 278 * add_module: 279 * Called from within ap_add_module() right after the module 280 * structure was linked into the Apache internal module list. 281 * It is mainly intended to be used to define configuration defines 282 * (<IfDefine>) which have to be available directly after a 283 * LoadModule/AddModule. Actually this is the earliest possible 284 * hook a module can use. 285 * 286 * remove_module: 287 * Called from within ap_remove_module() right before the module 288 * structure is kicked out from the Apache internal module list. 289 * Actually this is last possible hook a module can use and exists 290 * for consistency with the add_module hook. 291 * 292 * rewrite_command: 293 * Called right after a configuration directive line was read and 294 * before it is processed. It is mainly intended to be used for 295 * rewriting directives in order to provide backward compatibility to 296 * old directive variants. 297 * 298 * new_connection: 299 * Called from within the internal new_connection() function, right 300 * after the conn_rec structure for the new established connection 301 * was created and before Apache starts processing the request with 302 * ap_read_request(). It is mainly intended to be used to setup/run 303 * connection dependent things like sending start headers for 304 * on-the-fly compression, etc. 305 * 306 * close_connection: 307 * Called from within the Apache dispatching loop just before any 308 * ap_bclose() is performed on the socket connection, but a long time 309 * before any pool cleanups are done for the connection (which can be 310 * too late for some applications). It is mainly intended to be used 311 * to close/finalize connection dependent things like sending end 312 * headers for on-the-fly compression, etc. 313 */ 314 void (*add_module) (struct module_struct *); 315 void (*remove_module) (struct module_struct *); 316 char *(*rewrite_command) (cmd_parms *, void *config, const char *); 317 void (*new_connection) (conn_rec *); 318 void (*close_connection) (conn_rec *); 319 } module; 320 321 /* Initializer for the first few module slots, which are only 322 * really set up once we start running. Note that the first two slots 323 * provide a version check; this should allow us to deal with changes to 324 * the API. The major number should reflect changes to the API handler table 325 * itself or removal of functionality. The minor number should reflect 326 * additions of functionality to the existing API. (the server can detect 327 * an old-format module, and either handle it back-compatibly, or at least 328 * signal an error). See src/include/ap_mmn.h for MMN version history. 329 */ 330 331 #define STANDARD_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \ 332 MODULE_MAGIC_NUMBER_MINOR, \ 333 -1, \ 334 __FILE__, \ 335 NULL, \ 336 NULL, \ 337 MODULE_MAGIC_COOKIE 338 339 /* Generic accessors for other modules to get at their own module-specific 340 * data 341 */ 342 343 API_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m); 344 API_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val); 345 346 #define ap_get_module_config(v,m) \ 347 (((void **)(v))[(m)->module_index]) 348 #define ap_set_module_config(v,m,val) \ 349 ((((void **)(v))[(m)->module_index]) = (val)) 350 351 /* Generic command handling function... */ 352 353 API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, char *, char *); 354 API_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *, char *, 355 char *); 356 API_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *, char *, int); 357 API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *, char *, char *); 358 359 /* For modules which need to read config files, open logs, etc. ... 360 * this returns the fname argument if it begins with '/'; otherwise 361 * it relativizes it wrt server_root. 362 */ 363 364 API_EXPORT(char *) ap_server_root_relative(pool *p, char *fname); 365 366 /* Finally, the hook for dynamically loading modules in... */ 367 368 API_EXPORT(void) ap_add_module(module *m); 369 API_EXPORT(void) ap_remove_module(module *m); 370 API_EXPORT(void) ap_add_loaded_module(module *mod); 371 API_EXPORT(void) ap_remove_loaded_module(module *mod); 372 API_EXPORT(int) ap_add_named_module(const char *name); 373 API_EXPORT(void) ap_clear_module_list(void); 374 API_EXPORT(const char *) ap_find_module_name(module *m); 375 API_EXPORT(module *) ap_find_linked_module(const char *name); 376 377 /* for implementing subconfigs and customized config files */ 378 API_EXPORT(const char *) ap_srm_command_loop(cmd_parms *parms, void *config); 379 380 #ifdef CORE_PRIVATE 381 382 extern API_VAR_EXPORT module *top_module; 383 384 extern module *ap_prelinked_modules[]; 385 extern module *ap_preloaded_modules[]; 386 extern API_VAR_EXPORT module **ap_loaded_modules; 387 388 /* For mod_so.c... */ 389 390 API_EXPORT(void) ap_single_module_configure(pool *p, server_rec *s, module *m); 391 392 /* For http_main.c... */ 393 394 API_EXPORT(server_rec *) ap_read_config(pool *conf_pool, pool *temp_pool, 395 char *config_name); 396 API_EXPORT(void) ap_init_modules(pool *p, server_rec *s); 397 API_EXPORT(void) ap_child_init_modules(pool *p, server_rec *s); 398 API_EXPORT(void) ap_child_exit_modules(pool *p, server_rec *s); 399 API_EXPORT(void) ap_setup_prelinked_modules(void); 400 API_EXPORT(void) ap_show_directives(void); 401 API_EXPORT(void) ap_show_modules(void); 402 void ap_cleanup_method_ptrs(void); 403 404 /* For http_request.c... */ 405 406 CORE_EXPORT(void *) ap_create_request_config(pool *p); 407 CORE_EXPORT(void *) ap_create_per_dir_config(pool *p); 408 CORE_EXPORT(void *) ap_merge_per_dir_configs(pool *p, void *base, void *new); 409 410 /* For http_core.c... (<Directory> command and virtual hosts) */ 411 412 CORE_EXPORT(int) ap_parse_htaccess(void **result, request_rec *r, int override, 413 const char *path, const char *access_name); 414 415 CORE_EXPORT(const char *) ap_init_virtual_host(pool *p, const char *hostname, 416 server_rec *main_server, server_rec **); 417 CORE_EXPORT(void) ap_process_resource_config(server_rec *s, char *fname, 418 pool *p, pool *ptemp); 419 420 /* ap_check_cmd_context() definitions: */ 421 API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, 422 unsigned forbidden); 423 424 /* ap_check_cmd_context(): Forbidden in: */ 425 #define NOT_IN_VIRTUALHOST 0x01 /* <Virtualhost> */ 426 #define NOT_IN_LIMIT 0x02 /* <Limit> */ 427 #define NOT_IN_DIRECTORY 0x04 /* <Directory> */ 428 #define NOT_IN_LOCATION 0x08 /* <Location> */ 429 #define NOT_IN_FILES 0x10 /* <Files> */ 430 #define NOT_IN_DIR_LOC_FILE (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES) /* <Directory>/<Location>/<Files>*/ 431 #define GLOBAL_ONLY (NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE) 432 433 434 /* Module-method dispatchers, also for http_request.c */ 435 436 API_EXPORT(int) ap_translate_name(request_rec *); 437 /* check access on non-auth basis */ 438 API_EXPORT(int) ap_check_access(request_rec *); 439 /* obtain valid username from client auth */ 440 API_EXPORT(int) ap_check_user_id(request_rec *); 441 /* check (validated) user is authorized here */ 442 API_EXPORT(int) ap_check_auth(request_rec *); 443 /* identify MIME type */ 444 API_EXPORT(int) ap_find_types(request_rec *); 445 /* poke around for other metainfo, etc.... */ 446 API_EXPORT(int) ap_run_fixups(request_rec *); 447 API_EXPORT(int) ap_invoke_handler(request_rec *); 448 API_EXPORT(int) ap_log_transaction(request_rec *r); 449 API_EXPORT(int) ap_header_parse(request_rec *); 450 API_EXPORT(int) ap_run_post_read_request(request_rec *); 451 452 /* for mod_perl */ 453 454 CORE_EXPORT(const command_rec *) ap_find_command(const char *name, 455 const command_rec *cmds); 456 CORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char 457 *cmd_name, module **mod); 458 CORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, 459 module *mod); 460 CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, 461 const char *l); 462 463 #endif 464 465 #ifdef __cplusplus 466 } 467 #endif 468 469 #endif /* !APACHE_HTTP_CONFIG_H */ 470