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 command_struct {
100 const char *name; /* Name of this command */
101 const char *(*func) (); /* Function invoked */
102 void *cmd_data; /* Extra data, for functions which
103 * implement multiple commands...
105 int req_override; /* What overrides need to be allowed to
106 * enable this command.
108 enum cmd_how args_how; /* What the command expects as arguments */
110 const char *errmsg; /* 'usage' message, in case of syntax errors */
113 /* The allowed locations for a configuration directive are the union of
114 * those indicated by each set bit in the req_override mask.
116 * (req_override & RSRC_CONF) => *.conf outside <Directory> or <Location>
117 * (req_override & ACCESS_CONF) => *.conf inside <Directory> or <Location>
118 * (req_override & OR_AUTHCFG) => *.conf inside <Directory> or <Location>
119 * and .htaccess when AllowOverride AuthConfig
120 * (req_override & OR_LIMIT) => *.conf inside <Directory> or <Location>
121 * and .htaccess when AllowOverride Limit
122 * (req_override & OR_OPTIONS) => *.conf anywhere
123 * and .htaccess when AllowOverride Options
124 * (req_override & OR_FILEINFO) => *.conf anywhere
125 * and .htaccess when AllowOverride FileInfo
126 * (req_override & OR_INDEXES) => *.conf anywhere
127 * and .htaccess when AllowOverride Indexes
132 #define OR_FILEINFO 4
134 #define OR_INDEXES 16
136 #define ACCESS_CONF 64
137 #define RSRC_CONF 128
138 #define EXEC_ON_READ 256
139 #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG|OR_INDEXES)
141 /* This can be returned by a function if they don't wish to handle
142 * a command. Make it something not likely someone will actually use
146 #define DECLINE_CMD "\a\b"
148 /* Common structure for reading of config files / passwd files etc. */
150 int (*getch) (void *param); /* a getc()-like function */
151 void *(*getstr) (void *buf, size_t bufsiz, void *param); /* a fgets()-like function */
152 int (*close) (void *param); /* a close hander function */
153 void *param; /* the argument passed to getch/getstr/close */
154 const char *name; /* the filename / description */
155 unsigned line_number; /* current line number, starting at 1 */
159 * This structure is passed to a command which is being invoked,
160 * to carry a large variety of miscellaneous data which is all of
161 * use to *somebody*...
165 void *info; /* Argument to command from cmd_table */
166 int override; /* Which allow-override bits are set */
167 int limited; /* Which methods are <Limit>ed */
169 configfile_t *config_file; /* Config file structure. */
170 ap_directive_t *directive; /* the directive specifying this command */
172 ap_pool_t *pool; /* Pool to allocate new storage in */
173 ap_pool_t *temp_pool; /* Pool for scratch memory; persists during
174 * configuration, but wiped before the first
175 * request is served...
177 server_rec *server; /* Server_rec being configured for */
178 char *path; /* If configuring for a directory,
179 * pathname of that directory.
180 * NOPE! That's what it meant previous to the
181 * existance of <Files>, <Location> and regex
182 * matching. Now the only usefulness that can
183 * be derived from this field is whether a command
184 * is being called in a server context (path == NULL)
185 * or being called in a dir context (path != NULL).
187 const command_rec *cmd; /* configuration command */
189 void *context; /* per_dir_config vector passed
190 * to handle_command */
191 const ap_directive_t *err_directive; /* directive with syntax error */
194 /* This structure records the existence of handlers in a module... */
197 const char *content_type; /* MUST be all lower case */
198 int (*handler) (request_rec *);
202 * Module structures. Just about everything is dispatched through
203 * these, directly or indirectly (through the command and handler
207 typedef struct module_struct {
208 int version; /* API version, *not* module version;
209 * check that module is compatible with this
210 * version of the server.
212 int minor_version; /* API minor version. Provides API feature
213 * milestones. Not checked during module init
215 int module_index; /* Index to this modules structures in
220 void *dynamic_load_handle;
222 struct module_struct *next;
224 unsigned long magic; /* Magic Cookie to identify a module structure;
225 * It's mainly important for the DSO facility
228 void (*rewrite_args) (process_rec *process);
229 void *(*create_dir_config) (ap_pool_t *p, char *dir);
230 void *(*merge_dir_config) (ap_pool_t *p, void *base_conf, void *new_conf);
231 void *(*create_server_config) (ap_pool_t *p, server_rec *s);
232 void *(*merge_server_config) (ap_pool_t *p, void *base_conf, void *new_conf);
234 const command_rec *cmds;
235 const handler_rec *handlers;
237 /* Hooks for getting into the middle of server ops...
239 * translate_handler --- translate URI to filename
240 * access_checker --- check access by host address, etc. All of these
241 * run; if all decline, that's still OK.
242 * check_user_id --- get and validate user id from the HTTP request
243 * auth_checker --- see if the user (from check_user_id) is OK *here*.
244 * If all of *these* decline, the request is rejected
245 * (as a SERVER_ERROR, since the module which was
246 * supposed to handle this was configured wrong).
247 * type_checker --- Determine MIME type of the requested entity;
248 * sets content_type, _encoding and _language fields.
251 void (*register_hooks) (void);
254 /* Initializer for the first few module slots, which are only
255 * really set up once we start running. Note that the first two slots
256 * provide a version check; this should allow us to deal with changes to
257 * the API. The major number should reflect changes to the API handler table
258 * itself or removal of functionality. The minor number should reflect
259 * additions of functionality to the existing API. (the server can detect
260 * an old-format module, and either handle it back-compatibly, or at least
261 * signal an error). See src/include/ap_mmn.h for MMN version history.
264 #define STANDARD_MODULE_STUFF this_module_needs_to_be_ported_to_apache_2_0
266 #define STANDARD20_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \
267 MODULE_MAGIC_NUMBER_MINOR, \
272 MODULE_MAGIC_COOKIE, \
273 NULL /* rewrite args spot */
275 #define MPM20_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \
276 MODULE_MAGIC_NUMBER_MINOR, \
283 /* Generic accessors for other modules to get at their own module-specific
287 API_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m);
288 API_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val);
290 #define ap_get_module_config(v,m) \
291 (((void **)(v))[(m)->module_index])
292 #define ap_set_module_config(v,m,val) \
293 ((((void **)(v))[(m)->module_index]) = (val))
295 /* Generic command handling function... */
297 API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, char *, char *);
298 API_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *, char *, char *);
299 API_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *, char *, int);
300 API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *, char *, char *);
302 /* For modules which need to read config files, open logs, etc. ...
303 * this returns the fname argument if it begins with '/'; otherwise
304 * it relativizes it wrt server_root.
307 API_EXPORT(const char *) ap_server_root_relative(ap_pool_t *p, const char *fname);
309 /* Finally, the hook for dynamically loading modules in... */
311 API_EXPORT(void) ap_add_module(module *m);
312 API_EXPORT(void) ap_remove_module(module *m);
313 API_EXPORT(void) ap_add_loaded_module(module *mod);
314 API_EXPORT(void) ap_remove_loaded_module(module *mod);
315 API_EXPORT(int) ap_add_named_module(const char *name);
316 API_EXPORT(void) ap_clear_module_list(void);
317 API_EXPORT(const char *) ap_find_module_name(module *m);
318 API_EXPORT(module *) ap_find_linked_module(const char *name);
320 /* Open a configfile_t as FILE, return open configfile_t struct pointer */
321 API_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **, ap_pool_t *p, const char *name);
323 /* Allocate a configfile_t handle with user defined functions and params */
324 API_EXPORT(configfile_t *) ap_pcfg_open_custom(ap_pool_t *p, const char *descr,
326 int(*getc_func)(void*),
327 void *(*gets_func) (void *buf, size_t bufsiz, void *param),
328 int(*close_func)(void *param));
330 /* Read one line from open configfile_t, strip LF, increase line number */
331 API_EXPORT(int) ap_cfg_getline(char *buf, size_t bufsize, configfile_t *cfp);
333 /* Read one char from open configfile_t, increase line number upon LF */
334 API_EXPORT(int) ap_cfg_getc(configfile_t *cfp);
336 /* Detach from open configfile_t, calling the close handler */
337 API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp);
339 /* for implementing subconfigs and customized config files */
340 API_EXPORT(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive);
341 const char * ap_build_cont_config(ap_pool_t *p, ap_pool_t *temp_pool,
343 ap_directive_t **current,
344 ap_directive_t **curr_parent,
345 char *orig_directive);
346 API_EXPORT(const char *) ap_build_config(cmd_parms *parms,
347 ap_pool_t *conf_pool,
348 ap_pool_t *temp_pool,
349 ap_directive_t **conftree);
350 API_EXPORT(const char *) ap_walk_config(ap_directive_t *conftree,
351 cmd_parms *parms, void *config);
353 /* ap_check_cmd_context() definitions: */
354 API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden);
356 /* ap_check_cmd_context(): Forbidden in: */
357 #define NOT_IN_VIRTUALHOST 0x01 /* <Virtualhost> */
358 #define NOT_IN_LIMIT 0x02 /* <Limit> */
359 #define NOT_IN_DIRECTORY 0x04 /* <Directory> */
360 #define NOT_IN_LOCATION 0x08 /* <Location> */
361 #define NOT_IN_FILES 0x10 /* <Files> */
362 #define NOT_IN_DIR_LOC_FILE (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES) /* <Directory>/<Location>/<Files>*/
363 #define GLOBAL_ONLY (NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE)
368 extern API_VAR_EXPORT module *top_module;
370 extern API_VAR_EXPORT module *ap_prelinked_modules[];
371 extern API_VAR_EXPORT module *ap_preloaded_modules[];
372 extern API_VAR_EXPORT module **ap_loaded_modules;
374 /* For mod_so.c... */
376 void ap_single_module_configure(ap_pool_t *p, server_rec *s, module *m);
378 /* For http_main.c... */
380 API_EXPORT(void) ap_setup_prelinked_modules(process_rec *process);
381 API_EXPORT(void) ap_show_directives(void);
382 API_EXPORT(void) ap_show_modules(void);
383 API_EXPORT(server_rec*) ap_read_config(process_rec *process, ap_pool_t *temp_pool, const char *config_name);
384 API_EXPORT(void) ap_pre_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s);
385 API_EXPORT(void) ap_post_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s);
386 API_EXPORT(void) ap_run_rewrite_args(process_rec *process);
387 API_EXPORT(void) ap_register_hooks(module *m);
389 /* For http_request.c... */
391 void *ap_create_request_config(ap_pool_t *p);
392 CORE_EXPORT(void *) ap_create_per_dir_config(ap_pool_t *p);
393 void *ap_merge_per_dir_configs(ap_pool_t *p, void *base, void *new);
395 /* For http_connection.c... */
397 void *ap_create_conn_config(ap_pool_t *p);
399 /* For http_core.c... (<Directory> command and virtual hosts) */
401 int ap_parse_htaccess(void **result, request_rec *r, int override,
402 const char *path, const char *access_name);
404 CORE_EXPORT(const char *) ap_init_virtual_host(ap_pool_t *p, const char *hostname,
405 server_rec *main_server, server_rec **);
406 void ap_process_resource_config(server_rec *s, const char *fname, ap_pool_t *p, ap_pool_t *ptemp);
408 /* For individual MPMs... */
410 void ap_child_init_hook(ap_pool_t *pchild, server_rec *s);
412 /* Module-method dispatchers, also for http_request.c */
414 int ap_translate_name(request_rec *);
415 int ap_check_user_id(request_rec *); /* obtain valid username from client auth */
416 int ap_invoke_handler(request_rec *);
420 CORE_EXPORT(const command_rec *) ap_find_command(const char *name, const command_rec *cmds);
421 CORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod);
422 CORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod);
423 CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l);
428 AP_DECLARE_HOOK(int,header_parser,(request_rec *))
429 AP_DECLARE_HOOK(void,pre_config,
430 (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp))
431 AP_DECLARE_HOOK(void,post_config,
432 (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp,server_rec *s))
433 AP_DECLARE_HOOK(void,open_logs,
434 (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp,server_rec *s))
435 AP_DECLARE_HOOK(void,child_init,(ap_pool_t *pchild, server_rec *s))
441 #endif /* !APACHE_HTTP_CONFIG_H */