]> granicus.if.org Git - apache/blob - include/http_config.h
Start to implement module-defined hooks that are a) fast and b) typesafe.
[apache] / include / http_config.h
1 /* ====================================================================
2  * Copyright (c) 1995-1999 The Apache Group.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer. 
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * 3. All advertising materials mentioning features or use of this
17  *    software must display the following acknowledgment:
18  *    "This product includes software developed by the Apache Group
19  *    for use in the Apache HTTP server project (http://www.apache.org/)."
20  *
21  * 4. The names "Apache Server" and "Apache Group" must not be used to
22  *    endorse or promote products derived from this software without
23  *    prior written permission. For written permission, please contact
24  *    apache@apache.org.
25  *
26  * 5. Products derived from this software may not be called "Apache"
27  *    nor may "Apache" appear in their names without prior written
28  *    permission of the Apache Group.
29  *
30  * 6. Redistributions of any form whatsoever must retain the following
31  *    acknowledgment:
32  *    "This product includes software developed by the Apache Group
33  *    for use in the Apache HTTP server project (http://www.apache.org/)."
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
36  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46  * OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Group and was originally based
51  * on public domain software written at the National Center for
52  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
53  * For more information on the Apache Group and the Apache HTTP server
54  * project, please see <http://www.apache.org/>.
55  *
56  */
57
58 #ifndef APACHE_HTTP_CONFIG_H
59 #define APACHE_HTTP_CONFIG_H
60
61 #include "ap_hooks.h"
62
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66
67 /*
68  * The central data structures around here...
69  */
70
71 /* Command dispatch structures... */
72
73 /* Note that for all of these except RAW_ARGS, the config routine is
74  * passed a freshly allocated string which can be modified or stored
75  * or whatever... it's only necessary to do pstrdup() stuff with
76  * RAW_ARGS.
77  */
78 enum cmd_how {
79     RAW_ARGS,                   /* cmd_func parses command line itself */
80     TAKE1,                      /* one argument only */
81     TAKE2,                      /* two arguments only */
82     ITERATE,                    /* one argument, occuring multiple times
83                                  * (e.g., IndexIgnore)
84                                  */
85     ITERATE2,                   /* two arguments, 2nd occurs multiple times
86                                  * (e.g., AddIcon)
87                                  */
88     FLAG,                       /* One of 'On' or 'Off' */
89     NO_ARGS,                    /* No args at all, e.g. </Directory> */
90     TAKE12,                     /* one or two arguments */
91     TAKE3,                      /* three arguments only */
92     TAKE23,                     /* two or three arguments */
93     TAKE123,                    /* one, two or three arguments */
94     TAKE13                      /* one or three arguments */
95 };
96
97 typedef struct command_struct {
98     const char *name;           /* Name of this command */
99     const char *(*func) ();     /* Function invoked */
100     void *cmd_data;             /* Extra data, for functions which
101                                  * implement multiple commands...
102                                  */
103     int req_override;           /* What overrides need to be allowed to
104                                  * enable this command.
105                                  */
106     enum cmd_how args_how;      /* What the command expects as arguments */
107
108     const char *errmsg;         /* 'usage' message, in case of syntax errors */
109 } command_rec;
110
111 /* The allowed locations for a configuration directive are the union of
112  * those indicated by each set bit in the req_override mask.
113  *
114  * (req_override & RSRC_CONF)   => *.conf outside <Directory> or <Location>
115  * (req_override & ACCESS_CONF) => *.conf inside <Directory> or <Location>
116  * (req_override & OR_AUTHCFG)  => *.conf inside <Directory> or <Location>
117  *                                 and .htaccess when AllowOverride AuthConfig
118  * (req_override & OR_LIMIT)    => *.conf inside <Directory> or <Location>
119  *                                 and .htaccess when AllowOverride Limit
120  * (req_override & OR_OPTIONS)  => *.conf anywhere
121  *                                 and .htaccess when AllowOverride Options
122  * (req_override & OR_FILEINFO) => *.conf anywhere
123  *                                 and .htaccess when AllowOverride FileInfo
124  * (req_override & OR_INDEXES)  => *.conf anywhere
125  *                                 and .htaccess when AllowOverride Indexes
126  */
127 #define OR_NONE 0
128 #define OR_LIMIT 1
129 #define OR_OPTIONS 2
130 #define OR_FILEINFO 4
131 #define OR_AUTHCFG 8
132 #define OR_INDEXES 16
133 #define OR_UNSET 32
134 #define ACCESS_CONF 64
135 #define RSRC_CONF 128
136 #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG|OR_INDEXES)
137
138 /* This can be returned by a function if they don't wish to handle
139  * a command. Make it something not likely someone will actually use
140  * as an error code.
141  */
142
143 #define DECLINE_CMD "\a\b"
144
145 /*
146  * This structure is passed to a command which is being invoked,
147  * to carry a large variety of miscellaneous data which is all of
148  * use to *somebody*...
149  */
150
151 typedef struct {
152     void *info;                 /* Argument to command from cmd_table */
153     int override;               /* Which allow-override bits are set */
154     int limited;                /* Which methods are <Limit>ed */
155
156     configfile_t *config_file;  /* Config file structure from pcfg_openfile() */
157
158     ap_pool *pool;                      /* Pool to allocate new storage in */
159     struct pool *temp_pool;             /* Pool for scratch memory; persists during
160                                  * configuration, but wiped before the first
161                                  * request is served...
162                                  */
163     server_rec *server;         /* Server_rec being configured for */
164     char *path;                 /* If configuring for a directory,
165                                  * pathname of that directory.
166                                  * NOPE!  That's what it meant previous to the
167                                  * existance of <Files>, <Location> and regex
168                                  * matching.  Now the only usefulness that can
169                                  * be derived from this field is whether a command
170                                  * is being called in a server context (path == NULL)
171                                  * or being called in a dir context (path != NULL).
172                                  */
173     const command_rec *cmd;     /* configuration command */
174     const char *end_token;      /* end token required to end a nested section */
175     void *context;              /* per_dir_config vector passed 
176                                  * to handle_command */
177 } cmd_parms;
178
179 /* This structure records the existence of handlers in a module... */
180
181 typedef struct {
182     const char *content_type;   /* MUST be all lower case */
183     int (*handler) (request_rec *);
184 } handler_rec;
185
186 /*
187  * Module structures.  Just about everything is dispatched through
188  * these, directly or indirectly (through the command and handler
189  * tables).
190  */
191
192 typedef struct module_struct {
193     int version;                /* API version, *not* module version;
194                                  * check that module is compatible with this
195                                  * version of the server.
196                                  */
197     int minor_version;          /* API minor version. Provides API feature
198                                  * milestones. Not checked during module init
199                                  */
200     int module_index;           /* Index to this modules structures in
201                                  * config vectors.
202                                  */
203
204     const char *name;
205     void *dynamic_load_handle;
206
207     struct module_struct *next;
208
209     unsigned long magic;        /* Magic Cookie to identify a module structure;
210                                  * It's mainly important for the DSO facility
211                                  * (see also mod_so).
212                                  */
213
214     void *(*create_dir_config) (pool *p, char *dir);
215     void *(*merge_dir_config) (pool *p, void *base_conf, void *new_conf);
216     void *(*create_server_config) (pool *p, server_rec *s);
217     void *(*merge_server_config) (pool *p, void *base_conf, void *new_conf);
218
219     const command_rec *cmds;
220     const handler_rec *handlers;
221
222     /* Hooks for getting into the middle of server ops...
223
224      * translate_handler --- translate URI to filename
225      * access_checker --- check access by host address, etc.   All of these
226      *                    run; if all decline, that's still OK.
227      * check_user_id --- get and validate user id from the HTTP request
228      * auth_checker --- see if the user (from check_user_id) is OK *here*.
229      *                  If all of *these* decline, the request is rejected
230      *                  (as a SERVER_ERROR, since the module which was
231      *                  supposed to handle this was configured wrong).
232      * type_checker --- Determine MIME type of the requested entity;
233      *                  sets content_type, _encoding and _language fields.
234      */
235
236     void (*register_hooks) (void);
237 } module;
238
239 /* Initializer for the first few module slots, which are only
240  * really set up once we start running.  Note that the first two slots
241  * provide a version check; this should allow us to deal with changes to
242  * the API. The major number should reflect changes to the API handler table
243  * itself or removal of functionality. The minor number should reflect
244  * additions of functionality to the existing API. (the server can detect
245  * an old-format module, and either handle it back-compatibly, or at least
246  * signal an error). See src/include/ap_mmn.h for MMN version history.
247  */
248
249 #define STANDARD_MODULE_STUFF   this_module_needs_to_be_ported_to_apache_2_0
250
251 #define STANDARD20_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \
252                                 MODULE_MAGIC_NUMBER_MINOR, \
253                                 -1, \
254                                 __FILE__, \
255                                 NULL, \
256                                 NULL, \
257                                 MODULE_MAGIC_COOKIE
258
259 /* Generic accessors for other modules to get at their own module-specific
260  * data
261  */
262
263 API_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m);
264 API_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val);
265
266 #define ap_get_module_config(v,m)       \
267     (((void **)(v))[(m)->module_index])
268 #define ap_set_module_config(v,m,val)   \
269     ((((void **)(v))[(m)->module_index]) = (val))
270
271 /* Generic command handling function... */
272
273 API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, char *, char *);
274 API_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *, char *, char *);
275 API_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *, char *, int);
276 API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *, char *, char *);
277
278 /* For modules which need to read config files, open logs, etc. ...
279  * this returns the fname argument if it begins with '/'; otherwise
280  * it relativizes it wrt server_root.
281  */
282
283 API_EXPORT(const char *) ap_server_root_relative(pool *p, const char *fname);
284
285 /* Finally, the hook for dynamically loading modules in... */
286
287 API_EXPORT(void) ap_add_module(module *m);
288 API_EXPORT(void) ap_remove_module(module *m);
289 API_EXPORT(void) ap_add_loaded_module(module *mod);
290 API_EXPORT(void) ap_remove_loaded_module(module *mod);
291 API_EXPORT(int) ap_add_named_module(const char *name);
292 API_EXPORT(void) ap_clear_module_list(void);
293 API_EXPORT(const char *) ap_find_module_name(module *m);
294 API_EXPORT(module *) ap_find_linked_module(const char *name);
295
296 /* for implementing subconfigs and customized config files */
297 API_EXPORT(const char *) ap_srm_command_loop(cmd_parms *parms, void *config);
298
299 /* ap_check_cmd_context() definitions: */
300 API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden);
301
302 /* ap_check_cmd_context():              Forbidden in: */
303 #define  NOT_IN_VIRTUALHOST     0x01 /* <Virtualhost> */
304 #define  NOT_IN_LIMIT           0x02 /* <Limit> */
305 #define  NOT_IN_DIRECTORY       0x04 /* <Directory> */
306 #define  NOT_IN_LOCATION        0x08 /* <Location> */
307 #define  NOT_IN_FILES           0x10 /* <Files> */
308 #define  NOT_IN_DIR_LOC_FILE    (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES) /* <Directory>/<Location>/<Files>*/
309 #define  GLOBAL_ONLY            (NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE)
310
311
312 #ifdef CORE_PRIVATE
313
314 extern API_VAR_EXPORT module *top_module;
315
316 extern module *ap_prelinked_modules[];
317 extern module *ap_preloaded_modules[];
318 extern API_VAR_EXPORT module **ap_loaded_modules;
319
320 /* For mod_so.c... */
321
322 void ap_single_module_configure(pool *p, server_rec *s, module *m);
323
324 /* For http_main.c... */
325
326 void ap_setup_prelinked_modules(void);
327 void ap_show_directives(void);
328 void ap_show_modules(void);
329 server_rec *ap_read_config(pool *conf_pool, pool *temp_pool, const char *config_name);
330 void ap_post_config_hook(pool *pconf, pool *plog, pool *ptemp, server_rec *s);
331 void ap_child_init_hook(pool *pchild, server_rec *s);
332
333 /* For http_request.c... */
334
335 void *ap_create_request_config(pool *p);
336 CORE_EXPORT(void *) ap_create_per_dir_config(pool *p);
337 void *ap_merge_per_dir_configs(pool *p, void *base, void *new);
338
339 /* For http_connection.c... */
340
341 void *ap_create_conn_config(pool *p);
342
343 /* For http_core.c... (<Directory> command and virtual hosts) */
344
345 int ap_parse_htaccess(void **result, request_rec *r, int override,
346                 const char *path, const char *access_name);
347
348 CORE_EXPORT(const char *) ap_init_virtual_host(pool *p, const char *hostname,
349                                 server_rec *main_server, server_rec **);
350 void ap_process_resource_config(server_rec *s, const char *fname, pool *p, pool *ptemp);
351
352 /* Module-method dispatchers, also for http_request.c */
353
354 int ap_translate_name(request_rec *);
355 int ap_check_user_id(request_rec *);    /* obtain valid username from client auth */
356 int ap_invoke_handler(request_rec *);
357
358 /* for mod_perl */
359
360 CORE_EXPORT(const command_rec *) ap_find_command(const char *name, const command_rec *cmds);
361 CORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod);
362 CORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod);
363 CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l);
364
365 #endif
366
367   /* Hooks */
368 DECLARE_HOOK(int,header_parser,(request_rec *))
369 DECLARE_HOOK(void,pre_config,(pool *pconf,pool *plog,pool *ptemp))
370 DECLARE_HOOK(void,post_config,
371              (pool *pconf,pool *plog,pool *ptemp,server_rec *s))
372 DECLARE_HOOK(void,open_logs,
373              (pool *pconf,pool *plog,pool *ptemp,server_rec *s))
374 DECLARE_HOOK(void,child_init,(pool *pchild, server_rec *s))
375
376 #ifdef __cplusplus
377 }
378 #endif
379
380 #endif  /* !APACHE_HTTP_CONFIG_H */