]> granicus.if.org Git - apache/blob - include/http_config.h
Allow restart of httpd to occur even with syntax errors in the config
[apache] / include / http_config.h
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2003 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 "apr_hooks.h"
63 #include "util_cfgtree.h"
64
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68
69 /**
70  * @file http_config.h
71  * @brief Apache Configuration
72  */
73
74 /*
75  * The central data structures around here...
76  */
77
78 /* Command dispatch structures... */
79
80 /**
81  * How the directives arguments should be parsed.
82  * @remark Note that for all of these except RAW_ARGS, the config routine is
83  *      passed a freshly allocated string which can be modified or stored
84  *      or whatever...
85  */
86 enum cmd_how {
87     RAW_ARGS,                   /**< cmd_func parses command line itself */
88     TAKE1,                      /**< one argument only */
89     TAKE2,                      /**< two arguments only */
90     ITERATE,                    /**< one argument, occuring multiple times
91                                  * (e.g., IndexIgnore)
92                                  */
93     ITERATE2,                   /**< two arguments, 2nd occurs multiple times
94                                  * (e.g., AddIcon)
95                                  */
96     FLAG,                       /**< One of 'On' or 'Off' */
97     NO_ARGS,                    /**< No args at all, e.g. </Directory> */
98     TAKE12,                     /**< one or two arguments */
99     TAKE3,                      /**< three arguments only */
100     TAKE23,                     /**< two or three arguments */
101     TAKE123,                    /**< one, two or three arguments */
102     TAKE13                      /**< one or three arguments */
103 };
104 /**
105  * This structure is passed to a command which is being invoked,
106  * to carry a large variety of miscellaneous data which is all of
107  * use to *somebody*...
108  */
109 typedef struct cmd_parms_struct cmd_parms;
110
111 #if defined(AP_HAVE_DESIGNATED_INITIALIZER) || defined(DOXYGEN)
112
113 /** 
114  * All the types of functions that can be used in directives
115  * @internal
116  */
117 typedef union {
118     /** function to call for a no-args */
119     const char *(*no_args) (cmd_parms *parms, void *mconfig);
120     /** function to call for a raw-args */
121     const char *(*raw_args) (cmd_parms *parms, void *mconfig,
122                              const char *args);
123     /** function to call for a take1 */
124     const char *(*take1) (cmd_parms *parms, void *mconfig, const char *w);
125     /** function to call for a take2 */
126     const char *(*take2) (cmd_parms *parms, void *mconfig, const char *w,
127                           const char *w2);
128     /** function to call for a take3 */
129     const char *(*take3) (cmd_parms *parms, void *mconfig, const char *w,
130                           const char *w2, const char *w3);
131     /** function to call for a flag */
132     const char *(*flag) (cmd_parms *parms, void *mconfig, int on);
133 } cmd_func;
134
135 /** This configuration directive does not take any arguments */
136 # define AP_NO_ARGS     func.no_args
137 /** This configuration directive will handle it's own parsing of arguments*/
138 # define AP_RAW_ARGS    func.raw_args
139 /** This configuration directive takes 1 argument*/
140 # define AP_TAKE1       func.take1
141 /** This configuration directive takes 2 arguments */
142 # define AP_TAKE2       func.take2
143 /** This configuration directive takes 3 arguments */
144 # define AP_TAKE3       func.take3
145 /** This configuration directive takes a flag (on/off) as a argument*/
146 # define AP_FLAG        func.flag
147
148 /** method of declaring a directive with no arguments */
149 # define AP_INIT_NO_ARGS(directive, func, mconfig, where, help) \
150     { directive, { .no_args=func }, mconfig, where, RAW_ARGS, help }
151 /** method of declaring a directive with raw argument parsing */
152 # define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \
153     { directive, { .raw_args=func }, mconfig, where, RAW_ARGS, help }
154 /** method of declaring a directive which takes 1 argument */
155 # define AP_INIT_TAKE1(directive, func, mconfig, where, help) \
156     { directive, { .take1=func }, mconfig, where, TAKE1, help }
157 /** method of declaring a directive which takes multiple arguments */
158 # define AP_INIT_ITERATE(directive, func, mconfig, where, help) \
159     { directive, { .take1=func }, mconfig, where, ITERATE, help }
160 /** method of declaring a directive which takes 2 arguments */
161 # define AP_INIT_TAKE2(directive, func, mconfig, where, help) \
162     { directive, { .take2=func }, mconfig, where, TAKE2, help }
163 /** method of declaring a directive which takes 1 or 2 arguments */
164 # define AP_INIT_TAKE12(directive, func, mconfig, where, help) \
165     { directive, { .take2=func }, mconfig, where, TAKE12, help }
166 /** method of declaring a directive which takes multiple 2 arguments */
167 # define AP_INIT_ITERATE2(directive, func, mconfig, where, help) \
168     { directive, { .take2=func }, mconfig, where, ITERATE2, help }
169 /** method of declaring a directive which takes 1 or 3 arguments */
170 # define AP_INIT_TAKE13(directive, func, mconfig, where, help) \
171     { directive, { .take3=func }, mconfig, where, TAKE13, help }
172 /** method of declaring a directive which takes 2 or 3 arguments */
173 # define AP_INIT_TAKE23(directive, func, mconfig, where, help) \
174     { directive, { .take3=func }, mconfig, where, TAKE23, help }
175 /** method of declaring a directive which takes 1 to 3 arguments */
176 # define AP_INIT_TAKE123(directive, func, mconfig, where, help) \
177     { directive, { .take3=func }, mconfig, where, TAKE123, help }
178 /** method of declaring a directive which takes 3 arguments */
179 # define AP_INIT_TAKE3(directive, func, mconfig, where, help) \
180     { directive, { .take3=func }, mconfig, where, TAKE3, help }
181 /** method of declaring a directive which takes a flag (on/off) as a argument*/
182 # define AP_INIT_FLAG(directive, func, mconfig, where, help) \
183     { directive, { .flag=func }, mconfig, where, FLAG, help }
184
185 #else /* AP_HAVE_DESIGNATED_INITIALIZER */
186
187 typedef const char *(*cmd_func) ();
188
189 # define AP_NO_ARGS  func
190 # define AP_RAW_ARGS func
191 # define AP_TAKE1    func
192 # define AP_TAKE2    func
193 # define AP_TAKE3    func
194 # define AP_FLAG     func
195
196 # define AP_INIT_NO_ARGS(directive, func, mconfig, where, help) \
197     { directive, func, mconfig, where, RAW_ARGS, help }
198 # define AP_INIT_RAW_ARGS(directive, func, mconfig, where, help) \
199     { directive, func, mconfig, where, RAW_ARGS, help }
200 # define AP_INIT_TAKE1(directive, func, mconfig, where, help) \
201     { directive, func, mconfig, where, TAKE1, help }
202 # define AP_INIT_ITERATE(directive, func, mconfig, where, help) \
203     { directive, func, mconfig, where, ITERATE, help }
204 # define AP_INIT_TAKE2(directive, func, mconfig, where, help) \
205     { directive, func, mconfig, where, TAKE2, help }
206 # define AP_INIT_TAKE12(directive, func, mconfig, where, help) \
207     { directive, func, mconfig, where, TAKE12, help }
208 # define AP_INIT_ITERATE2(directive, func, mconfig, where, help) \
209     { directive, func, mconfig, where, ITERATE2, help }
210 # define AP_INIT_TAKE13(directive, func, mconfig, where, help) \
211     { directive, func, mconfig, where, TAKE13, help }
212 # define AP_INIT_TAKE23(directive, func, mconfig, where, help) \
213     { directive, func, mconfig, where, TAKE23, help }
214 # define AP_INIT_TAKE123(directive, func, mconfig, where, help) \
215     { directive, func, mconfig, where, TAKE123, help }
216 # define AP_INIT_TAKE3(directive, func, mconfig, where, help) \
217     { directive, func, mconfig, where, TAKE3, help }
218 # define AP_INIT_FLAG(directive, func, mconfig, where, help) \
219     { directive, func, mconfig, where, FLAG, help }
220
221 #endif /* AP_HAVE_DESIGNATED_INITIALIZER */
222
223 /**
224  * The command record structure.  Each modules can define a table of these
225  * to define the directives it will implement.
226  */
227 typedef struct command_struct command_rec; 
228 struct command_struct {
229     /** Name of this command */
230     const char *name;
231     /** The function to be called when this directive is parsed */
232     cmd_func func;
233     /** Extra data, for functions which implement multiple commands... */
234     void *cmd_data;             
235     /** What overrides need to be allowed to enable this command. */
236     int req_override;
237     /** What the command expects as arguments 
238      *  @defvar cmd_how args_how*/
239     enum cmd_how args_how;
240
241     /** 'usage' message, in case of syntax errors */
242     const char *errmsg;
243 };
244
245 /**
246  * @defgroup ConfigDirectives Allowed locations for configuration directives.
247  *
248  * The allowed locations for a configuration directive are the union of
249  * those indicated by each set bit in the req_override mask.
250  *
251  * @{
252  */
253 #define OR_NONE 0             /**< *.conf is not available anywhere in this override */
254 #define OR_LIMIT 1           /**< *.conf inside <Directory> or <Location>
255                                 and .htaccess when AllowOverride Limit */
256 #define OR_OPTIONS 2         /**< *.conf anywhere
257                                 and .htaccess when AllowOverride Options */
258 #define OR_FILEINFO 4        /**< *.conf anywhere
259                                 and .htaccess when AllowOverride FileInfo */
260 #define OR_AUTHCFG 8         /**< *.conf inside <Directory> or <Location>
261                                 and .htaccess when AllowOverride AuthConfig */
262 #define OR_INDEXES 16        /**< *.conf anywhere
263                                 and .htaccess when AllowOverride Indexes */
264 #define OR_UNSET 32          /**< unset a directive (in Allow) */
265 #define ACCESS_CONF 64       /**< *.conf inside <Directory> or <Location> */
266 #define RSRC_CONF 128        /**< *.conf outside <Directory> or <Location> */
267 #define EXEC_ON_READ 256     /**< force directive to execute a command 
268                 which would modify the configuration (like including another
269                 file, or IFModule */
270 /** this directive can be placed anywhere */
271 #define OR_ALL (OR_LIMIT|OR_OPTIONS|OR_FILEINFO|OR_AUTHCFG|OR_INDEXES)
272
273 /** @} */
274
275 /**
276  * This can be returned by a function if they don't wish to handle
277  * a command. Make it something not likely someone will actually use
278  * as an error code.
279  */
280 #define DECLINE_CMD "\a\b"
281
282 /** Common structure for reading of config files / passwd files etc. */
283 typedef struct ap_configfile_t ap_configfile_t;
284 struct ap_configfile_t {
285     int (*getch) (void *param);     /**< a getc()-like function */
286     void *(*getstr) (void *buf, size_t bufsiz, void *param);
287                                     /**< a fgets()-like function */
288     int (*close) (void *param);     /**< a close handler function */
289     void *param;                    /**< the argument passed to getch/getstr/close */
290     const char *name;               /**< the filename / description */
291     unsigned line_number;           /**< current line number, starting at 1 */
292 };
293
294 /**
295  * This structure is passed to a command which is being invoked,
296  * to carry a large variety of miscellaneous data which is all of
297  * use to *somebody*...
298  */
299 struct cmd_parms_struct {
300     /** Argument to command from cmd_table */
301     void *info;
302     /** Which allow-override bits are set */
303     int override;
304     /** Which methods are <Limit>ed */
305     apr_int64_t limited;
306     /** methods which are limited */
307     apr_array_header_t *limited_xmethods;
308     /** methods which are xlimited */
309     ap_method_list_t *xlimited;
310
311     /** Config file structure. */
312     ap_configfile_t *config_file;
313     /** the directive specifying this command */
314     ap_directive_t *directive;
315
316     /** Pool to allocate new storage in */
317     apr_pool_t *pool;
318     /** Pool for scratch memory; persists during configuration, but 
319      *  wiped before the first request is served...  */
320     apr_pool_t *temp_pool;
321     /** Server_rec being configured for */
322     server_rec *server;
323     /** If configuring for a directory, pathname of that directory.  
324      *  NOPE!  That's what it meant previous to the existance of <Files>, 
325      * <Location> and regex matching.  Now the only usefulness that can be 
326      * derived from this field is whether a command is being called in a 
327      * server context (path == NULL) or being called in a dir context 
328      * (path != NULL).  */
329     char *path;
330     /** configuration command */
331     const command_rec *cmd;
332
333     /** per_dir_config vector passed to handle_command */
334     struct ap_conf_vector_t *context;
335     /** directive with syntax error */
336     const ap_directive_t *err_directive;
337 };
338
339 /**
340  * Module structures.  Just about everything is dispatched through
341  * these, directly or indirectly (through the command and handler
342  * tables).
343  */
344 typedef struct module_struct module;
345 struct module_struct {
346     /** API version, *not* module version; check that module is 
347      * compatible with this version of the server.
348      */
349     int version;
350     /** API minor version. Provides API feature milestones. Not checked 
351      *  during module init */
352     int minor_version;
353     /** Index to this modules structures in config vectors.  */
354     int module_index;
355
356     /** The name of the module's C file */
357     const char *name;
358     /** The handle for the DSO.  Internal use only */
359     void *dynamic_load_handle;
360
361     /** A pointer to the next module in the list
362      *  @defvar module_struct *next */
363     struct module_struct *next;
364
365     /** Magic Cookie to identify a module structure;  It's mainly 
366      *  important for the DSO facility (see also mod_so).  */
367     unsigned long magic;
368
369     /** Function to allow MPMs to re-write command line arguments.  This
370      *  hook is only available to MPMs.
371      *  @param The process that the server is running in.
372      */
373     void (*rewrite_args) (process_rec *process);
374     /** Function to allow all modules to create per directory configuration
375      *  structures.
376      *  @param p The pool to use for all allocations.
377      *  @param dir The directory currently being processed.
378      *  @return The per-directory structure created
379      */
380     void *(*create_dir_config) (apr_pool_t *p, char *dir);
381     /** Function to allow all modules to merge the per directory configuration
382      *  structures for two directories.
383      *  @param p The pool to use for all allocations.
384      *  @param base_conf The directory structure created for the parent directory.
385      *  @param new_conf The directory structure currently being processed.
386      *  @return The new per-directory structure created
387      */
388     void *(*merge_dir_config) (apr_pool_t *p, void *base_conf, void *new_conf);
389     /** Function to allow all modules to create per server configuration
390      *  structures.
391      *  @param p The pool to use for all allocations.
392      *  @param s The server currently being processed.
393      *  @return The per-server structure created
394      */
395     void *(*create_server_config) (apr_pool_t *p, server_rec *s);
396     /** Function to allow all modules to merge the per server configuration
397      *  structures for two servers.
398      *  @param p The pool to use for all allocations.
399      *  @param base_conf The directory structure created for the parent directory.
400      *  @param new_conf The directory structure currently being processed.
401      *  @return The new per-directory structure created
402      */
403     void *(*merge_server_config) (apr_pool_t *p, void *base_conf, 
404                                   void *new_conf);
405
406     /** A command_rec table that describes all of the directives this module
407      * defines. */
408     const command_rec *cmds;
409
410     /** A hook to allow modules to hook other points in the request processing.
411      *  In this function, modules should call the ap_hook_*() functions to
412      *  register an interest in a specific step in processing the current
413      *  request.
414      *  @param p the pool to use for all allocations
415      */
416     void (*register_hooks) (apr_pool_t *p);
417 };
418
419 /**
420  * @defgroup ModuleInit Module structure initializers
421  *
422  * Initializer for the first few module slots, which are only
423  * really set up once we start running.  Note that the first two slots
424  * provide a version check; this should allow us to deal with changes to
425  * the API. The major number should reflect changes to the API handler table
426  * itself or removal of functionality. The minor number should reflect
427  * additions of functionality to the existing API. (the server can detect
428  * an old-format module, and either handle it back-compatibly, or at least
429  * signal an error). See src/include/ap_mmn.h for MMN version history.
430  * @{
431  */
432
433 /** The one used in Apache 1.3, which will deliberately cause an error */
434 #define STANDARD_MODULE_STUFF   this_module_needs_to_be_ported_to_apache_2_0
435
436 /** Use this in all standard modules */
437 #define STANDARD20_MODULE_STUFF MODULE_MAGIC_NUMBER_MAJOR, \
438                                 MODULE_MAGIC_NUMBER_MINOR, \
439                                 -1, \
440                                 __FILE__, \
441                                 NULL, \
442                                 NULL, \
443                                 MODULE_MAGIC_COOKIE, \
444                                 NULL      /* rewrite args spot */
445
446 /** Use this only in MPMs */
447 #define MPM20_MODULE_STUFF      MODULE_MAGIC_NUMBER_MAJOR, \
448                                 MODULE_MAGIC_NUMBER_MINOR, \
449                                 -1, \
450                                 __FILE__, \
451                                 NULL, \
452                                 NULL, \
453                                 MODULE_MAGIC_COOKIE
454
455 /** @} */
456
457 /* CONFIGURATION VECTOR FUNCTIONS */
458
459 /** configuration vector structure */
460 typedef struct ap_conf_vector_t ap_conf_vector_t;
461
462 #if defined(AP_DEBUG) || defined(DOXYGEN)
463 /**
464  * Generic accessors for other modules to get at their own module-specific
465  * data
466  * @param conf_vector The vector in which the modules configuration is stored.
467  *        usually r->per_dir_config or s->module_config
468  * @param m The module to get the data for.
469  * @return The module-specific data
470  */
471 AP_DECLARE(void *) ap_get_module_config(const ap_conf_vector_t *cv,
472                                         const module *m);
473
474 /**
475  * Generic accessors for other modules to set at their own module-specific
476  * data
477  * @param conf_vector The vector in which the modules configuration is stored.
478  *        usually r->per_dir_config or s->module_config
479  * @param m The module to set the data for.
480  * @param val The module-specific data to set
481  */
482 AP_DECLARE(void) ap_set_module_config(ap_conf_vector_t *cv, const module *m,
483                                       void *val);
484
485 #else /* AP_DEBUG */
486
487 #define ap_get_module_config(v,m)       \
488     (((void **)(v))[(m)->module_index])
489 #define ap_set_module_config(v,m,val)   \
490     ((((void **)(v))[(m)->module_index]) = (val))
491
492 #endif /* AP_DEBUG */
493
494
495 /**
496  * Generic command handling function for strings
497  * @param cmd The command parameters for this directive
498  * @param struct_ptr pointer into a given type
499  * @param arg The argument to the directive
500  * @return An error string or NULL on success
501  */
502 AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd, 
503                                                    void *struct_ptr,
504                                                    const char *arg);
505
506 /**
507  * Generic command handling function for integers
508  * @param cmd The command parameters for this directive
509  * @param struct_ptr pointer into a given type
510  * @param arg The argument to the directive
511  * @return An error string or NULL on success
512  */
513 AP_DECLARE_NONSTD(const char *) ap_set_int_slot(cmd_parms *cmd, 
514                                                 void *struct_ptr,
515                                                 const char *arg);
516
517 /**
518  * Return true if the specified method is limited by being listed in
519  * a <Limit> container, or by *not* being listed in a <LimiteExcept>
520  * container.
521  *
522  * @param   method  Pointer to a string specifying the method to check.
523  * @param   cmd     Pointer to the cmd_parms structure passed to the
524  *                  directive handler.
525  * @return  0 if the method is not limited in the current scope
526  */
527 AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method);
528
529 /**
530  * Generic command handling function for strings, always sets the value
531  * to a lowercase string
532  * @param cmd The command parameters for this directive
533  * @param struct_ptr pointer into a given type
534  * @param arg The argument to the directive
535  * @return An error string or NULL on success
536  */
537 AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd, 
538                                                          void *struct_ptr, 
539                                                          const char *arg);
540 /**
541  * Generic command handling function for flags
542  * @param cmd The command parameters for this directive
543  * @param struct_ptr pointer into a given type
544  * @param arg The argument to the directive (either 1 or 0)
545  * @return An error string or NULL on success
546  */
547 AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd, 
548                                                  void *struct_ptr, 
549                                                  int arg);
550 /**
551  * Generic command handling function for files
552  * @param cmd The command parameters for this directive
553  * @param struct_ptr pointer into a given type
554  * @param arg The argument to the directive
555  * @return An error string or NULL on success
556  */
557 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, 
558                                                  void *struct_ptr, 
559                                                  const char *arg);
560 /**
561  * Generic command handling function to respond with cmd->help as an error
562  * @param cmd The command parameters for this directive
563  * @param struct_ptr pointer into a given type
564  * @param arg The argument to the directive
565  * @return The cmd->help value as the error string
566  * @tip This allows simple declarations such as;
567  * <pre>
568  *     AP_INIT_RAW_ARGS("Foo", ap_set_deprecated, NULL, OR_ALL, 
569  *         "The Foo directive is no longer supported, use Bar"),
570  * </pre>
571  */
572 AP_DECLARE_NONSTD(const char *) ap_set_deprecated(cmd_parms *cmd, 
573                                                   void *struct_ptr, 
574                                                   const char *arg);
575 /**
576  * For modules which need to read config files, open logs, etc. this returns
577  * the canonical form of fname made absolute to ap_server_root.
578  * @param p pool to allocate data from
579  * @param fname The file name
580  */
581 AP_DECLARE(char *) ap_server_root_relative(apr_pool_t *p, const char *fname);
582
583 /* Finally, the hook for dynamically loading modules in... */
584
585 /**
586  * Add a module to the server
587  * @param m The module structure of the module to add
588  * @param p The pool of the same lifetime as the module
589  */
590 AP_DECLARE(void) ap_add_module(module *m, apr_pool_t *p);
591
592 /**
593  * Remove a module from the server.  There are some caveats:
594  * when the module is removed, its slot is lost so all the current
595  * per-dir and per-server configurations are invalid. So we should
596  * only ever call this function when you are invalidating almost
597  * all our current data. I.e. when doing a restart.
598  * @param m the module structure of the module to remove
599  */
600 AP_DECLARE(void) ap_remove_module(module *m);
601 /**
602  * Add a module to the chained modules list and the list of loaded modules
603  * @param m The module structure of the module to add
604  * @param p The pool with the same lifetime as the module
605  */
606 AP_DECLARE(void) ap_add_loaded_module(module *mod, apr_pool_t *p);
607 /**
608  * Remove a module fromthe chained modules list and the list of loaded modules
609  * @param m the module structure of the module to remove
610  */
611 AP_DECLARE(void) ap_remove_loaded_module(module *mod);
612 /**
613  * Add a module to the list of loaded module based on the name of the
614  * module
615  * @param name The name of the module
616  * @param p The pool valid for the lifetime of the module
617  * @return 1 on success, 0 on failure
618  */
619 AP_DECLARE(int) ap_add_named_module(const char *name, apr_pool_t *p);
620 /**
621  * Find the name of the specified module
622  * @param m The module to get the name for
623  * @return the name of the module
624  */
625 AP_DECLARE(const char *) ap_find_module_name(module *m);
626 /**
627  * Find a module based on the name of the module
628  * @param name the name of the module
629  * @return the module structure if found, NULL otherwise
630  */
631 AP_DECLARE(module *) ap_find_linked_module(const char *name);
632
633 /**
634  * Open a ap_configfile_t as apr_file_t
635  * @param ret_cfg open ap_configfile_t struct pointer
636  * @param p The pool to allocate the structure from
637  * @param name the name of the file to open
638  */
639 AP_DECLARE(apr_status_t) ap_pcfg_openfile(ap_configfile_t **ret_cfg, 
640                                           apr_pool_t *p, const char *name);
641
642 /**
643  * Allocate a ap_configfile_t handle with user defined functions and params 
644  * @param p The pool to allocate from
645  * @param descr The name of the file
646  * @param param The argument passed to getch/getstr/close
647  * @param getc_func The getch function
648  * @param gets_func The getstr function
649  * @param close_func The close function
650  */
651 AP_DECLARE(ap_configfile_t *) ap_pcfg_open_custom(apr_pool_t *p, 
652     const char *descr,
653     void *param,
654     int(*getc_func)(void*),
655     void *(*gets_func) (void *buf, size_t bufsiz, void *param),
656     int(*close_func)(void *param));
657
658 /**
659  * Read one line from open ap_configfile_t, strip LF, increase line number
660  * @param buf place to store the line read
661  * @param bufsize size of the buffer
662  * @param cfp File to read from
663  * @return 1 on success, 0 on failure
664  */
665 AP_DECLARE(int) ap_cfg_getline(char *buf, size_t bufsize, ap_configfile_t *cfp);
666
667 /**
668  * Read one char from open configfile_t, increase line number upon LF 
669  * @param cfp The file to read from
670  * @return the character read
671  */
672 AP_DECLARE(int) ap_cfg_getc(ap_configfile_t *cfp);
673
674 /**
675  * Detach from open ap_configfile_t, calling the close handler
676  * @param cfp The file to close
677  * @return 1 on sucess, 0 on failure
678  */
679 AP_DECLARE(int) ap_cfg_closefile(ap_configfile_t *cfp);
680
681 /**
682  * Read all data between the current <foo> and the matching </foo>.  All
683  * of this data is forgotten immediately.  
684  * @param cmd The cmd_parms to pass to the directives inside the container
685  * @param directive The directive name to read until
686  * @return Error string on failure, NULL on success
687  */
688 AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive);
689
690 /**
691  * Read all data between the current <foo> and the matching </foo> and build
692  * a config tree from it
693  * @param p pool to allocate from
694  * @param temp_pool Temporary pool to allocate from
695  * @param parms The cmd_parms to pass to all directives read
696  * @param current The current node in the tree
697  * @param curr_parent The current parent node
698  * @param orig_directive The directive to read until hit.
699  * @return Error string on failure, NULL on success
700 */
701 AP_DECLARE(const char *) ap_build_cont_config(apr_pool_t *p, 
702                                               apr_pool_t *temp_pool,
703                                               cmd_parms *parms,
704                                               ap_directive_t **current,
705                                               ap_directive_t **curr_parent,
706                                               char *orig_directive);
707
708 /**
709  * Build a config tree from a config file
710  * @param parms The cmd_parms to pass to all of the directives in the file
711  * @param conf_pool The pconf pool
712  * @param temp_pool The temporary pool
713  * @param conftree Place to store the root node of the config tree
714  * @return Error string on erro, NULL otherwise
715  */
716 AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
717                                          apr_pool_t *conf_pool,
718                                          apr_pool_t *temp_pool,
719                                          ap_directive_t **conftree);
720
721 /**
722  * Walk a config tree and setup the server's internal structures
723  * @param conftree The config tree to walk
724  * @param parms The cmd_parms to pass to all functions
725  * @param section_vector The per-section config vector.
726  * @return Error string on error, NULL otherwise
727  */
728 AP_DECLARE(const char *) ap_walk_config(ap_directive_t *conftree,
729                                         cmd_parms *parms,
730                                         ap_conf_vector_t *section_vector);
731
732 /**
733  * @defgroup ap_check_cmd_context ap_check_cmd_context
734  * @{
735  */
736 /**
737  * Check the context a command is used in.
738  * @param cmd The command to check
739  * @param forbidden Where the command is forbidden.
740  * @return Error string on error, NULL on success
741  */
742 AP_DECLARE(const char *) ap_check_cmd_context(cmd_parms *cmd, 
743                                               unsigned forbidden);
744
745 #define  NOT_IN_VIRTUALHOST     0x01 /**< Forbidden in <Virtualhost> */
746 #define  NOT_IN_LIMIT           0x02 /**< Forbidden in <Limit> */
747 #define  NOT_IN_DIRECTORY       0x04 /**< Forbidden in <Directory> */
748 #define  NOT_IN_LOCATION        0x08 /**< Forbidden in <Location> */
749 #define  NOT_IN_FILES           0x10 /**< Forbidden in <Files> */
750 /** Forbidden in <Directory>/<Location>/<Files>*/
751 #define  NOT_IN_DIR_LOC_FILE    (NOT_IN_DIRECTORY|NOT_IN_LOCATION|NOT_IN_FILES) 
752 /** Forbidden in <VirtualHost>/<Limit>/<Directory>/<Location>/<Files> */
753 #define  GLOBAL_ONLY            (NOT_IN_VIRTUALHOST|NOT_IN_LIMIT|NOT_IN_DIR_LOC_FILE) 
754
755 /** @} */
756
757 #ifdef CORE_PRIVATE
758
759 /**
760  * The topmost module in the list
761  * @defvar module *ap_top_module
762  */
763 AP_DECLARE_DATA extern module *ap_top_module;
764
765 /**
766  * Array of all statically linked modules
767  * @defvar module *ap_prelinked_modules[]
768  */
769 AP_DECLARE_DATA extern module *ap_prelinked_modules[];
770 /**
771  * Array of all preloaded modules
772  * @defvar module *ap_preloaded_modules[]
773  */
774 AP_DECLARE_DATA extern module *ap_preloaded_modules[];
775 /**
776  * Array of all loaded modules
777  * @defvar module **ap_loaded_modules
778  */
779 AP_DECLARE_DATA extern module **ap_loaded_modules;
780
781 /* For mod_so.c... */
782 /** Run a single module's two create_config hooks
783  *  @param p the pool to allocate from
784  *  @param s The server to configure for.
785  *  @param m The module to configure
786  */
787 AP_DECLARE(void) ap_single_module_configure(apr_pool_t *p, server_rec *s, 
788                                             module *m);
789
790 /* For http_main.c... */
791 /**
792  * Add all of the prelinked modules into the loaded module list
793  * @param process The process that is currently running the server
794  */
795 AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process);
796
797 /**
798  * Show the preloaded configuration directives, the help string explaining
799  * the directive arguments, in what module they are handled, and in
800  * what parts of the configuration they are allowed.  Used for httpd -h.
801  */
802 AP_DECLARE(void) ap_show_directives(void);
803
804 /** 
805  * Show the preloaded module names.  Used for httpd -l. 
806  */
807 AP_DECLARE(void) ap_show_modules(void);
808
809 /** 
810  * Show the MPM name.  Used in reporting modules such as mod_info to
811  * provide extra information to the user
812  */
813 AP_DECLARE(const char *) ap_show_mpm(void);
814
815 /**
816  * Read all config files and setup the server
817  * @param process The process running the server
818  * @param temp_pool A pool to allocate temporary data from.
819  * @param config_name The name of the config file
820  * @param conftree Place to store the root of the config tree
821  * @return The setup server_rec list.
822  */
823 AP_DECLARE(server_rec *) ap_read_config(process_rec *process, 
824                                         apr_pool_t *temp_pool, 
825                                         const char *config_name, 
826                                         ap_directive_t **conftree);
827
828 /**
829  * Run all rewrite args hooks for loaded modules
830  * @param process The process currently running the server
831  */
832 AP_DECLARE(void) ap_run_rewrite_args(process_rec *process);
833
834 /**
835  * Run the register hooks function for a specified module
836  * @param m The module to run the register hooks function fo
837  * @param p The pool valid for the lifetime of the module
838  */
839 AP_DECLARE(void) ap_register_hooks(module *m, apr_pool_t *p);
840
841 /**
842  * Setup all virtual hosts
843  * @param p The pool to allocate from
844  * @param main_server The head of the server_rec list
845  */
846 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, 
847                                         server_rec *main_server);
848
849 /* For http_request.c... */
850
851 /**
852  * Setup the config vector for a request_rec
853  * @param p The pool to allocate the config vector from
854  * @return The config vector
855  */
856 AP_CORE_DECLARE(ap_conf_vector_t*) ap_create_request_config(apr_pool_t *p);
857
858 /**
859  * Setup the config vector for per dir module configs
860  * @param p The pool to allocate the config vector from
861  * @return The config vector
862  */
863 AP_CORE_DECLARE(ap_conf_vector_t *) ap_create_per_dir_config(apr_pool_t *p);
864
865 /**
866  * Run all of the modules merge per dir config functions
867  * @param p The pool to pass to the merge functions
868  * @param base The base directory config structure
869  * @param new_conf The new directory config structure
870  */
871 AP_CORE_DECLARE(ap_conf_vector_t*) ap_merge_per_dir_configs(apr_pool_t *p,
872                                            ap_conf_vector_t *base,
873                                            ap_conf_vector_t *new_conf);
874
875 /* For http_connection.c... */
876 /**
877  * Setup the config vector for a connection_rec
878  * @param p The pool to allocate the config vector from
879  * @return The config vector
880  */
881 AP_CORE_DECLARE(ap_conf_vector_t*) ap_create_conn_config(apr_pool_t *p);
882
883 /* For http_core.c... (<Directory> command and virtual hosts) */
884
885 /**
886  * parse an htaccess file
887  * @param resulting htaccess_result
888  * @param r The request currently being served
889  * @param override Which overrides are active
890  * @param path The path to the htaccess file
891  * @param access_name The list of possible names for .htaccess files
892  * int The status of the current request
893  */
894 AP_CORE_DECLARE(int) ap_parse_htaccess(ap_conf_vector_t **result, 
895                                        request_rec *r, int override,
896                                        const char *path, 
897                                        const char *access_name);
898
899 /**
900  * Setup a virtual host
901  * @param p The pool to allocate all memory from
902  * @param hostname The hostname of the virtual hsot
903  * @param main_server The main server for this Apache configuration
904  * @param ps Place to store the new server_rec
905  * return Error string on error, NULL on success
906  */
907 AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, 
908                                                    const char *hostname,
909                                                    server_rec *main_server, 
910                                                    server_rec **);
911
912 /**
913  * Process the config file for Apache
914  * @param s The server rec to use for the command parms
915  * @param fname The name of the config file
916  * @param conftree The root node of the created config tree
917  * @param p Pool for general allocation
918  * @param ptem Pool for temporary allocation
919  */
920 AP_DECLARE(void) ap_process_resource_config(server_rec *s, const char *fname, 
921                                             ap_directive_t **conftree, 
922                                             apr_pool_t *p, apr_pool_t *ptemp);
923
924 /**
925  * Process all directives in the config tree
926  * @param s The server rec to use in the command parms
927  * @param conftree The config tree to process
928  * @param p The pool for general allocation
929  * @param ptemp The pool for temporary allocations
930  * @return OK if no problems
931  */
932 AP_DECLARE(int) ap_process_config_tree(server_rec *s,
933                                        ap_directive_t *conftree,
934                                        apr_pool_t *p,
935                                        apr_pool_t *ptemp);
936
937 /* Module-method dispatchers, also for http_request.c */
938 /**
939  * Run the handler phase of each module until a module accepts the
940  * responsibility of serving the request
941  * @param r The current request
942  * @return The status of the current request
943  */
944 AP_CORE_DECLARE(int) ap_invoke_handler(request_rec *r);
945
946 /* for mod_perl */
947
948 /**
949  * Find a given directive in a command_rec table
950  * @param name The directive to search for
951  * @param cmds The table to search
952  * @return The directive definition of the specified directive
953  */
954 AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, 
955                                                      const command_rec *cmds);
956
957 /**
958  * Find a given directive in a list module
959  * @param cmd_name The directive to search for
960  * @param mod The module list to search
961  * @return The directive definition of the specified directive
962  */
963 AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(const char *cmd_name, 
964                                                                 module **mod);
965
966 /**
967  * Ask a module to create per-server and per-section (dir/loc/file) configs
968  * (if it hasn't happened already). The results are stored in the server's
969  * config, and the specified per-section config vector.
970  * @param server The server to operate upon.
971  * @param section_vector The per-section config vector.
972  * @param section Which section to create a config for.
973  * @param mod The module which is defining the config data.
974  * @param pconf A pool for all configuration allocations.
975  * @return The (new) per-section config data.
976  */
977 AP_CORE_DECLARE(void *) ap_set_config_vectors(server_rec *server,
978                                               ap_conf_vector_t *section_vector,
979                                               const char *section,
980                                               module *mod, apr_pool_t *pconf);
981
982 #endif
983
984   /* Hooks */
985
986 /**
987  * Run the header parser functions for each module
988  * @param r The current request
989  * @return OK or DECLINED
990  */
991 AP_DECLARE_HOOK(int,header_parser,(request_rec *r))
992
993 /**
994  * Run the pre_config function for each module
995  * @param pconf The config pool
996  * @param plog The logging streams pool
997  * @param ptemp The temporary pool
998  * @return OK or DECLINED on success anything else is a error
999  */
1000 AP_DECLARE_HOOK(int,pre_config,(apr_pool_t *pconf,apr_pool_t *plog,
1001                                 apr_pool_t *ptemp))
1002
1003
1004 /**
1005  * Run the post_config function for each module
1006  * @param pconf The config pool
1007  * @param plog The logging streams pool
1008  * @param ptemp The temporary pool
1009  * @param s The list of server_recs
1010  * @return OK or DECLINED on success anything else is a error
1011  */
1012 AP_DECLARE_HOOK(int,post_config,(apr_pool_t *pconf,apr_pool_t *plog,
1013                                  apr_pool_t *ptemp,server_rec *s))
1014
1015 /**
1016  * Run the open_logs functions for each module
1017  * @param pconf The config pool
1018  * @param plog The logging streams pool
1019  * @param ptemp The temporary pool
1020  * @param s The list of server_recs
1021  * @return OK or DECLINED on success anything else is a error
1022  */
1023 AP_DECLARE_HOOK(int,open_logs,(apr_pool_t *pconf,apr_pool_t *plog,
1024                                apr_pool_t *ptemp,server_rec *s))
1025
1026 /**
1027  * Run the child_init functions for each module
1028  * @param pchild The child pool
1029  * @param s The list of server_recs in this server 
1030  */
1031 AP_DECLARE_HOOK(void,child_init,(apr_pool_t *pchild, server_rec *s))
1032
1033 /**
1034  * Run the handler functions for each module
1035  * @param r The request_rec
1036  * @remark non-wildcard handlers should HOOK_MIDDLE, wildcard HOOK_LAST
1037  */
1038 AP_DECLARE_HOOK(int,handler,(request_rec *r))
1039
1040 /**
1041  * Run the quick handler functions for each module. The quick_handler
1042  * is run before any other requests hooks are called (location_walk,
1043  * directory_walk, access checking, et. al.). This hook was added
1044  * to provide a quick way to serve content from a URI keyed cache.
1045  * 
1046  * @param r The request_rec
1047  * @param lookup_uri Controls whether the caller actually wants content or not.
1048  * lookup is set when the quick_handler is called out of 
1049  * ap_sub_req_lookup_uri()
1050  */
1051 AP_DECLARE_HOOK(int,quick_handler,(request_rec *r, int lookup_uri))
1052
1053 /**
1054  * Retrieve the optional functions for each module.
1055  * This is run immediately before the server starts. Optional functions should
1056  * be registered during the hook registration phase.
1057  */
1058 AP_DECLARE_HOOK(void,optional_fn_retrieve,(void))
1059
1060 #ifdef __cplusplus
1061 }
1062 #endif
1063
1064 #endif  /* !APACHE_HTTP_CONFIG_H */