1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000 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_CONFIG_H
60 #define APACHE_HTTP_CONFIG_H
63 #include "util_cfgtree.h"
70 * The central data structures around here...
73 /* Command dispatch structures... */
75 /* Note that for all of these except RAW_ARGS, the config routine is
76 * passed a freshly allocated string which can be modified or stored
77 * or whatever... it's only necessary to do pstrdup() stuff with
81 RAW_ARGS, /* cmd_func parses command line itself */
82 TAKE1, /* one argument only */
83 TAKE2, /* two arguments only */
84 ITERATE, /* one argument, occuring multiple times
87 ITERATE2, /* two arguments, 2nd occurs multiple times
90 FLAG, /* One of 'On' or 'Off' */
91 NO_ARGS, /* No args at all, e.g. </Directory> */
92 TAKE12, /* one or two arguments */
93 TAKE3, /* three arguments only */
94 TAKE23, /* two or three arguments */
95 TAKE123, /* one, two or three arguments */
96 TAKE13 /* one or three arguments */
99 typedef struct cmd_parms_struct cmd_parms;
104 const char *(*no_args) (cmd_parms *parms, void *mconfig);
105 const char *(*raw_args) (cmd_parms *parms, void *mconfig,
107 const char *(*take1) (cmd_parms *parms, void *mconfig, const char *w);
108 const char *(*take2) (cmd_parms *parms, void *mconfig, const char *w,
110 const char *(*take3) (cmd_parms *parms, void *mconfig, const char *w,
111 const char *w2, const char *w3);
112 const char *(*flag) (cmd_parms *parms, void *mconfig, int on);
115 # define AP_NO_ARGS func.no_args
116 # define AP_RAW_ARGS func.raw_args
117 # define AP_TAKE1 func.take1
118 # define AP_TAKE2 func.take2
119 # define AP_TAKE3 func.take3
120 # define AP_FLAG func.flag
122 # define AP_INIT_NO_ARGS(directive, func, mconfig, where, help) \
123 { directive, { .no_args=func }, mconfig, where, RAW_ARGS, help }
124 # define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \
125 { directive, { .raw_args=func }, mconfig, where, RAW_ARGS, help }
126 # define AP_INIT_TAKE1(directive, func, mconfig, where, help) \
127 { directive, { .take1=func }, mconfig, where, TAKE1, help }
128 # define AP_INIT_ITERATE(directive, func, mconfig, where, help) \
129 { directive, { .take1=func }, mconfig, where, ITERATE, help }
130 # define AP_INIT_TAKE2(directive, func, mconfig, where, help) \
131 { directive, { .take2=func }, mconfig, where, TAKE2, help }
132 # define AP_INIT_TAKE12(directive, func, mconfig, where, help) \
133 { directive, { .take2=func }, mconfig, where, TAKE12, help }
134 # define AP_INIT_ITERATE2(directive, func, mconfig, where, help) \
135 { directive, { .take2=func }, mconfig, where, ITERATE2, help }
136 # define AP_INIT_TAKE23(directive, func, mconfig, where, help) \
137 { directive, { .take3=func }, mconfig, where, TAKE23, help }
138 # define AP_INIT_FLAG(directive, func, mconfig, where, help) \
139 { directive, { .flag=func }, mconfig, where, FLAG, help }
143 typedef const char *(*cmd_func) ();
145 # define AP_NO_ARGS func
146 # define AP_RAW_ARGS func
147 # define AP_TAKE1 func
148 # define AP_TAKE2 func
149 # define AP_TAKE3 func
150 # define AP_FLAG func
152 # define AP_INIT_NO_ARGS(directive, func, mconfig, where, help) \
153 { directive, func, mconfig, where, RAW_ARGS, help }
154 # define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \
155 { directive, func, mconfig, where, RAW_ARGS, help }
156 # define AP_INIT_TAKE1(directive, func, mconfig, where, help) \
157 { directive, func, mconfig, where, TAKE1, help }
158 # define AP_INIT_ITERATE(directive, func, mconfig, where, help) \
159 { directive, func, mconfig, where, ITERATE, help }
160 # define AP_INIT_TAKE2(directive, func, mconfig, where, help) \
161 { directive, func, mconfig, where, TAKE2, help }
162 # define AP_INIT_TAKE12(directive, func, mconfig, where, help) \
163 { directive, func, mconfig, where, TAKE12, help }
164 # define AP_INIT_ITERATE2(directive, func, mconfig, where, help) \
165 { directive, func, mconfig, where, ITERATE2, help }
166 # define AP_INIT_TAKE23(directive, func, mconfig, where, help) \
167 { directive, func, mconfig, where, TAKE23, help }
168 # define AP_INIT_FLAG(directive, func, mconfig, where, help) \
169 { directive, func, mconfig, where, FLAG, help }
173 typedef struct command_struct {
174 const char *name; /* Name of this command */
176 void *cmd_data; /* Extra data, for functions which
177 * implement multiple commands...
179 int req_override; /* What overrides need to be allowed to
180 * enable this command.
182 enum cmd_how args_how; /* What the command expects as arguments */
184 const char *errmsg; /* 'usage' message, in case of syntax errors */
187 /* The allowed locations for a configuration directive are the union of
188 * those indicated by each set bit in the req_override mask.
190 * (req_override & RSRC_CONF) => *.conf outside <Directory> or <Location>
191 * (req_override & ACCESS_CONF) => *.conf inside <Directory> or <Location>
192 * (req_override & OR_AUTHCFG) => *.conf inside <Directory> or <Location>
193 * and .htaccess when AllowOverride AuthConfig
194 * (req_override & OR_LIMIT) => *.conf inside <Directory> or <Location>
195 * and .htaccess when AllowOverride Limit
196 * (req_override & OR_OPTIONS) => *.conf anywhere
197 * and .htaccess when AllowOverride Options
198 * (req_override & OR_FILEINFO) => *.conf anywhere
199 * and .htaccess when AllowOverride FileInfo
200 * (req_override & OR_INDEXES) => *.conf anywhere
201 * and .htaccess when AllowOverride Indexes
206 #define OR_FILEINFO 4
208 #define OR_INDEXES 16
210 #define ACCESS_CONF 64
211 #define RSRC_CONF 128
212 #define EXEC_ON_READ 256
213 #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG|OR_INDEXES)
215 /* This can be returned by a function if they don't wish to handle
216 * a command. Make it something not likely someone will actually use
220 #define DECLINE_CMD "\a\b"
222 /* Common structure for reading of config files / passwd files etc. */
224 int (*getch) (void *param); /* a getc()-like function */
225 void *(*getstr) (void *buf, size_t bufsiz, void *param); /* a fgets()-like function */
226 int (*close) (void *param); /* a close hander function */
227 void *param; /* the argument passed to getch/getstr/close */
228 const char *name; /* the filename / description */
229 unsigned line_number; /* current line number, starting at 1 */
233 * This structure is passed to a command which is being invoked,
234 * to carry a large variety of miscellaneous data which is all of
235 * use to *somebody*...
238 struct cmd_parms_struct
240 void *info; /* Argument to command from cmd_table */
241 int override; /* Which allow-override bits are set */
242 int limited; /* Which methods are <Limit>ed */
244 configfile_t *config_file; /* Config file structure. */
245 ap_directive_t *directive; /* the directive specifying this command */
247 ap_pool_t *pool; /* Pool to allocate new storage in */
248 ap_pool_t *temp_pool; /* Pool for scratch memory; persists during
249 * configuration, but wiped before the first
250 * request is served...
252 server_rec *server; /* Server_rec being configured for */
253 char *path; /* If configuring for a directory,
254 * pathname of that directory.
255 * NOPE! That's what it meant previous to the
256 * existance of <Files>, <Location> and regex
257 * matching. Now the only usefulness that can
258 * be derived from this field is whether a command
259 * is being called in a server context (path == NULL)
260 * or being called in a dir context (path != NULL).
262 const command_rec *cmd; /* configuration command */
264 void *context; /* per_dir_config vector passed
265 * to handle_command */
266 const ap_directive_t *err_directive; /* directive with syntax error */
270 /* This structure records the existence of handlers in a module... */
273 const char *content_type; /* MUST be all lower case */
274 int (*handler) (request_rec *);
278 * Module structures. Just about everything is dispatched through
279 * these, directly or indirectly (through the command and handler
283 typedef struct module_struct {
284 int version; /* API version, *not* module version;
285 * check that module is compatible with this
286 * version of the server.
288 int minor_version; /* API minor version. Provides API feature
289 * milestones. Not checked during module init
291 int module_index; /* Index to this modules structures in
296 void *dynamic_load_handle;
298 struct module_struct *next;
300 unsigned long magic; /* Magic Cookie to identify a module structure;
301 * It's mainly important for the DSO facility
304 unsigned int module_type /* What type of module is this? Currently
307 * AP_MODULE_TYPE_STANDARD
308 * AP_MODULE_TYPE_PROTOCOL
310 void (*rewrite_args) (process_rec *process);
311 void *(*create_dir_config) (ap_pool_t *p, char *dir);
312 void *(*merge_dir_config) (ap_pool_t *p, void *base_conf, void *new_conf);
313 void *(*create_server_config) (ap_pool_t *p, server_rec *s);
314 void *(*merge_server_config) (ap_pool_t *p, void *base_conf, void *new_conf);
316 const command_rec *cmds;
317 const handler_rec *handlers;
319 /* Hooks for getting into the middle of server ops...
321 * translate_handler --- translate URI to filename
322 * access_checker --- check access by host address, etc. All of these
323 * run; if all decline, that's still OK.
324 * check_user_id --- get and validate user id from the HTTP request
325 * auth_checker --- see if the user (from check_user_id) is OK *here*.
326 * If all of *these* decline, the request is rejected
327 * (as a HTTP_INTERNAL_SERVER_ERROR, since the module
328 * which was suppsoed to handle this was configured
330 * type_checker --- Determine MIME type of the requested entity;
331 * sets content_type, _encoding and _language fields.
334 void (*register_hooks) (void);
337 /* Initializer for the first few module slots, which are only
338 * really set up once we start running. Note that the first two slots
339 * provide a version check; this should allow us to deal with changes to
340 * the API. The major number should reflect changes to the API handler table
341 * itself or removal of functionality. The minor number should reflect
342 * additions of functionality to the existing API. (the server can detect
343 * an old-format module, and either handle it back-compatibly, or at least
344 * signal an error). See src/include/ap_mmn.h for MMN version history.
347 #define STANDARD_MODULE_STUFF this_module_needs_to_be_ported_to_apache_2_0
349 #define STANDARD20_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \
350 MODULE_MAGIC_NUMBER_MINOR, \
355 MODULE_MAGIC_COOKIE, \
356 NULL /* rewrite args spot */
358 #define MPM20_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \
359 MODULE_MAGIC_NUMBER_MINOR, \
366 /* Generic accessors for other modules to get at their own module-specific
370 API_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m);
371 API_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val);
373 #define ap_get_module_config(v,m) \
374 (((void **)(v))[(m)->module_index])
375 #define ap_set_module_config(v,m,val) \
376 ((((void **)(v))[(m)->module_index]) = (val))
378 /* Generic command handling function... */
380 API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, void *,
382 API_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *,
383 void *, const char *);
384 API_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *, void *, int);
385 API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *, char *, const char *);
387 /* For modules which need to read config files, open logs, etc. ...
388 * this returns the fname argument if it begins with '/'; otherwise
389 * it relativizes it wrt server_root.
392 API_EXPORT(const char *) ap_server_root_relative(ap_pool_t *p, const char *fname);
394 /* Finally, the hook for dynamically loading modules in... */
396 API_EXPORT(void) ap_add_module(module *m);
397 API_EXPORT(void) ap_remove_module(module *m);
398 API_EXPORT(void) ap_add_loaded_module(module *mod);
399 API_EXPORT(void) ap_remove_loaded_module(module *mod);
400 API_EXPORT(int) ap_add_named_module(const char *name);
401 API_EXPORT(void) ap_clear_module_list(void);
402 API_EXPORT(const char *) ap_find_module_name(module *m);
403 API_EXPORT(module *) ap_find_linked_module(const char *name);
405 /* Open a configfile_t as FILE, return open configfile_t struct pointer */
406 API_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **, ap_pool_t *p, const char *name);
408 /* Allocate a configfile_t handle with user defined functions and params */
409 API_EXPORT(configfile_t *) ap_pcfg_open_custom(ap_pool_t *p, const char *descr,
411 int(*getc_func)(void*),
412 void *(*gets_func) (void *buf, size_t bufsiz, void *param),
413 int(*close_func)(void *param));
415 /* Read one line from open configfile_t, strip LF, increase line number */
416 API_EXPORT(int) ap_cfg_getline(char *buf, size_t bufsize, configfile_t *cfp);
418 /* Read one char from open configfile_t, increase line number upon LF */
419 API_EXPORT(int) ap_cfg_getc(configfile_t *cfp);
421 /* Detach from open configfile_t, calling the close handler */
422 API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp);
424 /* for implementing subconfigs and customized config files */
425 API_EXPORT(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive);
426 const char * ap_build_cont_config(ap_pool_t *p, ap_pool_t *temp_pool,
428 ap_directive_t **current,
429 ap_directive_t **curr_parent,
430 char *orig_directive);
431 API_EXPORT(const char *) ap_build_config(cmd_parms *parms,
432 ap_pool_t *conf_pool,
433 ap_pool_t *temp_pool,
434 ap_directive_t **conftree);
435 API_EXPORT(const char *) ap_walk_config(ap_directive_t *conftree,
436 cmd_parms *parms, void *config);
438 /* ap_check_cmd_context() definitions: */
439 API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden);
441 /* ap_check_cmd_context(): Forbidden in: */
442 #define NOT_IN_VIRTUALHOST 0x01 /* <Virtualhost> */
443 #define NOT_IN_LIMIT 0x02 /* <Limit> */
444 #define NOT_IN_DIRECTORY 0x04 /* <Directory> */
445 #define NOT_IN_LOCATION 0x08 /* <Location> */
446 #define NOT_IN_FILES 0x10 /* <Files> */
447 #define NOT_IN_DIR_LOC_FILE (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES) /* <Directory>/<Location>/<Files>*/
448 #define GLOBAL_ONLY (NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE)
453 extern API_VAR_EXPORT module *top_module;
455 extern API_VAR_EXPORT module *ap_prelinked_modules[];
456 extern API_VAR_EXPORT module *ap_preloaded_modules[];
457 extern API_VAR_EXPORT module **ap_loaded_modules;
459 /* For mod_so.c... */
461 void ap_single_module_configure(ap_pool_t *p, server_rec *s, module *m);
463 /* For http_main.c... */
465 API_EXPORT(void) ap_setup_prelinked_modules(process_rec *process);
466 API_EXPORT(void) ap_show_directives(void);
467 API_EXPORT(void) ap_show_modules(void);
468 API_EXPORT(server_rec*) ap_read_config(process_rec *process, ap_pool_t *temp_pool, const char *config_name, ap_directive_t **conftree);
469 API_EXPORT(void) ap_pre_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s);
470 API_EXPORT(void) ap_post_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s);
471 API_EXPORT(void) ap_run_rewrite_args(process_rec *process);
472 API_EXPORT(void) ap_register_hooks(module *m);
473 API_EXPORT(void) ap_fixup_virtual_hosts(ap_pool_t *p, server_rec *main_server);
475 /* For http_request.c... */
477 void *ap_create_request_config(ap_pool_t *p);
478 CORE_EXPORT(void *) ap_create_per_dir_config(ap_pool_t *p);
479 void *ap_merge_per_dir_configs(ap_pool_t *p, void *base, void *new);
481 /* For http_connection.c... */
483 void *ap_create_conn_config(ap_pool_t *p);
485 /* For http_core.c... (<Directory> command and virtual hosts) */
487 int ap_parse_htaccess(void **result, request_rec *r, int override,
488 const char *path, const char *access_name);
490 CORE_EXPORT(const char *) ap_init_virtual_host(ap_pool_t *p, const char *hostname,
491 server_rec *main_server, server_rec **);
492 void ap_process_resource_config(server_rec *s, const char *fname,
493 ap_directive_t **conftree, ap_pool_t *p, ap_pool_t *ptemp);
494 API_EXPORT(void) ap_process_config_tree(server_rec *s, ap_directive_t *conftree,
495 ap_pool_t *p, ap_pool_t *ptemp);
498 /* For individual MPMs... */
500 void ap_child_init_hook(ap_pool_t *pchild, server_rec *s);
502 /* Module-method dispatchers, also for http_request.c */
504 int ap_translate_name(request_rec *);
505 int ap_check_user_id(request_rec *); /* obtain valid username from client auth */
506 int ap_invoke_handler(request_rec *);
510 CORE_EXPORT(const command_rec *) ap_find_command(const char *name, const command_rec *cmds);
511 CORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod);
512 CORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod);
513 CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l);
518 AP_DECLARE_HOOK(int,header_parser,(request_rec *))
519 AP_DECLARE_HOOK(void,pre_config,
520 (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp))
521 AP_DECLARE_HOOK(void,post_config,
522 (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp,server_rec *s))
523 AP_DECLARE_HOOK(void,open_logs,
524 (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp,server_rec *s))
525 AP_DECLARE_HOOK(void,child_init,(ap_pool_t *pchild, server_rec *s))
531 #endif /* !APACHE_HTTP_CONFIG_H */