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.
60 * http_config.c: once was auxillary functions for reading httpd's config
61 * file and converting filenames into a namespace
65 * Wall-to-wall rewrite for Apache... commands which are part of the
66 * server core can now be found next door in "http_core.c". Now contains
67 * general command loop, and functions which do bookkeeping for the new
68 * Apache config stuff (modules and configuration vectors).
75 #include "apr_strings.h"
76 #include "apr_portable.h"
77 #include "apr_file_io.h"
85 #include "ap_config.h"
87 #include "http_config.h"
88 #include "http_protocol.h"
89 #include "http_core.h"
90 #include "http_log.h" /* for errors in parse_htaccess */
91 #include "http_request.h" /* for default_handler (see invoke_handler) */
92 #include "http_main.h"
93 #include "http_vhost.h"
94 #include "util_cfgtree.h"
95 #ifdef HAVE_ARPA_INET_H
96 #include <arpa/inet.h>
102 AP_DECLARE_DATA const char *ap_server_argv0;
104 AP_DECLARE_DATA const char *ap_server_root;
106 AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config;
107 AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config;
108 AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines;
110 AP_DECLARE_DATA ap_directive_t *ap_conftree;
113 AP_HOOK_LINK(header_parser)
114 AP_HOOK_LINK(pre_config)
115 AP_HOOK_LINK(post_config)
116 AP_HOOK_LINK(open_logs)
117 AP_HOOK_LINK(child_init)
120 AP_IMPLEMENT_HOOK_RUN_ALL(int,header_parser,
121 (request_rec *r),(r),OK,DECLINED)
122 AP_IMPLEMENT_HOOK_VOID(pre_config,
123 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp),
125 AP_IMPLEMENT_HOOK_VOID(post_config,
126 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
127 server_rec *s),(pconf,plog,ptemp,s))
128 AP_IMPLEMENT_HOOK_VOID(open_logs,
129 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
130 server_rec *s),(pconf,plog,ptemp,s))
131 AP_IMPLEMENT_HOOK_VOID(child_init,
132 (apr_pool_t *pchild, server_rec *s),(pchild,s))
134 /****************************************************************
136 * We begin with the functions which deal with the linked list
137 * of modules which control just about all of the server operation.
140 /* total_modules is the number of modules that have been linked
143 static int total_modules = 0;
144 /* dynamic_modules is the number of modules that have been added
145 * after the pre-loaded ones have been set up. It shouldn't be larger
146 * than DYNAMIC_MODULE_LIMIT.
148 static int dynamic_modules = 0;
149 AP_DECLARE_DATA module *top_module = NULL;
150 AP_DECLARE_DATA module **ap_loaded_modules=NULL;
152 typedef int (*handler_func) (request_rec *);
153 typedef void *(*dir_maker_func) (apr_pool_t *, char *);
154 typedef void *(*merger_func) (apr_pool_t *, void *, void *);
156 /* Dealing with config vectors. These are associated with per-directory,
157 * per-server, and per-request configuration, and have a void* pointer for
158 * each modules. The nature of the structure pointed to is private to the
159 * module in question... the core doesn't (and can't) know. However, there
160 * are defined interfaces which allow it to create instances of its private
161 * per-directory and per-server structures, and to merge the per-directory
162 * structures of a directory and its subdirectory (producing a new one in
163 * which the defaults applying to the base directory have been properly
167 #ifndef ap_get_module_config
168 AP_DECLARE(void *) ap_get_module_config(void *conf_vector, module *m)
170 void **confv = (void **) conf_vector;
171 return confv[m->module_index];
175 #ifndef ap_set_module_config
176 AP_DECLARE(void) ap_set_module_config(void *conf_vector, module *m, void *val)
178 void **confv = (void **) conf_vector;
179 confv[m->module_index] = val;
183 static void *create_empty_config(apr_pool_t *p)
185 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) *
186 (total_modules + DYNAMIC_MODULE_LIMIT));
187 return (void *) conf_vector;
190 static void *create_default_per_dir_config(apr_pool_t *p)
192 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
195 for (modp = top_module; modp; modp = modp->next) {
196 dir_maker_func df = modp->create_dir_config;
199 conf_vector[modp->module_index] = (*df) (p, NULL);
202 return (void *) conf_vector;
206 ap_merge_per_dir_configs(apr_pool_t *p, void *base, void *new)
208 void **conf_vector = (void **) apr_palloc(p, sizeof(void *) * total_modules);
209 void **base_vector = (void **) base;
210 void **new_vector = (void **) new;
213 for (modp = top_module; modp; modp = modp->next) {
214 merger_func df = modp->merge_dir_config;
215 int i = modp->module_index;
217 if (df && new_vector[i])
218 conf_vector[i] = (*df) (p, base_vector[i], new_vector[i]);
220 conf_vector[i] = new_vector[i] ? new_vector[i] : base_vector[i];
223 return (void *) conf_vector;
226 static void *create_server_config(apr_pool_t *p, server_rec *s)
228 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
231 for (modp = top_module; modp; modp = modp->next) {
232 if (modp->create_server_config)
233 conf_vector[modp->module_index] = (*modp->create_server_config) (p, s);
236 return (void *) conf_vector;
239 static void merge_server_configs(apr_pool_t *p, void *base, void *virt)
241 /* Can reuse the 'virt' vector for the spine of it, since we don't
242 * have to deal with the moral equivalent of .htaccess files here...
245 void **base_vector = (void **) base;
246 void **virt_vector = (void **) virt;
249 for (modp = top_module; modp; modp = modp->next) {
250 merger_func df = modp->merge_server_config;
251 int i = modp->module_index;
254 virt_vector[i] = base_vector[i];
256 virt_vector[i] = (*df) (p, base_vector[i], virt_vector[i]);
260 void *ap_create_request_config(apr_pool_t *p)
262 return create_empty_config(p);
265 void *ap_create_conn_config(apr_pool_t *p)
267 return create_empty_config(p);
270 AP_CORE_DECLARE(void *) ap_create_per_dir_config(apr_pool_t *p)
272 return create_empty_config(p);
276 * For speed/efficiency we generate a compact list of all the handlers
277 * and wildcard handlers. This means we won't have to scan the entire
278 * module list looking for handlers... where we'll find a whole whack
286 static fast_handler_rec *handlers;
287 static fast_handler_rec *wildhandlers;
289 static void init_handlers(apr_pool_t *p)
293 int nwildhandlers = 0;
294 const handler_rec *handp;
295 fast_handler_rec *ph, *pw;
298 for (modp = top_module; modp; modp = modp->next) {
301 for (handp = modp->handlers; handp->content_type; ++handp) {
302 if (ap_strchr_c(handp->content_type, '*')) {
309 ph = handlers = apr_palloc(p, sizeof(*ph)*(nhandlers + 1));
310 pw = wildhandlers = apr_palloc(p, sizeof(*pw)*(nwildhandlers + 1));
311 for (modp = top_module; modp; modp = modp->next) {
314 for (handp = modp->handlers; handp->content_type; ++handp) {
315 if ((starp = ap_strchr_c(handp->content_type, '*'))) {
316 pw->hr.content_type = handp->content_type;
317 pw->hr.handler = handp->handler;
318 pw->len = starp - handp->content_type;
321 ph->hr.content_type = handp->content_type;
322 ph->hr.handler = handp->handler;
323 ph->len = strlen(handp->content_type);
328 pw->hr.content_type = NULL;
329 pw->hr.handler = NULL;
330 ph->hr.content_type = NULL;
331 ph->hr.handler = NULL;
334 int ap_invoke_handler(request_rec *r)
336 fast_handler_rec *handp;
340 int result = HTTP_INTERNAL_SERVER_ERROR;
343 handler = r->handler;
344 handler_len = strlen(handler);
347 handler = r->content_type ? r->content_type : ap_default_type(r);
348 if ((p = ap_strchr_c(handler, ';')) != NULL) {
349 /* MIME type arguments */
350 while (p > handler && p[-1] == ' ')
351 --p; /* strip trailing spaces */
352 handler_len = p - handler;
355 handler_len = strlen(handler);
359 /* Pass one --- direct matches */
361 for (handp = handlers; handp->hr.content_type; ++handp) {
362 if (handler_len == handp->len
363 && !strncmp(handler, handp->hr.content_type, handler_len)) {
364 result = (*handp->hr.handler) (r);
366 if (result != DECLINED)
371 /* Pass two --- wildcard matches */
373 for (handp = wildhandlers; handp->hr.content_type; ++handp) {
374 if (handler_len >= handp->len
375 && !strncmp(handler, handp->hr.content_type, handp->len)) {
376 result = (*handp->hr.handler) (r);
378 if (result != DECLINED)
383 if (result == HTTP_INTERNAL_SERVER_ERROR && r->handler && r->filename) {
384 ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r,
385 "handler \"%s\" not found for: %s", r->handler, r->filename);
387 return HTTP_INTERNAL_SERVER_ERROR;
390 AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method) {
395 methnum = ap_method_number_of(method);
397 * The simple case: a method hard-coded into Apache.
399 if (methnum != M_INVALID) {
400 return (methnum & cmd->limited);
403 * Some extension method we don't know implicitly.
405 if ((cmd->limited_xmethods == NULL)
406 || (cmd->limited_xmethods->nelts == 0)) {
409 xmethod = (char **) cmd->limited_xmethods->elts;
410 for (i = 0; i < cmd->limited_xmethods->nelts; ++i) {
411 if (strcmp(method, xmethod[i]) == 0) {
418 AP_DECLARE(void) ap_register_hooks(module *m)
420 if(m->register_hooks)
422 if(getenv("SHOW_HOOKS"))
424 printf("Registering hooks for %s\n",m->name);
425 ap_debug_module_hooks=1;
427 ap_debug_module_name=m->name;
432 /* One-time setup for precompiled modules --- NOT to be done on restart */
434 AP_DECLARE(void) ap_add_module(module *m)
436 /* This could be called from an AddModule httpd.conf command,
437 * after the file has been linked and the module structure within it
441 if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
442 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
443 "%s: module \"%s\" is not compatible with this "
444 "version of Apache.", ap_server_argv0, m->name);
445 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Please contact the vendor for the correct version.");
449 if (m->next == NULL) {
450 m->next = top_module;
453 if (m->module_index == -1) {
454 m->module_index = total_modules++;
457 if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
458 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
459 "%s: module \"%s\" could not be loaded, because"
460 " the dynamic", ap_server_argv0, m->name);
461 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
462 "module limit was reached. Please increase "
463 "DYNAMIC_MODULE_LIMIT and recompile.");
468 /* Some C compilers put a complete path into __FILE__, but we want
469 * only the filename (e.g. mod_includes.c). So check for path
470 * components (Unix and DOS), and remove them.
473 if (ap_strrchr_c(m->name, '/'))
474 m->name = 1 + ap_strrchr_c(m->name, '/');
475 if (ap_strrchr_c(m->name, '\\'))
476 m->name = 1 + ap_strrchr_c(m->name, '\\');
478 #ifdef _OSD_POSIX /* __FILE__="*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */
479 /* We cannot fix the string in-place, because it's const */
480 if (m->name[strlen(m->name)-1]==')') {
481 char *tmp = strdup(m->name); /* FIXME:memory leak, albeit a small one */
482 tmp[strlen(tmp)-1] = '\0';
485 #endif /*_OSD_POSIX*/
487 /* FIXME: is this the right place to call this? */
488 ap_register_hooks(m);
492 * remove_module undoes what add_module did. There are some caveats:
493 * when the module is removed, its slot is lost so all the current
494 * per-dir and per-server configurations are invalid. So we should
495 * only ever call this function when you are invalidating almost
496 * all our current data. I.e. when doing a restart.
499 AP_DECLARE(void) ap_remove_module(module *m)
505 /* We are the top module, special case */
506 top_module = modp->next;
510 /* Not the top module, find use. When found modp will
511 * point to the module _before_ us in the list
514 while (modp && modp->next != m) {
518 /* Uh-oh, this module doesn't exist */
519 ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
520 "Cannot remove module %s: not found in module list",
524 /* Eliminate us from the module list */
525 modp->next = modp->next->next;
528 m->module_index = -1; /* simulate being unloaded, should
534 AP_DECLARE(void) ap_add_loaded_module(module *mod)
539 * Add module pointer to top of chained module list
544 * And module pointer to list of loaded modules
546 * Notes: 1. ap_add_module() would already complain if no more space
547 * exists for adding a dynamically loaded module
548 * 2. ap_add_module() accepts double inclusion, so we have
549 * to accept this, too.
551 for (m = ap_loaded_modules; *m != NULL; m++)
557 AP_DECLARE(void) ap_remove_loaded_module(module *mod)
564 * Remove module pointer from chained module list
566 ap_remove_module(mod);
569 * Remove module pointer from list of loaded modules
571 * Note: 1. We cannot determine if the module was successfully
572 * removed by ap_remove_module().
573 * 2. We have not to complain explicity when the module
574 * is not found because ap_remove_module() did it
577 for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
578 if (*m2 == mod && done == 0)
586 AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process)
591 ap_global_hook_pool=process->pconf;
594 * Initialise total_modules variable and module indices
597 for (m = ap_preloaded_modules; *m != NULL; m++)
598 (*m)->module_index = total_modules++;
601 * Initialise list of loaded modules
603 ap_loaded_modules = (module **)apr_palloc(process->pool,
604 sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
605 if (ap_loaded_modules == NULL) {
606 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
607 "Ouch! Out of memory in ap_setup_prelinked_modules()!");
609 for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
614 * Initialize chain of linked (=activate) modules
616 for (m = ap_prelinked_modules; *m != NULL; m++)
622 AP_DECLARE(const char *) ap_find_module_name(module *m)
627 AP_DECLARE(module *) ap_find_linked_module(const char *name)
631 for (modp = top_module; modp; modp = modp->next) {
632 if (strcmp(modp->name, name) == 0)
638 /* Add a named module. Returns 1 if module found, 0 otherwise. */
639 AP_DECLARE(int) ap_add_named_module(const char *name)
644 for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) {
645 if (strcmp(modp->name, name) == 0) {
646 /* Only add modules that are not already enabled. */
647 if (modp->next == NULL) {
657 /* Clear the internal list of modules, in preparation for starting over. */
658 AP_DECLARE(void) ap_clear_module_list()
660 module **m = &top_module;
664 next_m = &((*m)->next);
669 /* This is required; so we add it always. */
670 ap_add_named_module("http_core.c");
673 /*****************************************************************
675 * Resource, access, and .htaccess config files now parsed by a common
678 * Let's begin with the basics; parsing the line and
679 * invoking the function...
682 static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
683 void *mconfig, const char *args)
688 if ((parms->override & cmd->req_override) == 0)
689 return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
691 parms->info = cmd->cmd_data;
694 switch (cmd->args_how) {
696 #ifdef RESOLVE_ENV_PER_TOKEN
697 args = ap_resolve_env(parms->pool,args);
699 return cmd->AP_RAW_ARGS(parms, mconfig, args);
703 return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
706 return cmd->AP_NO_ARGS(parms, mconfig);
709 w = ap_getword_conf(parms->pool, &args);
711 if (*w == '\0' || *args != 0)
712 return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
713 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
715 return cmd->AP_TAKE1(parms, mconfig, w);
718 w = ap_getword_conf(parms->pool, &args);
719 w2 = ap_getword_conf(parms->pool, &args);
721 if (*w == '\0' || *w2 == '\0' || *args != 0)
722 return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
723 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
725 return cmd->AP_TAKE2(parms, mconfig, w, w2);
729 w = ap_getword_conf(parms->pool, &args);
730 w2 = ap_getword_conf(parms->pool, &args);
732 if (*w == '\0' || *args != 0)
733 return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
734 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
736 return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
740 w = ap_getword_conf(parms->pool, &args);
741 w2 = ap_getword_conf(parms->pool, &args);
742 w3 = ap_getword_conf(parms->pool, &args);
744 if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
745 return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
746 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
748 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
752 w = ap_getword_conf(parms->pool, &args);
753 w2 = ap_getword_conf(parms->pool, &args);
754 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
756 if (*w == '\0' || *w2 == '\0' || *args != 0)
757 return apr_pstrcat(parms->pool, cmd->name,
758 " takes two or three arguments",
759 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
761 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
765 w = ap_getword_conf(parms->pool, &args);
766 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
767 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
769 if (*w == '\0' || *args != 0)
770 return apr_pstrcat(parms->pool, cmd->name,
771 " takes one, two or three arguments",
772 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
774 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
778 w = ap_getword_conf(parms->pool, &args);
779 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
780 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
782 if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
783 return apr_pstrcat(parms->pool, cmd->name,
784 " takes one or three arguments",
785 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
787 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
791 while (*(w = ap_getword_conf(parms->pool, &args)) != '\0')
793 if ((errmsg = cmd->AP_TAKE1(parms, mconfig, w)))
801 w = ap_getword_conf(parms->pool, &args);
803 if (*w == '\0' || *args == 0)
804 return apr_pstrcat(parms->pool, cmd->name,
805 " requires at least two arguments",
806 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
808 while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0')
810 if ((errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2)))
818 w = ap_getword_conf(parms->pool, &args);
820 if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
821 return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
824 return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
828 return apr_pstrcat(parms->pool, cmd->name,
829 " is improperly configured internally (server bug)",
834 AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, const command_rec *cmds)
837 if (!strcasecmp(name, cmds->name))
845 AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod)
847 const command_rec *cmdp;
850 for (modp = *mod; modp; modp = modp->next)
851 if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
859 AP_CORE_DECLARE(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod)
861 void *mconfig = ap_get_module_config(config, mod);
862 void *sconfig = ap_get_module_config(parms->server->module_config, mod);
864 if (!mconfig && mod->create_dir_config) {
865 mconfig = (*mod->create_dir_config) (parms->pool, parms->path);
866 ap_set_module_config(config, mod, mconfig);
869 if (!sconfig && mod->create_server_config) {
870 sconfig = (*mod->create_server_config) (parms->pool, parms->server);
871 ap_set_module_config(parms->server->module_config, mod, sconfig);
876 static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms,
877 apr_pool_t *p, apr_pool_t *ptemp,
878 ap_directive_t **sub_tree, ap_directive_t *parent);
880 static const char * ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
881 const char *l, cmd_parms *parms,
882 ap_directive_t **current,
883 ap_directive_t **curr_parent,
884 ap_directive_t **conftree)
888 ap_directive_t *newdir;
889 module *mod = top_module;
890 const command_rec *cmd;
892 if (*l == '#' || *l == '\0')
895 #if RESOLVE_ENV_PER_TOKEN
898 args = ap_resolve_env(temp_pool, l);
900 cmd_name = ap_getword_conf(p, &args);
901 if (*cmd_name == '\0') {
902 /* Note: this branch should not occur. An empty line should have
903 * triggered the exit further above.
908 newdir = apr_pcalloc(p, sizeof(ap_directive_t));
909 newdir->filename = parms->config_file->name;
910 newdir->line_num = parms->config_file->line_number;
911 newdir->directive = cmd_name;
912 newdir->args = apr_pstrdup(p, args);
914 if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) {
915 if (cmd->req_override & EXEC_ON_READ) {
917 ap_directive_t *sub_tree = NULL;
919 parms->err_directive = newdir;
920 retval = execute_now(cmd_name, args, parms, p, temp_pool,
921 &sub_tree, *curr_parent);
923 (*current)->next = sub_tree;
926 (*current) = sub_tree;
928 (*curr_parent)->first_child = (*current);
931 (*current)->parent = (*curr_parent);
936 /* Before walking *current to the end of the list,
937 * set the head to *current.
939 *conftree = *current;
941 while ((*current)->next != NULL) {
942 (*current) = (*current)->next;
943 (*current)->parent = (*curr_parent);
950 if (cmd_name[0] == '<') {
951 if (cmd_name[1] != '/') {
952 (*current) = ap_add_node(curr_parent, *current, newdir, 1);
954 else if (*curr_parent == NULL) {
955 parms->err_directive = newdir;
956 return apr_pstrcat(p, cmd_name,
957 " without matching <", cmd_name + 2,
961 char *bracket = cmd_name + strlen(cmd_name) - 1;
963 if (*bracket != '>') {
964 return apr_pstrcat(p, cmd_name,
965 "> directive missing closing '>'", NULL);
968 if (strcasecmp(cmd_name + 2,
969 (*curr_parent)->directive + 1) != 0) {
970 return apr_pstrcat(p, "Expected </",
971 (*curr_parent)->directive + 1, "> but saw ",
972 cmd_name, ">", NULL);
976 /* done with this section; move up a level */
977 *current = *curr_parent;
978 *curr_parent = (*current)->parent;
982 *current = ap_add_node(curr_parent, *current, newdir, 0);
988 const char *ap_build_cont_config(apr_pool_t *p, apr_pool_t *temp_pool,
990 ap_directive_t **current,
991 ap_directive_t **curr_parent,
992 char *orig_directive)
994 char l[MAX_STRING_LEN];
997 ap_directive_t *sub_tree = NULL;
999 bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL);
1000 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
1001 if (!memcmp(l, "</", 2) &&
1002 (strcasecmp(l + 2, bracket) == 0) &&
1003 (*curr_parent == NULL)) {
1006 retval = ap_build_config_sub(p, temp_pool, l, parms, current,
1007 curr_parent, &sub_tree);
1010 if (sub_tree == NULL && curr_parent != NULL) {
1011 sub_tree = *curr_parent;
1013 if (sub_tree == NULL && current != NULL) {
1014 sub_tree = *current;
1017 *current = sub_tree;
1021 static const char *ap_walk_config_sub(const ap_directive_t *current,
1022 cmd_parms *parms, void *config)
1024 module *mod = top_module;
1027 const command_rec *cmd;
1029 if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) {
1030 parms->err_directive = current;
1031 return apr_pstrcat(parms->pool, "Invalid command '",
1033 "', perhaps mis-spelled or defined by a module "
1034 "not included in the server configuration",
1038 void *mconfig = ap_set_config_vectors(parms,config, mod);
1041 retval = invoke_cmd(cmd, parms, mconfig, current->args);
1042 if (retval == NULL) {
1045 if (strcmp(retval, DECLINE_CMD) != 0) {
1046 /* If the directive in error has already been set, don't
1047 * replace it. Otherwise, an error inside a container
1048 * will be reported as occuring on the first line of the
1051 if (!parms->err_directive) {
1052 parms->err_directive = current;
1057 mod = mod->next; /* Next time around, skip this one */
1063 AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current,
1064 cmd_parms *parms, void *config)
1066 void *oldconfig = parms->context;
1068 parms->context = config;
1070 /* scan through all directives, executing each one */
1071 for (; current != NULL; current = current->next) {
1074 parms->directive = current;
1076 /* actually parse the command and execute the correct function */
1077 errmsg = ap_walk_config_sub(current, parms, config);
1078 if (errmsg != NULL) {
1079 /* restore the context (just in case) */
1080 parms->context = oldconfig;
1085 parms->context = oldconfig;
1090 AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
1091 apr_pool_t *p, apr_pool_t *temp_pool,
1092 ap_directive_t **conftree)
1094 ap_directive_t *current = *conftree;
1095 ap_directive_t *curr_parent = NULL;
1096 char l[MAX_STRING_LEN];
1099 if (current != NULL) {
1100 while (current->next) {
1101 current = current->next;
1105 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
1107 errmsg = ap_build_config_sub(p, temp_pool, l, parms,
1108 ¤t, &curr_parent, conftree);
1112 if (*conftree == NULL && curr_parent != NULL) {
1113 *conftree = curr_parent;
1115 if (*conftree == NULL && current != NULL) {
1116 *conftree = current;
1120 if (curr_parent != NULL) {
1122 while (curr_parent != NULL) {
1123 errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.",
1125 *errmsg == '\0' ? "" : APR_EOL_STR,
1126 curr_parent->filename,
1127 curr_parent->line_num,
1128 curr_parent->directive);
1129 curr_parent = curr_parent->parent;
1138 * Generic command functions...
1141 AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
1145 /* This one's pretty generic... */
1147 int offset = (int) (long) cmd->info;
1148 *(const char **) ((char *)struct_ptr + offset) = arg;
1152 AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
1156 /* This one's pretty generic... */
1157 char *arg=apr_pstrdup(cmd->pool,arg_);
1159 int offset = (int) (long) cmd->info;
1160 ap_str_tolower(arg);
1161 *(char **) ((char *)struct_ptr + offset) = arg;
1165 AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
1166 void *struct_ptr_v, int arg)
1168 /* This one's pretty generic too... */
1170 int offset = (int) (long) cmd->info;
1171 char *struct_ptr = (char *)struct_ptr_v;
1172 *(int *) (struct_ptr + offset) = arg ? 1 : 0;
1176 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, void *struct_ptr,
1179 /* Prepend server_root to relative arg.
1180 This allows .htaccess to be independent of server_root,
1181 so the server can be moved or mirrored with less pain. */
1183 int offset = (int) (long) cmd->info;
1185 arg = ap_os_canonical_filename(cmd->pool, arg);
1187 if (ap_os_is_path_absolute(arg))
1188 p = apr_pstrdup(cmd->pool, arg);
1190 p = ap_make_full_path(cmd->pool, ap_server_root, arg);
1191 *(char **) ((char*)struct_ptr + offset) = p;
1195 /*****************************************************************
1197 * Reading whole config files...
1200 static cmd_parms default_parms =
1201 {NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
1203 AP_DECLARE(const char *) ap_server_root_relative(apr_pool_t *p, const char *file)
1206 file = ap_os_canonical_filename(p, file);
1208 if(ap_os_is_path_absolute(file))
1210 return ap_make_full_path(p, ap_server_root, file);
1213 AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
1215 char l[MAX_STRING_LEN];
1219 while(!(ap_cfg_getline(l, MAX_STRING_LEN, cmd->config_file))) {
1220 #if RESOLVE_ENV_PER_TOKEN
1223 args = ap_resolve_env(cmd->temp_pool, l);
1225 cmd_name = ap_getword_conf(cmd->pool, &args);
1226 if (cmd_name[0] == '<') {
1227 if (cmd_name[1] == '/') {
1228 cmd_name[strlen(cmd_name) - 1] = '\0';
1229 if (strcasecmp(cmd_name + 2, directive + 1) != 0) {
1230 return apr_pstrcat(cmd->pool, "Expected </",
1231 directive + 1, "> but saw ",
1232 cmd_name, ">", NULL);
1237 ap_soak_end_container(cmd, cmd_name);
1244 static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms,
1245 apr_pool_t *p, apr_pool_t *ptemp,
1246 ap_directive_t **sub_tree, ap_directive_t *parent)
1248 module *mod = top_module;
1249 const command_rec *cmd;
1251 if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) {
1252 return apr_pstrcat(parms->pool, "Invalid command '",
1254 "', perhaps mis-spelled or defined by a module "
1255 "not included in the server configuration",
1259 return invoke_cmd(cmd, parms, sub_tree, args);
1263 /* This structure and the following functions are needed for the
1264 * table-based config file reading. They are passed to the
1265 * cfg_open_custom() routine.
1268 /* Structure to be passed to cfg_open_custom(): it contains an
1269 * index which is incremented from 0 to nelts on each call to
1270 * cfg_getline() (which in turn calls arr_elts_getstr())
1271 * and an apr_array_header_t pointer for the string array.
1274 apr_array_header_t *array;
1279 /* arr_elts_getstr() returns the next line from the string array. */
1280 static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
1282 arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
1284 /* End of array reached? */
1285 if (++arr_param->curr_idx > arr_param->array->nelts)
1288 /* return the line */
1289 apr_cpystrn(buf, ((char **) arr_param->array->elts)[arr_param->curr_idx - 1], bufsiz);
1295 /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
1296 static int arr_elts_close(void *param)
1298 arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
1299 arr_param->curr_idx = arr_param->array->nelts;
1303 static void process_command_config(server_rec *s, apr_array_header_t *arr,
1304 ap_directive_t **conftree, apr_pool_t *p,
1309 arr_elts_param_t arr_parms;
1311 arr_parms.curr_idx = 0;
1312 arr_parms.array = arr;
1314 parms = default_parms;
1316 parms.temp_pool = ptemp;
1318 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1320 parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
1322 arr_elts_getstr, arr_elts_close);
1324 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1326 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1327 "Syntax error in -C/-c directive:" APR_EOL_STR "%s",
1332 ap_cfg_closefile(parms.config_file);
1339 static int fname_alphasort(const void *fn1, const void *fn2)
1341 const fnames *f1 = fn1;
1342 const fnames *f2 = fn2;
1344 return strcmp(f1->fname,f2->fname);
1347 void ap_process_resource_config(server_rec *s, const char *fname,
1348 ap_directive_t **conftree, apr_pool_t *p,
1356 fname = ap_server_root_relative(p, fname);
1358 /* don't require conf/httpd.conf if we have a -C or -c switch */
1359 if ((ap_server_pre_read_config->nelts
1360 || ap_server_post_read_config->nelts)
1361 && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
1362 if (apr_stat(&finfo, fname, p) != APR_SUCCESS)
1367 * here we want to check if the candidate file is really a
1368 * directory, and most definitely NOT a symlink (to prevent
1369 * horrible loops). If so, let's recurse and toss it back into
1372 if (ap_is_rdirectory(fname)) {
1375 apr_array_header_t *candidates = NULL;
1379 * first course of business is to grok all the directory
1380 * entries here and store 'em away. Recall we need full pathnames
1383 fprintf(stderr, "Processing config directory: %s\n", fname);
1384 if (apr_dir_open(&dirp, fname, p) != APR_SUCCESS) {
1386 fprintf(stderr, "%s: could not open config directory %s\n",
1387 ap_server_argv0, fname);
1390 candidates = apr_make_array(p, 1, sizeof(fnames));
1391 while (apr_readdir(dirp) == APR_SUCCESS) {
1393 apr_get_dir_filename(&d_name, dirp);
1394 /* strip out '.' and '..' */
1395 if (strcmp(d_name, ".") &&
1396 strcmp(d_name, "..")) {
1397 fnew = (fnames *) apr_push_array(candidates);
1398 fnew->fname = ap_make_full_path(p, fname, d_name);
1402 if (candidates->nelts != 0) {
1403 qsort((void *) candidates->elts, candidates->nelts,
1404 sizeof(fnames), fname_alphasort);
1406 * Now recurse these... we handle errors and subdirectories
1407 * via the recursion, which is nice
1409 for (current = 0; current < candidates->nelts; ++current) {
1410 fnew = &((fnames *) candidates->elts)[current];
1411 fprintf(stderr, " Processing config file: %s\n", fnew->fname);
1412 ap_process_resource_config(s, fnew->fname, conftree, p, ptemp);
1418 /* GCC's initialization extensions are soooo nice here... */
1420 parms = default_parms;
1422 parms.temp_pool = ptemp;
1424 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1426 if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) {
1427 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1428 "%s: could not open document config file %s",
1429 ap_server_argv0, fname);
1433 parms.config_file = cfp;
1435 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1437 if (errmsg != NULL) {
1438 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1439 "Syntax error on line %d of %s:",
1440 parms.err_directive->line_num,
1441 parms.err_directive->filename);
1442 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1447 ap_cfg_closefile(cfp);
1450 AP_DECLARE(void)ap_process_config_tree(server_rec *s, ap_directive_t *conftree,
1451 apr_pool_t *p, apr_pool_t *ptemp)
1456 parms = default_parms;
1458 parms.temp_pool = ptemp;
1460 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1463 errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
1465 ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, p,
1466 "Syntax error on line %d of %s:",
1467 parms.err_directive->line_num,
1468 parms.err_directive->filename);
1469 ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, p,
1475 int ap_parse_htaccess(void **result, request_rec *r, int override,
1476 const char *d, const char *access_name) {
1477 configfile_t *f = NULL;
1479 char *filename = NULL;
1480 const struct htaccess_result *cache;
1481 struct htaccess_result *new;
1483 apr_status_t status;
1485 /* firstly, search cache */
1486 for (cache = r->htaccess; cache != NULL; cache = cache->next)
1487 if (cache->override == override && strcmp(cache->dir, d) == 0) {
1488 if (cache->htaccess != NULL)
1489 *result = cache->htaccess;
1493 parms = default_parms;
1494 parms.override = override;
1495 parms.pool = r->pool;
1496 parms.temp_pool = r->pool;
1497 parms.server = r->server;
1498 parms.path = apr_pstrdup(r->pool, d);
1500 /* loop through the access names and find the first one */
1502 while (access_name[0]) {
1503 filename = ap_make_full_path(r->pool, d,
1504 ap_getword_conf(r->pool, &access_name));
1505 status = ap_pcfg_openfile(&f, r->pool, filename);
1507 if (status == APR_SUCCESS) {
1509 ap_directive_t *temptree = NULL;
1511 dc = ap_create_per_dir_config(r->pool);
1513 parms.config_file = f;
1514 errmsg = ap_build_config(&parms, r->pool, r->pool, &temptree);
1516 errmsg = ap_walk_config(temptree, &parms, dc);
1518 ap_cfg_closefile(f);
1521 ap_log_rerror(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, r,
1522 "%s: %s", filename, errmsg);
1523 return HTTP_INTERNAL_SERVER_ERROR;
1528 if (!APR_STATUS_IS_ENOENT(status) && !APR_STATUS_IS_ENOTDIR(status)) {
1529 ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
1530 "%s pcfg_openfile: unable to check htaccess file, "
1531 "ensure it is readable",
1533 apr_table_setn(r->notes, "error-notes",
1534 "Server unable to read htaccess file, denying "
1535 "access to be safe");
1536 return HTTP_FORBIDDEN;
1542 new = apr_palloc(r->pool, sizeof(struct htaccess_result));
1543 new->dir = parms.path;
1544 new->override = override;
1546 /* add to head of list */
1547 new->next = r->htaccess;
1553 AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, const char *hostname,
1554 server_rec *main_server, server_rec **ps)
1556 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1558 /* TODO: this crap belongs in http_core */
1559 s->process = main_server->process;
1560 s->server_admin = NULL;
1561 s->server_hostname = NULL;
1562 s->error_fname = NULL;
1564 s->keep_alive_timeout = 0;
1566 s->keep_alive_max = -1;
1567 s->error_log = main_server->error_log;
1568 s->loglevel = main_server->loglevel;
1569 /* useful default, otherwise we get a port of 0 on redirects */
1570 s->port = main_server->port;
1574 s->names = apr_make_array(p, 4, sizeof(char **));
1575 s->wild_names = apr_make_array(p, 4, sizeof(char **));
1577 s->module_config = create_empty_config(p);
1578 s->lookup_defaults = ap_create_per_dir_config(p);
1580 s->limit_req_line = main_server->limit_req_line;
1581 s->limit_req_fieldsize = main_server->limit_req_fieldsize;
1582 s->limit_req_fields = main_server->limit_req_fields;
1586 return ap_parse_vhost_addrs(p, hostname, s);
1590 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
1594 for (virt = main_server->next; virt; virt = virt->next) {
1595 merge_server_configs(p, main_server->module_config,
1596 virt->module_config);
1598 virt->lookup_defaults =
1599 ap_merge_per_dir_configs(p, main_server->lookup_defaults,
1600 virt->lookup_defaults);
1602 if (virt->server_admin == NULL)
1603 virt->server_admin = main_server->server_admin;
1605 if (virt->timeout == 0)
1606 virt->timeout = main_server->timeout;
1608 if (virt->keep_alive_timeout == 0)
1609 virt->keep_alive_timeout = main_server->keep_alive_timeout;
1611 if (virt->keep_alive == -1)
1612 virt->keep_alive = main_server->keep_alive;
1614 if (virt->keep_alive_max == -1)
1615 virt->keep_alive_max = main_server->keep_alive_max;
1617 /* XXX: this is really something that should be dealt with by a
1618 * post-config api phase */
1619 ap_core_reorder_directories(p, virt);
1621 ap_core_reorder_directories(p, main_server);
1624 /*****************************************************************
1626 * Getting *everything* configured...
1629 static void init_config_globals(apr_pool_t *p)
1631 /* Global virtual host hash bucket pointers. Init to null. */
1632 ap_init_vhost_config(p);
1635 static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
1638 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1640 apr_open_stderr(&s->error_log, p);
1641 s->process = process;
1643 s->server_admin = DEFAULT_ADMIN;
1644 s->server_hostname = NULL;
1645 s->error_fname = DEFAULT_ERRORLOG;
1646 s->loglevel = DEFAULT_LOGLEVEL;
1647 s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
1648 s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
1649 s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
1650 s->timeout = DEFAULT_TIMEOUT;
1651 s->keep_alive_timeout = DEFAULT_KEEPALIVE_TIMEOUT;
1652 s->keep_alive_max = DEFAULT_KEEPALIVE;
1655 s->addrs = apr_pcalloc(p, sizeof(server_addr_rec));
1656 /* NOT virtual host; don't match any real network interface */
1657 rv = apr_getaddrinfo(&s->addrs->host_addr,
1658 NULL, APR_INET, 0, 0, p);
1659 ap_assert(rv == APR_SUCCESS); /* otherwise: bug or no storage */
1660 s->addrs->host_port = 0; /* matches any port */
1661 s->addrs->virthost = ""; /* must be non-NULL */
1662 s->names = s->wild_names = NULL;
1664 s->module_config = create_server_config(p, s);
1665 s->lookup_defaults = create_default_per_dir_config(p);
1671 AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
1672 const char *confname,
1673 ap_directive_t **conftree)
1675 apr_pool_t *p = process->pconf;
1676 server_rec *s = init_server_config(process, p);
1678 init_config_globals(p);
1680 /* All server-wide config files now have the SAME syntax... */
1682 process_command_config(s, ap_server_pre_read_config, conftree,
1685 ap_process_resource_config(s, confname, conftree, p, ptemp);
1687 process_command_config(s, ap_server_post_read_config, conftree,
1693 void ap_single_module_configure(apr_pool_t *p, server_rec *s, module *m)
1695 if (m->create_server_config)
1696 ap_set_module_config(s->module_config, m,
1697 (*m->create_server_config)(p, s));
1698 if (m->create_dir_config)
1699 ap_set_module_config(s->lookup_defaults, m,
1700 (*m->create_dir_config)(p, NULL));
1703 AP_DECLARE(void) ap_run_rewrite_args(process_rec *process)
1707 for (m = top_module; m; m = m->next)
1708 if (m->rewrite_args)
1709 (*m->rewrite_args) (process);
1712 AP_DECLARE(void) ap_post_config_hook(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
1714 ap_run_post_config(pconf,plog,ptemp,s);
1715 init_handlers(pconf);
1718 void ap_child_init_hook(apr_pool_t *pchild, server_rec *s)
1720 /* TODO: uh this seems ugly, is there a better way? */
1721 /*ap_child_init_alloc(); PUT THIS BACK IN XXXXX */
1723 ap_run_child_init(pchild,s);
1726 /********************************************************************
1727 * Configuration directives are restricted in terms of where they may
1728 * appear in the main configuration files and/or .htaccess files according
1729 * to the bitmask req_override in the command_rec structure.
1730 * If any of the overrides set in req_override are also allowed in the
1731 * context in which the command is read, then the command is allowed.
1732 * The context is determined as follows:
1734 * inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
1735 * within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
1736 * within .htaccess --> override = AllowOverride for current directory;
1738 * the result is, well, a rather confusing set of possibilities for when
1739 * a particular directive is allowed to be used. This procedure prints
1740 * in English where the given (pc) directive can be used.
1742 static void show_overrides(const command_rec *pc, module *pm)
1746 printf("\tAllowed in *.conf ");
1747 if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) ||
1748 ((pc->req_override & RSRC_CONF) &&
1749 ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT)))))
1751 else if (pc->req_override & RSRC_CONF)
1752 printf("only outside <Directory>, <Files> or <Location>");
1754 printf("only inside <Directory>, <Files> or <Location>");
1756 /* Warn if the directive is allowed inside <Directory> or .htaccess
1757 * but module doesn't support per-dir configuration */
1759 if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
1760 printf(" [no per-dir config]");
1762 if (pc->req_override & OR_ALL) {
1763 printf(" and in .htaccess\n\twhen AllowOverride");
1765 if ((pc->req_override & OR_ALL) == OR_ALL)
1766 printf(" isn't None");
1768 printf(" includes ");
1770 if (pc->req_override & OR_AUTHCFG) {
1773 printf("AuthConfig");
1775 if (pc->req_override & OR_LIMIT) {
1780 if (pc->req_override & OR_OPTIONS) {
1785 if (pc->req_override & OR_FILEINFO) {
1790 if (pc->req_override & OR_INDEXES) {
1800 /* Show the preloaded configuration directives, the help string explaining
1801 * the directive arguments, in what module they are handled, and in
1802 * what parts of the configuration they are allowed. Used for httpd -h.
1804 AP_DECLARE(void) ap_show_directives()
1806 const command_rec *pc;
1809 for (n = 0; ap_loaded_modules[n]; ++n)
1810 for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
1811 printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
1813 printf("\t%s\n", pc->errmsg);
1814 show_overrides(pc, ap_loaded_modules[n]);
1818 /* Show the preloaded module names. Used for httpd -l. */
1819 AP_DECLARE(void) ap_show_modules()
1823 printf("Compiled in modules:\n");
1824 for (n = 0; ap_loaded_modules[n]; ++n)
1825 printf(" %s\n", ap_loaded_modules[n]->name);