]> granicus.if.org Git - apache/blob - include/http_config.h
This patch corrects the issues from the AP_EXPORT and linkage
[apache] / include / http_config.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
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
17  *    distribution.
18  *
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.
25  *
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.
30  *
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.
34  *
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
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
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/>.
53  *
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.
57  */
58
59 #ifndef APACHE_HTTP_CONFIG_H
60 #define APACHE_HTTP_CONFIG_H
61
62 #include "ap_hooks.h"
63 #include "util_cfgtree.h"
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
69 /*
70  * The central data structures around here...
71  */
72
73 /* Command dispatch structures... */
74
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
78  * RAW_ARGS.
79  */
80 enum cmd_how {
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
85                                  * (e.g., IndexIgnore)
86                                  */
87     ITERATE2,                   /* two arguments, 2nd occurs multiple times
88                                  * (e.g., AddIcon)
89                                  */
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 */
97 };
98
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...
104                                  */
105     int req_override;           /* What overrides need to be allowed to
106                                  * enable this command.
107                                  */
108     enum cmd_how args_how;      /* What the command expects as arguments */
109
110     const char *errmsg;         /* 'usage' message, in case of syntax errors */
111 } command_rec;
112
113 /* The allowed locations for a configuration directive are the union of
114  * those indicated by each set bit in the req_override mask.
115  *
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
128  */
129 #define OR_NONE 0
130 #define OR_LIMIT 1
131 #define OR_OPTIONS 2
132 #define OR_FILEINFO 4
133 #define OR_AUTHCFG 8
134 #define OR_INDEXES 16
135 #define OR_UNSET 32
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)
140
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
143  * as an error code.
144  */
145
146 #define DECLINE_CMD "\a\b"
147
148 /* Common structure for reading of config files / passwd files etc. */
149 typedef struct {
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 */
156 } configfile_t;
157
158 /*
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*...
162  */
163
164 typedef struct {
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 */
168
169     configfile_t *config_file;  /* Config file structure. */
170     ap_directive_t *directive;  /* the directive specifying this command */
171
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...
176                                  */
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).
186                                  */
187     const command_rec *cmd;     /* configuration command */
188
189     void *context;              /* per_dir_config vector passed 
190                                  * to handle_command */
191 } cmd_parms;
192
193 /* This structure records the existence of handlers in a module... */
194
195 typedef struct {
196     const char *content_type;   /* MUST be all lower case */
197     int (*handler) (request_rec *);
198 } handler_rec;
199
200 /*
201  * Module structures.  Just about everything is dispatched through
202  * these, directly or indirectly (through the command and handler
203  * tables).
204  */
205
206 typedef struct module_struct {
207     int version;                /* API version, *not* module version;
208                                  * check that module is compatible with this
209                                  * version of the server.
210                                  */
211     int minor_version;          /* API minor version. Provides API feature
212                                  * milestones. Not checked during module init
213                                  */
214     int module_index;           /* Index to this modules structures in
215                                  * config vectors.
216                                  */
217
218     const char *name;
219     void *dynamic_load_handle;
220
221     struct module_struct *next;
222
223     unsigned long magic;        /* Magic Cookie to identify a module structure;
224                                  * It's mainly important for the DSO facility
225                                  * (see also mod_so).
226                                  */
227     void (*pre_config) (ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp);
228     void *(*create_dir_config) (ap_pool_t *p, char *dir);
229     void *(*merge_dir_config) (ap_pool_t *p, void *base_conf, void *new_conf);
230     void *(*create_server_config) (ap_pool_t *p, server_rec *s);
231     void *(*merge_server_config) (ap_pool_t *p, void *base_conf, void *new_conf);
232
233     const command_rec *cmds;
234     const handler_rec *handlers;
235
236     /* Hooks for getting into the middle of server ops...
237
238      * translate_handler --- translate URI to filename
239      * access_checker --- check access by host address, etc.   All of these
240      *                    run; if all decline, that's still OK.
241      * check_user_id --- get and validate user id from the HTTP request
242      * auth_checker --- see if the user (from check_user_id) is OK *here*.
243      *                  If all of *these* decline, the request is rejected
244      *                  (as a SERVER_ERROR, since the module which was
245      *                  supposed to handle this was configured wrong).
246      * type_checker --- Determine MIME type of the requested entity;
247      *                  sets content_type, _encoding and _language fields.
248      */
249
250     void (*register_hooks) (void);
251 } module;
252
253 /* Initializer for the first few module slots, which are only
254  * really set up once we start running.  Note that the first two slots
255  * provide a version check; this should allow us to deal with changes to
256  * the API. The major number should reflect changes to the API handler table
257  * itself or removal of functionality. The minor number should reflect
258  * additions of functionality to the existing API. (the server can detect
259  * an old-format module, and either handle it back-compatibly, or at least
260  * signal an error). See src/include/ap_mmn.h for MMN version history.
261  */
262
263 #define STANDARD_MODULE_STUFF   this_module_needs_to_be_ported_to_apache_2_0
264
265 #define STANDARD20_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \
266                                 MODULE_MAGIC_NUMBER_MINOR, \
267                                 -1, \
268                                 __FILE__, \
269                                 NULL, \
270                                 NULL, \
271                                 MODULE_MAGIC_COOKIE, \
272                                 NULL
273
274 #define MPM20_MODULE_STUFF      MODULE_MAGIC_NUMBER_MAJOR, \
275                                 MODULE_MAGIC_NUMBER_MINOR, \
276                                 -1, \
277                                 __FILE__, \
278                                 NULL, \
279                                 NULL, \
280                                 MODULE_MAGIC_COOKIE
281
282 /* Generic accessors for other modules to get at their own module-specific
283  * data
284  */
285
286 API_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m);
287 API_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val);
288
289 #define ap_get_module_config(v,m)       \
290     (((void **)(v))[(m)->module_index])
291 #define ap_set_module_config(v,m,val)   \
292     ((((void **)(v))[(m)->module_index]) = (val))
293
294 /* Generic command handling function... */
295
296 API_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *, char *, char *);
297 API_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *, char *, char *);
298 API_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *, char *, int);
299 API_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *, char *, char *);
300
301 /* For modules which need to read config files, open logs, etc. ...
302  * this returns the fname argument if it begins with '/'; otherwise
303  * it relativizes it wrt server_root.
304  */
305
306 API_EXPORT(const char *) ap_server_root_relative(ap_pool_t *p, const char *fname);
307
308 /* Finally, the hook for dynamically loading modules in... */
309
310 API_EXPORT(void) ap_add_module(module *m);
311 API_EXPORT(void) ap_remove_module(module *m);
312 API_EXPORT(void) ap_add_loaded_module(module *mod);
313 API_EXPORT(void) ap_remove_loaded_module(module *mod);
314 API_EXPORT(int) ap_add_named_module(const char *name);
315 API_EXPORT(void) ap_clear_module_list(void);
316 API_EXPORT(const char *) ap_find_module_name(module *m);
317 API_EXPORT(module *) ap_find_linked_module(const char *name);
318
319 /* Open a configfile_t as FILE, return open configfile_t struct pointer */
320 API_EXPORT(ap_status_t) ap_pcfg_openfile(configfile_t **, ap_pool_t *p, const char *name);
321
322 /* Allocate a configfile_t handle with user defined functions and params */
323 API_EXPORT(configfile_t *) ap_pcfg_open_custom(ap_pool_t *p, const char *descr,
324     void *param,
325     int(*getc_func)(void*),
326     void *(*gets_func) (void *buf, size_t bufsiz, void *param),
327     int(*close_func)(void *param));
328
329 /* Read one line from open configfile_t, strip LF, increase line number */
330 API_EXPORT(int) ap_cfg_getline(char *buf, size_t bufsize, configfile_t *cfp);
331
332 /* Read one char from open configfile_t, increase line number upon LF */
333 API_EXPORT(int) ap_cfg_getc(configfile_t *cfp);
334
335 /* Detach from open configfile_t, calling the close handler */
336 API_EXPORT(int) ap_cfg_closefile(configfile_t *cfp);
337
338 /* for implementing subconfigs and customized config files */
339 API_EXPORT(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive);
340 const char * ap_build_cont_config(ap_pool_t *p, ap_pool_t *temp_pool,
341                                         cmd_parms *parms,
342                                         ap_directive_t **current,
343                                         ap_directive_t **curr_parent,
344                                         char *orig_directive);
345 API_EXPORT(const char *) ap_build_config(cmd_parms *parms,
346                                          ap_pool_t *conf_pool,
347                                          ap_pool_t *temp_pool,
348                                          ap_directive_t **conftree);
349 API_EXPORT(const char *) ap_walk_config(ap_directive_t *conftree,
350                                         cmd_parms *parms, void *config);
351
352 /* ap_check_cmd_context() definitions: */
353 API_EXPORT(const char *) ap_check_cmd_context(cmd_parms *cmd, unsigned forbidden);
354
355 /* ap_check_cmd_context():              Forbidden in: */
356 #define  NOT_IN_VIRTUALHOST     0x01 /* <Virtualhost> */
357 #define  NOT_IN_LIMIT           0x02 /* <Limit> */
358 #define  NOT_IN_DIRECTORY       0x04 /* <Directory> */
359 #define  NOT_IN_LOCATION        0x08 /* <Location> */
360 #define  NOT_IN_FILES           0x10 /* <Files> */
361 #define  NOT_IN_DIR_LOC_FILE    (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES) /* <Directory>/<Location>/<Files>*/
362 #define  GLOBAL_ONLY            (NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE)
363
364
365 #ifdef CORE_PRIVATE
366
367 extern API_EXPORT_VAR module *top_module;
368
369 extern module *ap_prelinked_modules[];
370 extern module *ap_preloaded_modules[];
371 extern API_EXPORT_VAR module **ap_loaded_modules;
372
373 /* For mod_so.c... */
374
375 void ap_single_module_configure(ap_pool_t *p, server_rec *s, module *m);
376
377 /* For http_main.c... */
378
379 void ap_setup_prelinked_modules(process_rec *process);
380 void ap_show_directives(void);
381 void ap_show_modules(void);
382 server_rec *ap_read_config(process_rec *process, ap_pool_t *temp_pool, const char *config_name);
383 void ap_post_config_hook(ap_pool_t *pconf, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s);
384 void ap_child_init_hook(ap_pool_t *pchild, server_rec *s);
385 void ap_run_pre_config(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp);
386
387 void ap_register_hooks(module *m);
388
389 /* For http_request.c... */
390
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);
394
395 /* For http_connection.c... */
396
397 void *ap_create_conn_config(ap_pool_t *p);
398
399 /* For http_core.c... (<Directory> command and virtual hosts) */
400
401 int ap_parse_htaccess(void **result, request_rec *r, int override,
402                 const char *path, const char *access_name);
403
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);
407
408 /* Module-method dispatchers, also for http_request.c */
409
410 int ap_translate_name(request_rec *);
411 int ap_check_user_id(request_rec *);    /* obtain valid username from client auth */
412 int ap_invoke_handler(request_rec *);
413
414 /* for mod_perl */
415
416 CORE_EXPORT(const command_rec *) ap_find_command(const char *name, const command_rec *cmds);
417 CORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod);
418 CORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod);
419 CORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l);
420
421 #endif
422
423   /* Hooks */
424 AP_DECLARE_HOOK(API_EXPORT,int,header_parser,(request_rec *))
425 AP_DECLARE_HOOK(API_EXPORT,void,post_config,
426              (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp,server_rec *s))
427 AP_DECLARE_HOOK(API_EXPORT,void,open_logs,
428              (ap_pool_t *pconf,ap_pool_t *plog,ap_pool_t *ptemp,server_rec *s))
429 AP_DECLARE_HOOK(API_EXPORT,void,child_init,(ap_pool_t *pchild, server_rec *s))
430
431 #ifdef __cplusplus
432 }
433 #endif
434
435 #endif  /* !APACHE_HTTP_CONFIG_H */