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).
76 #include "ap_config.h"
77 #include "apr_portable.h"
78 #include "apr_strings.h"
79 #include "apr_file_io.h"
81 #include "http_config.h"
82 #include "http_protocol.h"
83 #include "http_core.h"
84 #include "http_log.h" /* for errors in parse_htaccess */
85 #include "http_request.h" /* for default_handler (see invoke_handler) */
86 #include "http_main.h"
87 #include "http_vhost.h"
88 #include "util_cfgtree.h"
89 #ifdef HAVE_ARPA_INET_H
90 #include <arpa/inet.h>
96 AP_DECLARE_DATA const char *ap_server_argv0;
98 AP_DECLARE_DATA const char *ap_server_root;
100 AP_DECLARE_DATA apr_array_header_t *ap_server_pre_read_config;
101 AP_DECLARE_DATA apr_array_header_t *ap_server_post_read_config;
102 AP_DECLARE_DATA apr_array_header_t *ap_server_config_defines;
105 AP_HOOK_LINK(header_parser)
106 AP_HOOK_LINK(pre_config)
107 AP_HOOK_LINK(post_config)
108 AP_HOOK_LINK(open_logs)
109 AP_HOOK_LINK(child_init)
112 AP_IMPLEMENT_HOOK_RUN_ALL(int,header_parser,
113 (request_rec *r),(r),OK,DECLINED)
114 AP_IMPLEMENT_HOOK_VOID(pre_config,
115 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp),
117 AP_IMPLEMENT_HOOK_VOID(post_config,
118 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
119 server_rec *s),(pconf,plog,ptemp,s))
120 AP_IMPLEMENT_HOOK_VOID(open_logs,
121 (apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp,
122 server_rec *s),(pconf,plog,ptemp,s))
123 AP_IMPLEMENT_HOOK_VOID(child_init,
124 (apr_pool_t *pchild, server_rec *s),(pchild,s))
126 /****************************************************************
128 * We begin with the functions which deal with the linked list
129 * of modules which control just about all of the server operation.
132 /* total_modules is the number of modules that have been linked
135 static int total_modules = 0;
136 /* dynamic_modules is the number of modules that have been added
137 * after the pre-loaded ones have been set up. It shouldn't be larger
138 * than DYNAMIC_MODULE_LIMIT.
140 static int dynamic_modules = 0;
141 AP_DECLARE_DATA module *top_module = NULL;
142 AP_DECLARE_DATA module **ap_loaded_modules=NULL;
144 typedef int (*handler_func) (request_rec *);
145 typedef void *(*dir_maker_func) (apr_pool_t *, char *);
146 typedef void *(*merger_func) (apr_pool_t *, void *, void *);
148 /* Dealing with config vectors. These are associated with per-directory,
149 * per-server, and per-request configuration, and have a void* pointer for
150 * each modules. The nature of the structure pointed to is private to the
151 * module in question... the core doesn't (and can't) know. However, there
152 * are defined interfaces which allow it to create instances of its private
153 * per-directory and per-server structures, and to merge the per-directory
154 * structures of a directory and its subdirectory (producing a new one in
155 * which the defaults applying to the base directory have been properly
159 #ifndef ap_get_module_config
160 AP_DECLARE(void *) ap_get_module_config(void *conf_vector, module *m)
162 void **confv = (void **) conf_vector;
163 return confv[m->module_index];
167 #ifndef ap_set_module_config
168 AP_DECLARE(void) ap_set_module_config(void *conf_vector, module *m, void *val)
170 void **confv = (void **) conf_vector;
171 confv[m->module_index] = val;
175 static void *create_empty_config(apr_pool_t *p)
177 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) *
178 (total_modules + DYNAMIC_MODULE_LIMIT));
179 return (void *) conf_vector;
182 static void *create_default_per_dir_config(apr_pool_t *p)
184 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
187 for (modp = top_module; modp; modp = modp->next) {
188 dir_maker_func df = modp->create_dir_config;
191 conf_vector[modp->module_index] = (*df) (p, NULL);
194 return (void *) conf_vector;
198 ap_merge_per_dir_configs(apr_pool_t *p, void *base, void *new)
200 void **conf_vector = (void **) apr_palloc(p, sizeof(void *) * total_modules);
201 void **base_vector = (void **) base;
202 void **new_vector = (void **) new;
205 for (modp = top_module; modp; modp = modp->next) {
206 merger_func df = modp->merge_dir_config;
207 int i = modp->module_index;
209 if (df && new_vector[i])
210 conf_vector[i] = (*df) (p, base_vector[i], new_vector[i]);
212 conf_vector[i] = new_vector[i] ? new_vector[i] : base_vector[i];
215 return (void *) conf_vector;
218 static void *create_server_config(apr_pool_t *p, server_rec *s)
220 void **conf_vector = (void **) apr_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
223 for (modp = top_module; modp; modp = modp->next) {
224 if (modp->create_server_config)
225 conf_vector[modp->module_index] = (*modp->create_server_config) (p, s);
228 return (void *) conf_vector;
231 static void merge_server_configs(apr_pool_t *p, void *base, void *virt)
233 /* Can reuse the 'virt' vector for the spine of it, since we don't
234 * have to deal with the moral equivalent of .htaccess files here...
237 void **base_vector = (void **) base;
238 void **virt_vector = (void **) virt;
241 for (modp = top_module; modp; modp = modp->next) {
242 merger_func df = modp->merge_server_config;
243 int i = modp->module_index;
246 virt_vector[i] = base_vector[i];
248 virt_vector[i] = (*df) (p, base_vector[i], virt_vector[i]);
252 void *ap_create_request_config(apr_pool_t *p)
254 return create_empty_config(p);
257 void *ap_create_conn_config(apr_pool_t *p)
259 return create_empty_config(p);
262 AP_CORE_DECLARE(void *) ap_create_per_dir_config(apr_pool_t *p)
264 return create_empty_config(p);
268 * For speed/efficiency we generate a compact list of all the handlers
269 * and wildcard handlers. This means we won't have to scan the entire
270 * module list looking for handlers... where we'll find a whole whack
278 static fast_handler_rec *handlers;
279 static fast_handler_rec *wildhandlers;
281 static void init_handlers(apr_pool_t *p)
285 int nwildhandlers = 0;
286 const handler_rec *handp;
287 fast_handler_rec *ph, *pw;
290 for (modp = top_module; modp; modp = modp->next) {
293 for (handp = modp->handlers; handp->content_type; ++handp) {
294 if (ap_strchr_c(handp->content_type, '*')) {
301 ph = handlers = apr_palloc(p, sizeof(*ph)*(nhandlers + 1));
302 pw = wildhandlers = apr_palloc(p, sizeof(*pw)*(nwildhandlers + 1));
303 for (modp = top_module; modp; modp = modp->next) {
306 for (handp = modp->handlers; handp->content_type; ++handp) {
307 if ((starp = ap_strchr_c(handp->content_type, '*'))) {
308 pw->hr.content_type = handp->content_type;
309 pw->hr.handler = handp->handler;
310 pw->len = starp - handp->content_type;
313 ph->hr.content_type = handp->content_type;
314 ph->hr.handler = handp->handler;
315 ph->len = strlen(handp->content_type);
320 pw->hr.content_type = NULL;
321 pw->hr.handler = NULL;
322 ph->hr.content_type = NULL;
323 ph->hr.handler = NULL;
326 int ap_invoke_handler(request_rec *r)
328 fast_handler_rec *handp;
332 int result = HTTP_INTERNAL_SERVER_ERROR;
335 handler = r->handler;
336 handler_len = strlen(handler);
339 handler = r->content_type ? r->content_type : ap_default_type(r);
340 if ((p = ap_strchr_c(handler, ';')) != NULL) {
341 /* MIME type arguments */
342 while (p > handler && p[-1] == ' ')
343 --p; /* strip trailing spaces */
344 handler_len = p - handler;
347 handler_len = strlen(handler);
351 /* Pass one --- direct matches */
353 for (handp = handlers; handp->hr.content_type; ++handp) {
354 if (handler_len == handp->len
355 && !strncmp(handler, handp->hr.content_type, handler_len)) {
356 result = (*handp->hr.handler) (r);
358 if (result != DECLINED)
363 /* Pass two --- wildcard matches */
365 for (handp = wildhandlers; handp->hr.content_type; ++handp) {
366 if (handler_len >= handp->len
367 && !strncmp(handler, handp->hr.content_type, handp->len)) {
368 result = (*handp->hr.handler) (r);
370 if (result != DECLINED)
375 if (result == HTTP_INTERNAL_SERVER_ERROR && r->handler && r->filename) {
376 ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, 0, r,
377 "handler \"%s\" not found for: %s", r->handler, r->filename);
379 return HTTP_INTERNAL_SERVER_ERROR;
382 AP_DECLARE(int) ap_method_is_limited(cmd_parms *cmd, const char *method) {
387 methnum = ap_method_number_of(method);
389 * The simple case: a method hard-coded into Apache.
391 if (methnum != M_INVALID) {
392 return (methnum & cmd->limited);
395 * Some extension method we don't know implicitly.
397 if ((cmd->limited_xmethods == NULL)
398 || (cmd->limited_xmethods->nelts == 0)) {
401 xmethod = (char **) cmd->limited_xmethods->elts;
402 for (i = 0; i < cmd->limited_xmethods->nelts; ++i) {
403 if (strcmp(method, xmethod[i]) == 0) {
410 AP_DECLARE(void) ap_register_hooks(module *m)
412 if(m->register_hooks)
414 if(getenv("SHOW_HOOKS"))
416 printf("Registering hooks for %s\n",m->name);
417 ap_debug_module_hooks=1;
419 ap_debug_module_name=m->name;
424 /* One-time setup for precompiled modules --- NOT to be done on restart */
426 AP_DECLARE(void) ap_add_module(module *m)
428 /* This could be called from an AddModule httpd.conf command,
429 * after the file has been linked and the module structure within it
433 if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
434 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
435 "%s: module \"%s\" is not compatible with this "
436 "version of Apache.", ap_server_argv0, m->name);
437 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, "Please contact the vendor for the correct version.");
441 if (m->next == NULL) {
442 m->next = top_module;
445 if (m->module_index == -1) {
446 m->module_index = total_modules++;
449 if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
450 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
451 "%s: module \"%s\" could not be loaded, because"
452 " the dynamic", ap_server_argv0, m->name);
453 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
454 "module limit was reached. Please increase "
455 "DYNAMIC_MODULE_LIMIT and recompile.");
460 /* Some C compilers put a complete path into __FILE__, but we want
461 * only the filename (e.g. mod_includes.c). So check for path
462 * components (Unix and DOS), and remove them.
465 if (ap_strrchr_c(m->name, '/'))
466 m->name = 1 + ap_strrchr_c(m->name, '/');
467 if (ap_strrchr_c(m->name, '\\'))
468 m->name = 1 + ap_strrchr_c(m->name, '\\');
470 #ifdef _OSD_POSIX /* __FILE__="*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */
471 /* We cannot fix the string in-place, because it's const */
472 if (m->name[strlen(m->name)-1]==')') {
473 char *tmp = strdup(m->name); /* FIXME:memory leak, albeit a small one */
474 tmp[strlen(tmp)-1] = '\0';
477 #endif /*_OSD_POSIX*/
479 /* FIXME: is this the right place to call this? */
480 ap_register_hooks(m);
484 * remove_module undoes what add_module did. There are some caveats:
485 * when the module is removed, its slot is lost so all the current
486 * per-dir and per-server configurations are invalid. So we should
487 * only ever call this function when you are invalidating almost
488 * all our current data. I.e. when doing a restart.
491 AP_DECLARE(void) ap_remove_module(module *m)
497 /* We are the top module, special case */
498 top_module = modp->next;
502 /* Not the top module, find use. When found modp will
503 * point to the module _before_ us in the list
506 while (modp && modp->next != m) {
510 /* Uh-oh, this module doesn't exist */
511 ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
512 "Cannot remove module %s: not found in module list",
516 /* Eliminate us from the module list */
517 modp->next = modp->next->next;
520 m->module_index = -1; /* simulate being unloaded, should
526 AP_DECLARE(void) ap_add_loaded_module(module *mod)
531 * Add module pointer to top of chained module list
536 * And module pointer to list of loaded modules
538 * Notes: 1. ap_add_module() would already complain if no more space
539 * exists for adding a dynamically loaded module
540 * 2. ap_add_module() accepts double inclusion, so we have
541 * to accept this, too.
543 for (m = ap_loaded_modules; *m != NULL; m++)
549 AP_DECLARE(void) ap_remove_loaded_module(module *mod)
556 * Remove module pointer from chained module list
558 ap_remove_module(mod);
561 * Remove module pointer from list of loaded modules
563 * Note: 1. We cannot determine if the module was successfully
564 * removed by ap_remove_module().
565 * 2. We have not to complain explicity when the module
566 * is not found because ap_remove_module() did it
569 for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
570 if (*m2 == mod && done == 0)
578 AP_DECLARE(void) ap_setup_prelinked_modules(process_rec *process)
583 ap_global_hook_pool=process->pconf;
586 * Initialise total_modules variable and module indices
589 for (m = ap_preloaded_modules; *m != NULL; m++)
590 (*m)->module_index = total_modules++;
593 * Initialise list of loaded modules
595 ap_loaded_modules = (module **)apr_palloc(process->pool,
596 sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
597 if (ap_loaded_modules == NULL) {
598 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
599 "Ouch! Out of memory in ap_setup_prelinked_modules()!");
601 for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
606 * Initialize chain of linked (=activate) modules
608 for (m = ap_prelinked_modules; *m != NULL; m++)
614 AP_DECLARE(const char *) ap_find_module_name(module *m)
619 AP_DECLARE(module *) ap_find_linked_module(const char *name)
623 for (modp = top_module; modp; modp = modp->next) {
624 if (strcmp(modp->name, name) == 0)
630 /* Add a named module. Returns 1 if module found, 0 otherwise. */
631 AP_DECLARE(int) ap_add_named_module(const char *name)
636 for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) {
637 if (strcmp(modp->name, name) == 0) {
638 /* Only add modules that are not already enabled. */
639 if (modp->next == NULL) {
649 /* Clear the internal list of modules, in preparation for starting over. */
650 AP_DECLARE(void) ap_clear_module_list()
652 module **m = &top_module;
656 next_m = &((*m)->next);
661 /* This is required; so we add it always. */
662 ap_add_named_module("http_core.c");
665 /*****************************************************************
667 * Resource, access, and .htaccess config files now parsed by a common
670 * Let's begin with the basics; parsing the line and
671 * invoking the function...
674 static const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
675 void *mconfig, const char *args)
680 if ((parms->override & cmd->req_override) == 0)
681 return apr_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
683 parms->info = cmd->cmd_data;
686 switch (cmd->args_how) {
688 #ifdef RESOLVE_ENV_PER_TOKEN
689 args = ap_resolve_env(parms->pool,args);
691 return cmd->AP_RAW_ARGS(parms, mconfig, args);
695 return apr_pstrcat(parms->pool, cmd->name, " takes no arguments",
698 return cmd->AP_NO_ARGS(parms, mconfig);
701 w = ap_getword_conf(parms->pool, &args);
703 if (*w == '\0' || *args != 0)
704 return apr_pstrcat(parms->pool, cmd->name, " takes one argument",
705 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
707 return cmd->AP_TAKE1(parms, mconfig, w);
710 w = ap_getword_conf(parms->pool, &args);
711 w2 = ap_getword_conf(parms->pool, &args);
713 if (*w == '\0' || *w2 == '\0' || *args != 0)
714 return apr_pstrcat(parms->pool, cmd->name, " takes two arguments",
715 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
717 return cmd->AP_TAKE2(parms, mconfig, w, w2);
721 w = ap_getword_conf(parms->pool, &args);
722 w2 = ap_getword_conf(parms->pool, &args);
724 if (*w == '\0' || *args != 0)
725 return apr_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
726 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
728 return cmd->AP_TAKE2(parms, mconfig, w, *w2 ? w2 : NULL);
732 w = ap_getword_conf(parms->pool, &args);
733 w2 = ap_getword_conf(parms->pool, &args);
734 w3 = ap_getword_conf(parms->pool, &args);
736 if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
737 return apr_pstrcat(parms->pool, cmd->name, " takes three arguments",
738 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
740 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
744 w = ap_getword_conf(parms->pool, &args);
745 w2 = ap_getword_conf(parms->pool, &args);
746 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
748 if (*w == '\0' || *w2 == '\0' || *args != 0)
749 return apr_pstrcat(parms->pool, cmd->name,
750 " takes two or three arguments",
751 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
753 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
757 w = ap_getword_conf(parms->pool, &args);
758 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
759 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
761 if (*w == '\0' || *args != 0)
762 return apr_pstrcat(parms->pool, cmd->name,
763 " takes one, two or three arguments",
764 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
766 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
770 w = ap_getword_conf(parms->pool, &args);
771 w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
772 w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
774 if (*w == '\0' || (w2 && *w2 && !w3) || *args != 0)
775 return apr_pstrcat(parms->pool, cmd->name,
776 " takes one or three arguments",
777 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
779 return cmd->AP_TAKE3(parms, mconfig, w, w2, w3);
783 while (*(w = ap_getword_conf(parms->pool, &args)) != '\0')
785 if ((errmsg = cmd->AP_TAKE1(parms, mconfig, w)))
793 w = ap_getword_conf(parms->pool, &args);
795 if (*w == '\0' || *args == 0)
796 return apr_pstrcat(parms->pool, cmd->name,
797 " requires at least two arguments",
798 cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
800 while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0')
802 if ((errmsg = cmd->AP_TAKE2(parms, mconfig, w, w2)))
810 w = ap_getword_conf(parms->pool, &args);
812 if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
813 return apr_pstrcat(parms->pool, cmd->name, " must be On or Off",
816 return cmd->AP_FLAG(parms, mconfig, strcasecmp(w, "off") != 0);
820 return apr_pstrcat(parms->pool, cmd->name,
821 " is improperly configured internally (server bug)",
826 AP_CORE_DECLARE(const command_rec *) ap_find_command(const char *name, const command_rec *cmds)
829 if (!strcasecmp(name, cmds->name))
837 AP_CORE_DECLARE(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod)
839 const command_rec *cmdp;
842 for (modp = *mod; modp; modp = modp->next)
843 if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
851 AP_CORE_DECLARE(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod)
853 void *mconfig = ap_get_module_config(config, mod);
854 void *sconfig = ap_get_module_config(parms->server->module_config, mod);
856 if (!mconfig && mod->create_dir_config) {
857 mconfig = (*mod->create_dir_config) (parms->pool, parms->path);
858 ap_set_module_config(config, mod, mconfig);
861 if (!sconfig && mod->create_server_config) {
862 sconfig = (*mod->create_server_config) (parms->pool, parms->server);
863 ap_set_module_config(parms->server->module_config, mod, sconfig);
868 static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms,
869 apr_pool_t *p, apr_pool_t *ptemp,
870 ap_directive_t **sub_tree, ap_directive_t *parent);
872 static const char * ap_build_config_sub(apr_pool_t *p, apr_pool_t *temp_pool,
873 const char *l, cmd_parms *parms,
874 ap_directive_t **current,
875 ap_directive_t **curr_parent,
876 ap_directive_t **conftree)
880 ap_directive_t *newdir;
881 module *mod = top_module;
882 const command_rec *cmd;
884 if (*l == '#' || *l == '\0')
887 #if RESOLVE_ENV_PER_TOKEN
890 args = ap_resolve_env(temp_pool, l);
892 cmd_name = ap_getword_conf(p, &args);
893 if (*cmd_name == '\0') {
894 /* Note: this branch should not occur. An empty line should have
895 * triggered the exit further above.
900 newdir = apr_pcalloc(p, sizeof(ap_directive_t));
901 newdir->filename = parms->config_file->name;
902 newdir->line_num = parms->config_file->line_number;
903 newdir->directive = cmd_name;
904 newdir->args = apr_pstrdup(p, args);
906 if ((cmd = ap_find_command_in_modules(cmd_name, &mod)) != NULL) {
907 if (cmd->req_override & EXEC_ON_READ) {
909 ap_directive_t *sub_tree = NULL;
911 parms->err_directive = newdir;
912 retval = execute_now(cmd_name, args, parms, p, temp_pool,
913 &sub_tree, *curr_parent);
915 (*current)->next = sub_tree;
918 (*current) = sub_tree;
920 (*curr_parent)->first_child = (*current);
923 (*current)->parent = (*curr_parent);
928 /* Before walking *current to the end of the list,
929 * set the head to *current.
931 *conftree = *current;
933 while ((*current)->next != NULL) {
934 (*current) = (*current)->next;
935 (*current)->parent = (*curr_parent);
942 if (cmd_name[0] == '<') {
943 if (cmd_name[1] != '/') {
944 (*current) = ap_add_node(curr_parent, *current, newdir, 1);
946 else if (*curr_parent == NULL) {
947 parms->err_directive = newdir;
948 return apr_pstrcat(p, cmd_name,
949 " without matching <", cmd_name + 2,
953 char *bracket = cmd_name + strlen(cmd_name) - 1;
955 if (*bracket != '>') {
956 return apr_pstrcat(p, cmd_name,
957 "> directive missing closing '>'", NULL);
960 if (strcasecmp(cmd_name + 2,
961 (*curr_parent)->directive + 1) != 0) {
962 return apr_pstrcat(p, "Expected </",
963 (*curr_parent)->directive + 1, "> but saw ",
964 cmd_name, ">", NULL);
968 /* done with this section; move up a level */
969 *current = *curr_parent;
970 *curr_parent = (*current)->parent;
974 *current = ap_add_node(curr_parent, *current, newdir, 0);
980 const char *ap_build_cont_config(apr_pool_t *p, apr_pool_t *temp_pool,
982 ap_directive_t **current,
983 ap_directive_t **curr_parent,
984 char *orig_directive)
986 char l[MAX_STRING_LEN];
989 ap_directive_t *conftree = NULL;
991 bracket = apr_pstrcat(p, orig_directive + 1, ">", NULL);
992 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
993 if (!memcmp(l, "</", 2) &&
994 (strcasecmp(l + 2, bracket) == 0) &&
995 (*curr_parent == NULL)) {
998 retval = ap_build_config_sub(p, temp_pool, l, parms, current,
999 curr_parent, &conftree);
1002 if (conftree == NULL && curr_parent != NULL) {
1003 conftree = *curr_parent;
1005 if (conftree == NULL && current != NULL) {
1006 conftree = *current;
1009 *current = conftree;
1013 static const char *ap_walk_config_sub(const ap_directive_t *current,
1014 cmd_parms *parms, void *config)
1016 module *mod = top_module;
1019 const command_rec *cmd;
1021 if (!(cmd = ap_find_command_in_modules(current->directive, &mod))) {
1022 parms->err_directive = current;
1023 return apr_pstrcat(parms->pool, "Invalid command '",
1025 "', perhaps mis-spelled or defined by a module "
1026 "not included in the server configuration",
1030 void *mconfig = ap_set_config_vectors(parms,config, mod);
1033 retval = invoke_cmd(cmd, parms, mconfig, current->args);
1034 if (retval == NULL) {
1037 if (strcmp(retval, DECLINE_CMD) != 0) {
1038 /* If the directive in error has already been set, don't
1039 * replace it. Otherwise, an error inside a container
1040 * will be reported as occuring on the first line of the
1043 if (!parms->err_directive) {
1044 parms->err_directive = current;
1049 mod = mod->next; /* Next time around, skip this one */
1055 AP_DECLARE(const char *) ap_walk_config(ap_directive_t *current,
1056 cmd_parms *parms, void *config)
1058 void *oldconfig = parms->context;
1060 parms->context = config;
1062 /* scan through all directives, executing each one */
1063 for (; current != NULL; current = current->next) {
1066 parms->directive = current;
1068 /* actually parse the command and execute the correct function */
1069 errmsg = ap_walk_config_sub(current, parms, config);
1070 if (errmsg != NULL) {
1071 /* restore the context (just in case) */
1072 parms->context = oldconfig;
1077 parms->context = oldconfig;
1082 AP_DECLARE(const char *) ap_build_config(cmd_parms *parms,
1083 apr_pool_t *p, apr_pool_t *temp_pool,
1084 ap_directive_t **conftree)
1086 ap_directive_t *current = *conftree;
1087 ap_directive_t *curr_parent = NULL;
1088 char l[MAX_STRING_LEN];
1091 if (current != NULL) {
1092 while (current->next) {
1093 current = current->next;
1097 while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
1099 errmsg = ap_build_config_sub(p, temp_pool, l, parms,
1100 ¤t, &curr_parent, conftree);
1104 if (*conftree == NULL && curr_parent != NULL) {
1105 *conftree = curr_parent;
1107 if (*conftree == NULL && current != NULL) {
1108 *conftree = current;
1112 if (curr_parent != NULL) {
1114 while (curr_parent != NULL) {
1115 errmsg = apr_psprintf(p, "%s%s%s:%u: %s> was not closed.",
1117 *errmsg == '\0' ? "" : APR_EOL_STR,
1118 curr_parent->filename,
1119 curr_parent->line_num,
1120 curr_parent->directive);
1121 curr_parent = curr_parent->parent;
1130 * Generic command functions...
1133 AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
1137 /* This one's pretty generic... */
1139 int offset = (int) (long) cmd->info;
1140 *(const char **) ((char *)struct_ptr + offset) = arg;
1144 AP_DECLARE_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
1148 /* This one's pretty generic... */
1149 char *arg=apr_pstrdup(cmd->pool,arg_);
1151 int offset = (int) (long) cmd->info;
1152 ap_str_tolower(arg);
1153 *(char **) ((char *)struct_ptr + offset) = arg;
1157 AP_DECLARE_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
1158 void *struct_ptr_v, int arg)
1160 /* This one's pretty generic too... */
1162 int offset = (int) (long) cmd->info;
1163 char *struct_ptr = (char *)struct_ptr_v;
1164 *(int *) (struct_ptr + offset) = arg ? 1 : 0;
1168 AP_DECLARE_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, char *struct_ptr,
1171 /* Prepend server_root to relative arg.
1172 This allows .htaccess to be independent of server_root,
1173 so the server can be moved or mirrored with less pain. */
1175 int offset = (int) (long) cmd->info;
1176 if (ap_os_is_path_absolute(arg))
1177 p = apr_pstrdup(cmd->pool, arg);
1179 p = ap_make_full_path(cmd->pool, ap_server_root, arg);
1180 *(char **) (struct_ptr + offset) = p;
1184 /*****************************************************************
1186 * Reading whole config files...
1189 static cmd_parms default_parms =
1190 {NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
1192 AP_DECLARE(const char *) ap_server_root_relative(apr_pool_t *p, const char *file)
1194 if(ap_os_is_path_absolute(file))
1196 return ap_make_full_path(p, ap_server_root, file);
1199 AP_DECLARE(const char *) ap_soak_end_container(cmd_parms *cmd, char *directive)
1201 char l[MAX_STRING_LEN];
1205 while(!(ap_cfg_getline(l, MAX_STRING_LEN, cmd->config_file))) {
1206 #if RESOLVE_ENV_PER_TOKEN
1209 args = ap_resolve_env(cmd->temp_pool, l);
1211 cmd_name = ap_getword_conf(cmd->pool, &args);
1212 if (cmd_name[0] == '<') {
1213 if (cmd_name[1] == '/') {
1214 cmd_name[strlen(cmd_name) - 1] = '\0';
1215 if (strcasecmp(cmd_name + 2, directive + 1) != 0) {
1216 return apr_pstrcat(cmd->pool, "Expected </",
1217 directive + 1, "> but saw ",
1218 cmd_name, ">", NULL);
1223 ap_soak_end_container(cmd, cmd_name);
1230 static const char *execute_now(char *cmd_line, const char *args, cmd_parms *parms,
1231 apr_pool_t *p, apr_pool_t *ptemp,
1232 ap_directive_t **sub_tree, ap_directive_t *parent)
1234 module *mod = top_module;
1235 const command_rec *cmd;
1237 if (!(cmd = ap_find_command_in_modules(cmd_line, &mod))) {
1238 return apr_pstrcat(parms->pool, "Invalid command '",
1240 "', perhaps mis-spelled or defined by a module "
1241 "not included in the server configuration",
1245 return invoke_cmd(cmd, parms, sub_tree, args);
1249 /* This structure and the following functions are needed for the
1250 * table-based config file reading. They are passed to the
1251 * cfg_open_custom() routine.
1254 /* Structure to be passed to cfg_open_custom(): it contains an
1255 * index which is incremented from 0 to nelts on each call to
1256 * cfg_getline() (which in turn calls arr_elts_getstr())
1257 * and an apr_array_header_t pointer for the string array.
1260 apr_array_header_t *array;
1265 /* arr_elts_getstr() returns the next line from the string array. */
1266 static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
1268 arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
1270 /* End of array reached? */
1271 if (++arr_param->curr_idx > arr_param->array->nelts)
1274 /* return the line */
1275 apr_cpystrn(buf, ((char **) arr_param->array->elts)[arr_param->curr_idx - 1], bufsiz);
1281 /* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
1282 static int arr_elts_close(void *param)
1284 arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
1285 arr_param->curr_idx = arr_param->array->nelts;
1289 static void process_command_config(server_rec *s, apr_array_header_t *arr,
1290 ap_directive_t **conftree, apr_pool_t *p,
1295 arr_elts_param_t arr_parms;
1297 arr_parms.curr_idx = 0;
1298 arr_parms.array = arr;
1300 parms = default_parms;
1302 parms.temp_pool = ptemp;
1304 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1306 parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
1308 arr_elts_getstr, arr_elts_close);
1310 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1312 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1313 "Syntax error in -C/-c directive:" APR_EOL_STR "%s",
1318 ap_cfg_closefile(parms.config_file);
1325 static int fname_alphasort(const void *fn1, const void *fn2)
1327 const fnames *f1 = fn1;
1328 const fnames *f2 = fn2;
1330 return strcmp(f1->fname,f2->fname);
1333 void ap_process_resource_config(server_rec *s, const char *fname,
1334 ap_directive_t **conftree, apr_pool_t *p,
1342 fname = ap_server_root_relative(p, fname);
1344 /* don't require conf/httpd.conf if we have a -C or -c switch */
1345 if ((ap_server_pre_read_config->nelts
1346 || ap_server_post_read_config->nelts)
1347 && !(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
1348 if (apr_stat(&finfo, fname, p) != APR_SUCCESS)
1353 * here we want to check if the candidate file is really a
1354 * directory, and most definitely NOT a symlink (to prevent
1355 * horrible loops). If so, let's recurse and toss it back into
1358 if (ap_is_rdirectory(fname)) {
1361 apr_array_header_t *candidates = NULL;
1365 * first course of business is to grok all the directory
1366 * entries here and store 'em away. Recall we need full pathnames
1369 fprintf(stderr, "Processing config directory: %s\n", fname);
1370 if (apr_opendir(&dirp, fname, p) != APR_SUCCESS) {
1372 fprintf(stderr, "%s: could not open config directory %s\n",
1373 ap_server_argv0, fname);
1376 candidates = apr_make_array(p, 1, sizeof(fnames));
1377 while (apr_readdir(dirp) == APR_SUCCESS) {
1379 apr_get_dir_filename(&d_name, dirp);
1380 /* strip out '.' and '..' */
1381 if (strcmp(d_name, ".") &&
1382 strcmp(d_name, "..")) {
1383 fnew = (fnames *) apr_push_array(candidates);
1384 fnew->fname = ap_make_full_path(p, fname, d_name);
1388 if (candidates->nelts != 0) {
1389 qsort((void *) candidates->elts, candidates->nelts,
1390 sizeof(fnames), fname_alphasort);
1392 * Now recurse these... we handle errors and subdirectories
1393 * via the recursion, which is nice
1395 for (current = 0; current < candidates->nelts; ++current) {
1396 fnew = &((fnames *) candidates->elts)[current];
1397 fprintf(stderr, " Processing config file: %s\n", fnew->fname);
1398 ap_process_resource_config(s, fnew->fname, conftree, p, ptemp);
1404 /* GCC's initialization extensions are soooo nice here... */
1406 parms = default_parms;
1408 parms.temp_pool = ptemp;
1410 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1412 if (ap_pcfg_openfile(&cfp, p, fname) != APR_SUCCESS) {
1413 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1414 "%s: could not open document config file %s",
1415 ap_server_argv0, fname);
1419 parms.config_file = cfp;
1421 errmsg = ap_build_config(&parms, p, ptemp, conftree);
1423 if (errmsg != NULL) {
1424 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1425 "Syntax error on line %d of %s:",
1426 parms.err_directive->line_num,
1427 parms.err_directive->filename);
1428 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1433 ap_cfg_closefile(cfp);
1436 AP_DECLARE(void)ap_process_config_tree(server_rec *s, ap_directive_t *conftree,
1437 apr_pool_t *p, apr_pool_t *ptemp)
1442 parms = default_parms;
1444 parms.temp_pool = ptemp;
1446 parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
1449 errmsg = ap_walk_config(conftree, &parms, s->lookup_defaults);
1451 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1452 "Syntax error on line %d of %s:",
1453 parms.err_directive->line_num,
1454 parms.err_directive->filename);
1455 ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
1461 int ap_parse_htaccess(void **result, request_rec *r, int override,
1462 const char *d, const char *access_name) {
1463 configfile_t *f = NULL;
1465 char *filename = NULL;
1466 const struct htaccess_result *cache;
1467 struct htaccess_result *new;
1469 apr_status_t status;
1471 /* firstly, search cache */
1472 for (cache = r->htaccess; cache != NULL; cache = cache->next)
1473 if (cache->override == override && strcmp(cache->dir, d) == 0) {
1474 if (cache->htaccess != NULL)
1475 *result = cache->htaccess;
1479 parms = default_parms;
1480 parms.override = override;
1481 parms.pool = r->pool;
1482 parms.temp_pool = r->pool;
1483 parms.server = r->server;
1484 parms.path = apr_pstrdup(r->pool, d);
1486 /* loop through the access names and find the first one */
1488 while (access_name[0]) {
1489 filename = ap_make_full_path(r->pool, d,
1490 ap_getword_conf(r->pool, &access_name));
1491 status = ap_pcfg_openfile(&f, r->pool, filename);
1493 if (status == APR_SUCCESS) {
1495 ap_directive_t *conftree = NULL;
1497 dc = ap_create_per_dir_config(r->pool);
1499 parms.config_file = f;
1500 errmsg = ap_build_config(&parms, r->pool, r->pool, &conftree);
1502 errmsg = ap_walk_config(conftree, &parms, dc);
1504 ap_cfg_closefile(f);
1507 ap_log_rerror(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, 0, r,
1508 "%s: %s", filename, errmsg);
1509 return HTTP_INTERNAL_SERVER_ERROR;
1514 if (!APR_STATUS_IS_ENOENT(status) && !APR_STATUS_IS_ENOTDIR(status)) {
1515 ap_log_rerror(APLOG_MARK, APLOG_CRIT, status, r,
1516 "%s pcfg_openfile: unable to check htaccess file, "
1517 "ensure it is readable",
1519 apr_table_setn(r->notes, "error-notes",
1520 "Server unable to read htaccess file, denying "
1521 "access to be safe");
1522 return HTTP_FORBIDDEN;
1528 new = apr_palloc(r->pool, sizeof(struct htaccess_result));
1529 new->dir = parms.path;
1530 new->override = override;
1532 /* add to head of list */
1533 new->next = r->htaccess;
1539 AP_CORE_DECLARE(const char *) ap_init_virtual_host(apr_pool_t *p, const char *hostname,
1540 server_rec *main_server, server_rec **ps)
1542 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1544 /* TODO: this crap belongs in http_core */
1545 s->process = main_server->process;
1546 s->server_admin = NULL;
1547 s->server_hostname = NULL;
1548 s->error_fname = NULL;
1550 s->keep_alive_timeout = 0;
1552 s->keep_alive_max = -1;
1553 s->error_log = main_server->error_log;
1554 s->loglevel = main_server->loglevel;
1555 /* useful default, otherwise we get a port of 0 on redirects */
1556 s->port = main_server->port;
1560 s->names = apr_make_array(p, 4, sizeof(char **));
1561 s->wild_names = apr_make_array(p, 4, sizeof(char **));
1563 s->module_config = create_empty_config(p);
1564 s->lookup_defaults = ap_create_per_dir_config(p);
1566 s->limit_req_line = main_server->limit_req_line;
1567 s->limit_req_fieldsize = main_server->limit_req_fieldsize;
1568 s->limit_req_fields = main_server->limit_req_fields;
1572 return ap_parse_vhost_addrs(p, hostname, s);
1576 AP_DECLARE(void) ap_fixup_virtual_hosts(apr_pool_t *p, server_rec *main_server)
1580 for (virt = main_server->next; virt; virt = virt->next) {
1581 merge_server_configs(p, main_server->module_config,
1582 virt->module_config);
1584 virt->lookup_defaults =
1585 ap_merge_per_dir_configs(p, main_server->lookup_defaults,
1586 virt->lookup_defaults);
1588 if (virt->server_admin == NULL)
1589 virt->server_admin = main_server->server_admin;
1591 if (virt->timeout == 0)
1592 virt->timeout = main_server->timeout;
1594 if (virt->keep_alive_timeout == 0)
1595 virt->keep_alive_timeout = main_server->keep_alive_timeout;
1597 if (virt->keep_alive == -1)
1598 virt->keep_alive = main_server->keep_alive;
1600 if (virt->keep_alive_max == -1)
1601 virt->keep_alive_max = main_server->keep_alive_max;
1603 /* XXX: this is really something that should be dealt with by a
1604 * post-config api phase */
1605 ap_core_reorder_directories(p, virt);
1607 ap_core_reorder_directories(p, main_server);
1610 /*****************************************************************
1612 * Getting *everything* configured...
1615 static void init_config_globals(apr_pool_t *p)
1617 /* Global virtual host hash bucket pointers. Init to null. */
1618 ap_init_vhost_config(p);
1621 static server_rec *init_server_config(process_rec *process, apr_pool_t *p)
1623 server_rec *s = (server_rec *) apr_pcalloc(p, sizeof(server_rec));
1625 apr_open_stderr(&s->error_log, p);
1626 s->process = process;
1628 s->server_admin = DEFAULT_ADMIN;
1629 s->server_hostname = NULL;
1630 s->error_fname = DEFAULT_ERRORLOG;
1631 s->loglevel = DEFAULT_LOGLEVEL;
1632 s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
1633 s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
1634 s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
1635 s->timeout = DEFAULT_TIMEOUT;
1636 s->keep_alive_timeout = DEFAULT_KEEPALIVE_TIMEOUT;
1637 s->keep_alive_max = DEFAULT_KEEPALIVE;
1640 s->addrs = apr_pcalloc(p, sizeof(server_addr_rec));
1641 /* NOT virtual host; don't match any real network interface */
1642 s->addrs->host_addr.s_addr = htonl(INADDR_ANY);
1643 s->addrs->host_port = 0; /* matches any port */
1644 s->addrs->virthost = ""; /* must be non-NULL */
1645 s->names = s->wild_names = NULL;
1647 s->module_config = create_server_config(p, s);
1648 s->lookup_defaults = create_default_per_dir_config(p);
1654 AP_DECLARE(server_rec*) ap_read_config(process_rec *process, apr_pool_t *ptemp,
1655 const char *confname,
1656 ap_directive_t **conftree)
1658 apr_pool_t *p = process->pconf;
1659 server_rec *s = init_server_config(process, p);
1661 init_config_globals(p);
1663 /* All server-wide config files now have the SAME syntax... */
1665 process_command_config(s, ap_server_pre_read_config, conftree,
1668 ap_process_resource_config(s, confname, conftree, p, ptemp);
1670 process_command_config(s, ap_server_post_read_config, conftree,
1676 void ap_single_module_configure(apr_pool_t *p, server_rec *s, module *m)
1678 if (m->create_server_config)
1679 ap_set_module_config(s->module_config, m,
1680 (*m->create_server_config)(p, s));
1681 if (m->create_dir_config)
1682 ap_set_module_config(s->lookup_defaults, m,
1683 (*m->create_dir_config)(p, NULL));
1686 AP_DECLARE(void) ap_run_rewrite_args(process_rec *process)
1690 for (m = top_module; m; m = m->next)
1691 if (m->rewrite_args)
1692 (*m->rewrite_args) (process);
1695 AP_DECLARE(void) ap_post_config_hook(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
1697 ap_run_post_config(pconf,plog,ptemp,s);
1698 init_handlers(pconf);
1701 void ap_child_init_hook(apr_pool_t *pchild, server_rec *s)
1703 /* TODO: uh this seems ugly, is there a better way? */
1704 /*ap_child_init_alloc(); PUT THIS BACK IN XXXXX */
1706 ap_run_child_init(pchild,s);
1709 /********************************************************************
1710 * Configuration directives are restricted in terms of where they may
1711 * appear in the main configuration files and/or .htaccess files according
1712 * to the bitmask req_override in the command_rec structure.
1713 * If any of the overrides set in req_override are also allowed in the
1714 * context in which the command is read, then the command is allowed.
1715 * The context is determined as follows:
1717 * inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
1718 * within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
1719 * within .htaccess --> override = AllowOverride for current directory;
1721 * the result is, well, a rather confusing set of possibilities for when
1722 * a particular directive is allowed to be used. This procedure prints
1723 * in English where the given (pc) directive can be used.
1725 static void show_overrides(const command_rec *pc, module *pm)
1729 printf("\tAllowed in *.conf ");
1730 if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) ||
1731 ((pc->req_override & RSRC_CONF) &&
1732 ((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT)))))
1734 else if (pc->req_override & RSRC_CONF)
1735 printf("only outside <Directory>, <Files> or <Location>");
1737 printf("only inside <Directory>, <Files> or <Location>");
1739 /* Warn if the directive is allowed inside <Directory> or .htaccess
1740 * but module doesn't support per-dir configuration */
1742 if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
1743 printf(" [no per-dir config]");
1745 if (pc->req_override & OR_ALL) {
1746 printf(" and in .htaccess\n\twhen AllowOverride");
1748 if ((pc->req_override & OR_ALL) == OR_ALL)
1749 printf(" isn't None");
1751 printf(" includes ");
1753 if (pc->req_override & OR_AUTHCFG) {
1756 printf("AuthConfig");
1758 if (pc->req_override & OR_LIMIT) {
1763 if (pc->req_override & OR_OPTIONS) {
1768 if (pc->req_override & OR_FILEINFO) {
1773 if (pc->req_override & OR_INDEXES) {
1783 /* Show the preloaded configuration directives, the help string explaining
1784 * the directive arguments, in what module they are handled, and in
1785 * what parts of the configuration they are allowed. Used for httpd -h.
1787 AP_DECLARE(void) ap_show_directives()
1789 const command_rec *pc;
1792 for (n = 0; ap_loaded_modules[n]; ++n)
1793 for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
1794 printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
1796 printf("\t%s\n", pc->errmsg);
1797 show_overrides(pc, ap_loaded_modules[n]);
1801 /* Show the preloaded module names. Used for httpd -l. */
1802 AP_DECLARE(void) ap_show_modules()
1806 printf("Compiled in modules:\n");
1807 for (n = 0; ap_loaded_modules[n]; ++n)
1808 printf(" %s\n", ap_loaded_modules[n]->name);