config.c revision d936d7dcfc1a35dec2a026d23053f8230301cdff
842ae4bd224140319ae7feec1872b93dfd491143fielding/* ====================================================================
842ae4bd224140319ae7feec1872b93dfd491143fielding * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
842ae4bd224140319ae7feec1872b93dfd491143fielding *
842ae4bd224140319ae7feec1872b93dfd491143fielding * Redistribution and use in source and binary forms, with or without
842ae4bd224140319ae7feec1872b93dfd491143fielding * modification, are permitted provided that the following conditions
842ae4bd224140319ae7feec1872b93dfd491143fielding * are met:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * 1. Redistributions of source code must retain the above copyright
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * notice, this list of conditions and the following disclaimer.
04891cf70e0bfc38bfb027541dc821f04c754ff7nd *
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * 2. Redistributions in binary form must reproduce the above copyright
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * notice, this list of conditions and the following disclaimer in
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * the documentation and/or other materials provided with the
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * distribution.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 3. All advertising materials mentioning features or use of this
3568de757bac0b47256647504c186d17ca272f85rbb * software must display the following acknowledgment:
3568de757bac0b47256647504c186d17ca272f85rbb * "This product includes software developed by the Apache Group
3568de757bac0b47256647504c186d17ca272f85rbb * for use in the Apache HTTP server project (http://www.apache.org/)."
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * 4. The names "Apache Server" and "Apache Group" must not be used to
3568de757bac0b47256647504c186d17ca272f85rbb * endorse or promote products derived from this software without
3568de757bac0b47256647504c186d17ca272f85rbb * prior written permission. For written permission, please contact
3568de757bac0b47256647504c186d17ca272f85rbb * apache@apache.org.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * 5. Products derived from this software may not be called "Apache"
3568de757bac0b47256647504c186d17ca272f85rbb * nor may "Apache" appear in their names without prior written
3568de757bac0b47256647504c186d17ca272f85rbb * permission of the Apache Group.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * 6. Redistributions of any form whatsoever must retain the following
3568de757bac0b47256647504c186d17ca272f85rbb * acknowledgment:
3568de757bac0b47256647504c186d17ca272f85rbb * "This product includes software developed by the Apache Group
3568de757bac0b47256647504c186d17ca272f85rbb * for use in the Apache HTTP server project (http://www.apache.org/)."
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
3568de757bac0b47256647504c186d17ca272f85rbb * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3568de757bac0b47256647504c186d17ca272f85rbb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
3568de757bac0b47256647504c186d17ca272f85rbb * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
3568de757bac0b47256647504c186d17ca272f85rbb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3568de757bac0b47256647504c186d17ca272f85rbb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
3568de757bac0b47256647504c186d17ca272f85rbb * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
3568de757bac0b47256647504c186d17ca272f85rbb * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3568de757bac0b47256647504c186d17ca272f85rbb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3568de757bac0b47256647504c186d17ca272f85rbb * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3568de757bac0b47256647504c186d17ca272f85rbb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3568de757bac0b47256647504c186d17ca272f85rbb * OF THE POSSIBILITY OF SUCH DAMAGE.
3568de757bac0b47256647504c186d17ca272f85rbb * ====================================================================
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * This software consists of voluntary contributions made by many
3568de757bac0b47256647504c186d17ca272f85rbb * individuals on behalf of the Apache Group and was originally based
3568de757bac0b47256647504c186d17ca272f85rbb * on public domain software written at the National Center for
3568de757bac0b47256647504c186d17ca272f85rbb * Supercomputing Applications, University of Illinois, Urbana-Champaign.
3568de757bac0b47256647504c186d17ca272f85rbb * For more information on the Apache Group and the Apache HTTP server
3568de757bac0b47256647504c186d17ca272f85rbb * project, please see <http://www.apache.org/>.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * http_config.c: once was auxillary functions for reading httpd's config
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * file and converting filenames into a namespace
3568de757bac0b47256647504c186d17ca272f85rbb *
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick * Rob McCool
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * Wall-to-wall rewrite for Apache... commands which are part of the
3568de757bac0b47256647504c186d17ca272f85rbb * server core can now be found next door in "http_core.c". Now contains
3568de757bac0b47256647504c186d17ca272f85rbb * general command loop, and functions which do bookkeeping for the new
98fb535f829e2a95aabd82420931f476661fa8e3jorton * Apache config stuff (modules and configuration vectors).
db12cd62083041bf90945eeb90cc40fbd2340797trawick *
db12cd62083041bf90945eeb90cc40fbd2340797trawick * rst
db12cd62083041bf90945eeb90cc40fbd2340797trawick *
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawick */
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawick
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem#define CORE_PRIVATE
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "apr_portable.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "httpd.h"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "http_config.h"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "http_core.h"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "http_log.h" /* for errors in parse_htaccess */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_request.h" /* for default_handler (see invoke_handler) */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "http_main.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_vhost.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "explain.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbbHOOK_STRUCT(
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb HOOK_LINK(header_parser)
3d96ee83babeec32482c9082c9426340cee8c44dwrowe HOOK_LINK(pre_config)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding HOOK_LINK(post_config)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf HOOK_LINK(open_logs)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf HOOK_LINK(child_init)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick)
98fb535f829e2a95aabd82420931f476661fa8e3jorton
f0e395a55abfcad3d2bd7c63470003b08a93d567ndIMPLEMENT_HOOK_RUN_ALL(int,header_parser,(request_rec *r),(r),OK,DECLINED)
f0e395a55abfcad3d2bd7c63470003b08a93d567ndIMPLEMENT_HOOK_VOID(pre_config,(ap_context_t *pconf,ap_context_t *plog,ap_context_t *ptemp),
f0e395a55abfcad3d2bd7c63470003b08a93d567nd (pconf,plog,ptemp))
f0e395a55abfcad3d2bd7c63470003b08a93d567ndIMPLEMENT_HOOK_VOID(post_config,
98fb535f829e2a95aabd82420931f476661fa8e3jorton (ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s),
7cd5419264796cfeaf8215383cf0f89130a81fectrawick (pconf,plog,ptemp,s))
7cd5419264796cfeaf8215383cf0f89130a81fectrawickIMPLEMENT_HOOK_VOID(open_logs,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick (ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s),
7cd5419264796cfeaf8215383cf0f89130a81fectrawick (pconf,plog,ptemp,s))
7cd5419264796cfeaf8215383cf0f89130a81fectrawickIMPLEMENT_HOOK_VOID(child_init,(ap_context_t *pchild, server_rec *s),(pchild,s))
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawickDEF_Explain
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
3568de757bac0b47256647504c186d17ca272f85rbb/****************************************************************
41634f717c623556a16b27b25d7d909a66fe20f8wrowe *
3568de757bac0b47256647504c186d17ca272f85rbb * We begin with the functions which deal with the linked list
3568de757bac0b47256647504c186d17ca272f85rbb * of modules which control just about all of the server operation.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* total_modules is the number of modules that have been linked
3568de757bac0b47256647504c186d17ca272f85rbb * into the server.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
3568de757bac0b47256647504c186d17ca272f85rbbstatic int total_modules = 0;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* dynamic_modules is the number of modules that have been added
3568de757bac0b47256647504c186d17ca272f85rbb * after the pre-loaded ones have been set up. It shouldn't be larger
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * than DYNAMIC_MODULE_LIMIT.
41634f717c623556a16b27b25d7d909a66fe20f8wrowe */
3568de757bac0b47256647504c186d17ca272f85rbbstatic int dynamic_modules = 0;
3568de757bac0b47256647504c186d17ca272f85rbbAPI_VAR_EXPORT module *top_module = NULL;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzAPI_VAR_EXPORT module **ap_loaded_modules=NULL;
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantztypedef int (*handler_func) (request_rec *);
3568de757bac0b47256647504c186d17ca272f85rbbtypedef void *(*dir_maker_func) (ap_context_t *, char *);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantztypedef void *(*merger_func) (ap_context_t *, void *, void *);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Dealing with config vectors. These are associated with per-directory,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * per-server, and per-request configuration, and have a void* pointer for
3568de757bac0b47256647504c186d17ca272f85rbb * each modules. The nature of the structure pointed to is private to the
fc1efab92032301e317f07e1b3a00082d9d71f3frbb * module in question... the core doesn't (and can't) know. However, there
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * are defined interfaces which allow it to create instances of its private
24b534291150023e6b68eca89ddd33e475ccddc0wrowe * per-directory and per-server structures, and to merge the per-directory
3568de757bac0b47256647504c186d17ca272f85rbb * structures of a directory and its subdirectory (producing a new one in
24b534291150023e6b68eca89ddd33e475ccddc0wrowe * which the defaults applying to the base directory have been properly
3568de757bac0b47256647504c186d17ca272f85rbb * overridden).
24b534291150023e6b68eca89ddd33e475ccddc0wrowe */
24b534291150023e6b68eca89ddd33e475ccddc0wrowe
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#ifndef ap_get_module_config
3568de757bac0b47256647504c186d17ca272f85rbbAPI_EXPORT(void *) ap_get_module_config(void *conf_vector, module *m)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz{
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz void **confv = (void **) conf_vector;
3568de757bac0b47256647504c186d17ca272f85rbb return confv[m->module_index];
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz}
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#endif
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#ifndef ap_set_module_config
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzAPI_EXPORT(void) ap_set_module_config(void *conf_vector, module *m, void *val)
3568de757bac0b47256647504c186d17ca272f85rbb{
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz void **confv = (void **) conf_vector;
3568de757bac0b47256647504c186d17ca272f85rbb confv[m->module_index] = val;
3568de757bac0b47256647504c186d17ca272f85rbb}
3568de757bac0b47256647504c186d17ca272f85rbb#endif
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstatic void *create_empty_config(ap_context_t *p)
3568de757bac0b47256647504c186d17ca272f85rbb{
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) *
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz (total_modules + DYNAMIC_MODULE_LIMIT));
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return (void *) conf_vector;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz}
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstatic void *create_default_per_dir_config(ap_context_t *p)
3568de757bac0b47256647504c186d17ca272f85rbb{
3568de757bac0b47256647504c186d17ca272f85rbb void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
3568de757bac0b47256647504c186d17ca272f85rbb module *modp;
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb for (modp = top_module; modp; modp = modp->next) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz dir_maker_func df = modp->create_dir_config;
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb if (df)
3568de757bac0b47256647504c186d17ca272f85rbb conf_vector[modp->module_index] = (*df) (p, NULL);
3568de757bac0b47256647504c186d17ca272f85rbb }
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb return (void *) conf_vector;
3568de757bac0b47256647504c186d17ca272f85rbb}
3fa816e4832a1c70600bdfd6fc5ef60e9f1c18bbsf
397df70abe0bdd78a84fb6c38c02641bcfeadceasfvoid *
397df70abe0bdd78a84fb6c38c02641bcfeadceasf ap_merge_per_dir_configs(ap_context_t *p, void *base, void *new)
397df70abe0bdd78a84fb6c38c02641bcfeadceasf{
397df70abe0bdd78a84fb6c38c02641bcfeadceasf void **conf_vector = (void **) ap_palloc(p, sizeof(void *) * total_modules);
3568de757bac0b47256647504c186d17ca272f85rbb void **base_vector = (void **) base;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding void **new_vector = (void **) new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding module *modp;
3568de757bac0b47256647504c186d17ca272f85rbb
239f998fbee5ac5b114b965bb76e217cce0003edstoddard for (modp = top_module; modp; modp = modp->next) {
78ae889ffe0fdfab72f56c6993b0f302cb48da55rbb merger_func df = modp->merge_dir_config;
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick int i = modp->module_index;
6653a33e820463abd4f81915b7a1eba0f602e200brianp
6653a33e820463abd4f81915b7a1eba0f602e200brianp if (df && new_vector[i])
6653a33e820463abd4f81915b7a1eba0f602e200brianp conf_vector[i] = (*df) (p, base_vector[i], new_vector[i]);
41634f717c623556a16b27b25d7d909a66fe20f8wrowe else
41634f717c623556a16b27b25d7d909a66fe20f8wrowe conf_vector[i] = new_vector[i] ? new_vector[i] : base_vector[i];
6653a33e820463abd4f81915b7a1eba0f602e200brianp }
3568de757bac0b47256647504c186d17ca272f85rbb
6653a33e820463abd4f81915b7a1eba0f602e200brianp return (void *) conf_vector;
6653a33e820463abd4f81915b7a1eba0f602e200brianp}
95e04bdfdb8fbb70158afd18bbf0acc340615d65jorton
64c351fd973428b5bb4c28e983fa86875ea4e60fdougmstatic void *create_server_config(ap_context_t *p, server_rec *s)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick{
36c8049de63c446926139936c3d195330a0539cetrawick void **conf_vector = (void **) ap_pcalloc(p, sizeof(void *) * (total_modules + DYNAMIC_MODULE_LIMIT));
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf module *modp;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
3568de757bac0b47256647504c186d17ca272f85rbb for (modp = top_module; modp; modp = modp->next) {
dd028aa8111afb6534fece555e8c2d408894671etrawick if (modp->create_server_config)
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin conf_vector[modp->module_index] = (*modp->create_server_config) (p, s);
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin }
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin return (void *) conf_vector;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrinstatic void merge_server_configs(ap_context_t *p, void *base, void *virt)
ca53a74f4012a45cbad48e940eddf27d866981f9dougm{
ca53a74f4012a45cbad48e940eddf27d866981f9dougm /* Can reuse the 'virt' vector for the spine of it, since we don't
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * have to deal with the moral equivalent of .htaccess files here...
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin */
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin void **base_vector = (void **) base;
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin void **virt_vector = (void **) virt;
dd028aa8111afb6534fece555e8c2d408894671etrawick module *modp;
dd028aa8111afb6534fece555e8c2d408894671etrawick
6653a33e820463abd4f81915b7a1eba0f602e200brianp for (modp = top_module; modp; modp = modp->next) {
6653a33e820463abd4f81915b7a1eba0f602e200brianp merger_func df = modp->merge_server_config;
6653a33e820463abd4f81915b7a1eba0f602e200brianp int i = modp->module_index;
6653a33e820463abd4f81915b7a1eba0f602e200brianp
6653a33e820463abd4f81915b7a1eba0f602e200brianp if (!virt_vector[i])
6653a33e820463abd4f81915b7a1eba0f602e200brianp virt_vector[i] = base_vector[i];
6653a33e820463abd4f81915b7a1eba0f602e200brianp else if (df)
6653a33e820463abd4f81915b7a1eba0f602e200brianp virt_vector[i] = (*df) (p, base_vector[i], virt_vector[i]);
6653a33e820463abd4f81915b7a1eba0f602e200brianp }
6653a33e820463abd4f81915b7a1eba0f602e200brianp}
6653a33e820463abd4f81915b7a1eba0f602e200brianp
6653a33e820463abd4f81915b7a1eba0f602e200brianpvoid *ap_create_request_config(ap_context_t *p)
6653a33e820463abd4f81915b7a1eba0f602e200brianp{
6653a33e820463abd4f81915b7a1eba0f602e200brianp return create_empty_config(p);
6653a33e820463abd4f81915b7a1eba0f602e200brianp}
6653a33e820463abd4f81915b7a1eba0f602e200brianp
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawickvoid *ap_create_conn_config(ap_context_t *p)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick{
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf return create_empty_config(p);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf}
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfCORE_EXPORT(void *) ap_create_per_dir_config(ap_context_t *p)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick{
239f998fbee5ac5b114b965bb76e217cce0003edstoddard return create_empty_config(p);
3568de757bac0b47256647504c186d17ca272f85rbb}
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/*
185aa71728867671e105178b4c66fbc22b65ae26sf * For speed/efficiency we generate a compact list of all the handlers
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * and wildcard handlers. This means we won't have to scan the entire
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * module list looking for handlers... where we'll find a whole whack
3568de757bac0b47256647504c186d17ca272f85rbb * of NULLs.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbbtypedef struct {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding handler_rec hr;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard size_t len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding} fast_handler_rec;
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic fast_handler_rec *handlers;
3568de757bac0b47256647504c186d17ca272f85rbbstatic fast_handler_rec *wildhandlers;
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstatic void init_handlers(ap_context_t *p)
3568de757bac0b47256647504c186d17ca272f85rbb{
3568de757bac0b47256647504c186d17ca272f85rbb module *modp;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard int nhandlers = 0;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard int nwildhandlers = 0;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz const handler_rec *handp;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz fast_handler_rec *ph, *pw;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard char *starp;
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem for (modp = top_module; modp; modp = modp->next) {
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem if (!modp->handlers)
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem continue;
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem for (handp = modp->handlers; handp->content_type; ++handp) {
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem if (strchr(handp->content_type, '*')) {
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem nwildhandlers ++;
e2de0e939faab767454a164c7d2e8ea710fd1a26sf } else {
e2de0e939faab767454a164c7d2e8ea710fd1a26sf nhandlers ++;
e2de0e939faab767454a164c7d2e8ea710fd1a26sf }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ph = handlers = ap_palloc(p, sizeof(*ph)*(nhandlers + 1));
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard pw = wildhandlers = ap_palloc(p, sizeof(*pw)*(nwildhandlers + 1));
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (modp = top_module; modp; modp = modp->next) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (!modp->handlers)
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton continue;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard for (handp = modp->handlers; handp->content_type; ++handp) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if ((starp = strchr(handp->content_type, '*'))) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard pw->hr.content_type = handp->content_type;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard pw->hr.handler = handp->handler;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz pw->len = starp - handp->content_type;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard pw ++;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard } else {
3568de757bac0b47256647504c186d17ca272f85rbb ph->hr.content_type = handp->content_type;
3568de757bac0b47256647504c186d17ca272f85rbb ph->hr.handler = handp->handler;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick ph->len = strlen(handp->content_type);
7cd5419264796cfeaf8215383cf0f89130a81fectrawick ph ++;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick }
7cd5419264796cfeaf8215383cf0f89130a81fectrawick }
7cd5419264796cfeaf8215383cf0f89130a81fectrawick }
e8f95a682820a599fe41b22977010636be5c2717jim pw->hr.content_type = NULL;
98cd3186185bb28ae6c95a3f159899fcf56a663ftrawick pw->hr.handler = NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ph->hr.content_type = NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ph->hr.handler = NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf}
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawickint ap_invoke_handler(request_rec *r)
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick{
3568de757bac0b47256647504c186d17ca272f85rbb fast_handler_rec *handp;
95e04bdfdb8fbb70158afd18bbf0acc340615d65jorton const char *handler;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm char *p;
397df70abe0bdd78a84fb6c38c02641bcfeadceasf size_t handler_len;
397df70abe0bdd78a84fb6c38c02641bcfeadceasf int result = HTTP_INTERNAL_SERVER_ERROR;
397df70abe0bdd78a84fb6c38c02641bcfeadceasf
397df70abe0bdd78a84fb6c38c02641bcfeadceasf if (r->handler) {
397df70abe0bdd78a84fb6c38c02641bcfeadceasf handler = r->handler;
397df70abe0bdd78a84fb6c38c02641bcfeadceasf handler_len = strlen(handler);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm else {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm handler = r->content_type ? r->content_type : ap_default_type(r);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if ((p = strchr(handler, ';')) != NULL) { /* MIME type arguments */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf while (p > handler && p[-1] == ' ')
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf --p; /* strip trailing spaces */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf handler_len = p - handler;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf }
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf else {
3cbd177a6c885562f9ad0cf11695f044489c881dgregames handler_len = strlen(handler);
3cbd177a6c885562f9ad0cf11695f044489c881dgregames }
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /* Pass one --- direct matches */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf for (handp = handlers; handp->hr.content_type; ++handp) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (handler_len == handp->len
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf && !strncmp(handler, handp->hr.content_type, handler_len)) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf result = (*handp->hr.handler) (r);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames if (result != DECLINED)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return result;
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames }
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames }
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* Pass two --- wildcard matches */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm for (handp = wildhandlers; handp->hr.content_type; ++handp) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (handler_len >= handp->len
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard && !strncmp(handler, handp->hr.content_type, handp->len)) {
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard result = (*handp->hr.handler) (r);
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick if (result != DECLINED)
7cd5419264796cfeaf8215383cf0f89130a81fectrawick return result;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick }
7cd5419264796cfeaf8215383cf0f89130a81fectrawick }
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick if (result == HTTP_INTERNAL_SERVER_ERROR && r->handler && r->filename) {
7cd5419264796cfeaf8215383cf0f89130a81fectrawick ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, r,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick "handler \"%s\" not found for: %s", r->handler, r->filename);
4f017cb91aa6591385966ccaf0c326e6b2f2c2b8sf }
7cd5419264796cfeaf8215383cf0f89130a81fectrawick return HTTP_INTERNAL_SERVER_ERROR;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick}
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawickint g_bDebugHooks;
7cd5419264796cfeaf8215383cf0f89130a81fectrawickconst char *g_szCurrentHookName;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawickstatic void register_hooks(module *m)
7cd5419264796cfeaf8215383cf0f89130a81fectrawick {
7cd5419264796cfeaf8215383cf0f89130a81fectrawick if(m->register_hooks)
4f017cb91aa6591385966ccaf0c326e6b2f2c2b8sf {
7cd5419264796cfeaf8215383cf0f89130a81fectrawick if(getenv("SHOW_HOOKS"))
7cd5419264796cfeaf8215383cf0f89130a81fectrawick {
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard printf("Registering hooks for %s\n",m->name);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz g_bDebugHooks=1;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard g_szCurrentHookName=m->name;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz m->register_hooks();
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/* One-time setup for precompiled modules --- NOT to be done on restart */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardAPI_EXPORT(void) ap_add_module(module *m)
3568de757bac0b47256647504c186d17ca272f85rbb{
7cd5419264796cfeaf8215383cf0f89130a81fectrawick /* This could be called from an AddModule httpd.conf command,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * after the file has been linked and the module structure within it
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * teased out...
7cd5419264796cfeaf8215383cf0f89130a81fectrawick */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick if (m->version != MODULE_MAGIC_NUMBER_MAJOR) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm fprintf(stderr, "%s: module \"%s\" is not compatible with this "
3568de757bac0b47256647504c186d17ca272f85rbb "version of Apache.\n", ap_server_argv0, m->name);
3568de757bac0b47256647504c186d17ca272f85rbb fprintf(stderr, "Please contact the vendor for the correct version.\n");
74fd6d9aeadb9022086259c5c1ae00bc0dda9c9astoddard exit(1);
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp }
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp
3568de757bac0b47256647504c186d17ca272f85rbb if (m->next == NULL) {
3568de757bac0b47256647504c186d17ca272f85rbb m->next = top_module;
83df3fbb3f37cf5337c8793b4559392a672e0696jim top_module = m;
89da6eb70c41422a20e5f871dbf5950140d128abjim }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (m->module_index == -1) {
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf m->module_index = total_modules++;
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf dynamic_modules++;
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf if (dynamic_modules > DYNAMIC_MODULE_LIMIT) {
dcd19776e8e3d73519ffb0201d6dfea67f0aeb3ejim fprintf(stderr, "%s: module \"%s\" could not be loaded, because"
dcd19776e8e3d73519ffb0201d6dfea67f0aeb3ejim " the dynamic\n", ap_server_argv0, m->name);
b5ffe4f30780fb159db08bd9f628980d2a092711sf fprintf(stderr, "module limit was reached. Please increase "
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard "DYNAMIC_MODULE_LIMIT and recompile.\n");
1ce78cf71b5baaf2c1ab48e818cb1f2397df5010trawick exit(1);
36f5cd02b820ec5fef198c08bf29a76b53700181jim }
36f5cd02b820ec5fef198c08bf29a76b53700181jim }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* Some C compilers put a complete path into __FILE__, but we want
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * only the filename (e.g. mod_includes.c). So check for path
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * components (Unix and DOS), and remove them.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (strrchr(m->name, '/'))
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz m->name = 1 + strrchr(m->name, '/');
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (strrchr(m->name, '\\'))
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard m->name = 1 + strrchr(m->name, '\\');
01d315c948a50cb511dbaee108b9571ee9a4d287jim
01d315c948a50cb511dbaee108b9571ee9a4d287jim#ifdef _OSD_POSIX /* __FILE__="*POSIX(/home/martin/apache/src/modules/standard/mod_info.c)" */
01d315c948a50cb511dbaee108b9571ee9a4d287jim /* We cannot fix the string in-place, because it's const */
dd028aa8111afb6534fece555e8c2d408894671etrawick if (m->name[strlen(m->name)-1]==')') {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard char *tmp = strdup(m->name); /* FIXME:memory leak, albeit a small one */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard tmp[strlen(tmp)-1] = '\0';
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard m->name = tmp;
83df3fbb3f37cf5337c8793b4559392a672e0696jim }
83df3fbb3f37cf5337c8793b4559392a672e0696jim#endif /*_OSD_POSIX*/
83df3fbb3f37cf5337c8793b4559392a672e0696jim
3568de757bac0b47256647504c186d17ca272f85rbb /* FIXME: is this the right place to call this? */
3568de757bac0b47256647504c186d17ca272f85rbb register_hooks(m);
3568de757bac0b47256647504c186d17ca272f85rbb}
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/*
f714f1a7002928d785e53e70349700a7f595fee3trawick * remove_module undoes what add_module did. There are some caveats:
f714f1a7002928d785e53e70349700a7f595fee3trawick * when the module is removed, its slot is lost so all the current
3568de757bac0b47256647504c186d17ca272f85rbb * per-dir and per-server configurations are invalid. So we should
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard * only ever call this function when you are invalidating almost
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh * all our current data. I.e. when doing a restart.
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh */
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh
4a13940dc2990df0a798718d3a3f9cf1566c2217bjhAPI_EXPORT(void) ap_remove_module(module *m)
3568de757bac0b47256647504c186d17ca272f85rbb{
3568de757bac0b47256647504c186d17ca272f85rbb module *modp;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim modp = top_module;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (modp == m) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* We are the top module, special case */
3568de757bac0b47256647504c186d17ca272f85rbb top_module = modp->next;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard m->next = NULL;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim else {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* Not the top module, find use. When found modp will
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * point to the module _before_ us in the list
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz while (modp && modp->next != m) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard modp = modp->next;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if (!modp) {
3568de757bac0b47256647504c186d17ca272f85rbb /* Uh-oh, this module doesn't exist */
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, NULL,
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh "Cannot remove module %s: not found in module list",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard m->name);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard return;
3568de757bac0b47256647504c186d17ca272f85rbb }
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh /* Eliminate us from the module list */
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh modp->next = modp->next->next;
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh }
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb m->module_index = -1; /* simulate being unloaded, should
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim * be unnecessary */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard dynamic_modules--;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard total_modules--;
3568de757bac0b47256647504c186d17ca272f85rbb}
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardAPI_EXPORT(void) ap_add_loaded_module(module *mod)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard{
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard module **m;
3568de757bac0b47256647504c186d17ca272f85rbb
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /*
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * Add module pointer to top of chained module list
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ap_add_module(mod);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
3568de757bac0b47256647504c186d17ca272f85rbb /*
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * And module pointer to list of loaded modules
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz *
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * Notes: 1. ap_add_module() would already complain if no more space
3568de757bac0b47256647504c186d17ca272f85rbb * exists for adding a dynamically loaded module
3568de757bac0b47256647504c186d17ca272f85rbb * 2. ap_add_module() accepts double ap_context_t nclusion, so we have
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * to accept this, too.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
3568de757bac0b47256647504c186d17ca272f85rbb for (m = ap_loaded_modules; *m != NULL; m++)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ;
3568de757bac0b47256647504c186d17ca272f85rbb *m++ = mod;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *m = NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf}
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfAPI_EXPORT(void) ap_remove_loaded_module(module *mod)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf{
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf module **m;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf module **m2;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf int done;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Remove module pointer from chained module list
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_remove_module(mod);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Remove module pointer from list of loaded modules
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Note: 1. We cannot determine if the module was successfully
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * removed by ap_remove_module().
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * 2. We have not to complain explicity when the module
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * is not found because ap_remove_module() did it
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * for us already.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf for (m = m2 = ap_loaded_modules, done = 0; *m2 != NULL; m2++) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (*m2 == mod && done == 0)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf done = 1;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf else
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *m++ = *m2;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf }
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *m = NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf}
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfvoid ap_setup_prelinked_modules()
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf{
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf module **m;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf module **m2;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Initialise total_modules variable and module indices
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf total_modules = 0;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf for (m = ap_preloaded_modules; *m != NULL; m++)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf (*m)->module_index = total_modules++;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Initialise list of loaded modules
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_loaded_modules = (module **)malloc(
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf sizeof(module *)*(total_modules+DYNAMIC_MODULE_LIMIT+1));
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (ap_loaded_modules == NULL) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf fprintf(stderr, "Ouch! Out of memory in ap_setup_prelinked_modules()!\n");
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf }
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf for (m = ap_preloaded_modules, m2 = ap_loaded_modules; *m != NULL; )
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *m2++ = *m++;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *m2 = NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Initialize chain of linked (=activate) modules
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf for (m = ap_prelinked_modules; *m != NULL; m++)
3568de757bac0b47256647504c186d17ca272f85rbb ap_add_module(*m);
3568de757bac0b47256647504c186d17ca272f85rbb
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_sort_hooks();
3568de757bac0b47256647504c186d17ca272f85rbb}
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
3568de757bac0b47256647504c186d17ca272f85rbbAPI_EXPORT(const char *) ap_find_module_name(module *m)
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick{
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick return m->name;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick}
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawickAPI_EXPORT(module *) ap_find_linked_module(const char *name)
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick{
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick module *modp;
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick for (modp = top_module; modp; modp = modp->next) {
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick if (strcmp(modp->name, name) == 0)
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick return modp;
beb70d51e435dc36c56a72b6cd83556c04db9283wrowe }
fe6baec9bbcd36f932b71a355120cd7b5a685d6cfielding return NULL;
3568de757bac0b47256647504c186d17ca272f85rbb}
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
3568de757bac0b47256647504c186d17ca272f85rbb/* Add a named module. Returns 1 if module found, 0 otherwise. */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardAPI_EXPORT(int) ap_add_named_module(const char *name)
3568de757bac0b47256647504c186d17ca272f85rbb{
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf module *modp;
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf int i = 0;
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf for (modp = ap_loaded_modules[i]; modp; modp = ap_loaded_modules[++i]) {
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf if (strcmp(modp->name, name) == 0) {
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf /* Only add modules that are not already enabled. */
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf if (modp->next == NULL) {
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf ap_add_module(modp);
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf }
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf return 1;
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf }
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf }
ee3abe0378785ceef4780586ca309ef2ef60f431trawick
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf return 0;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard}
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
8e9734d1a4af74c141e2a0f880bb51bb061fa03atrawick/* Clear the internal list of modules, in preparation for starting over. */
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsfAPI_EXPORT(void) ap_clear_module_list()
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf{
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard module **m = &top_module;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick module **next_m;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick
3568de757bac0b47256647504c186d17ca272f85rbb while (*m) {
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard next_m = &((*m)->next);
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe *m = NULL;
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick m = next_m;
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick }
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /* This is required; so we add it always. */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard ap_add_named_module("http_core.c");
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard}
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/*****************************************************************
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard *
3568de757bac0b47256647504c186d17ca272f85rbb * Resource, access, and .htaccess config files now parsed by a common
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * command loop.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz *
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * Let's begin with the basics; parsing the line and
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * invoking the function...
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstatic const char *invoke_cmd(const command_rec *cmd, cmd_parms *parms,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick void *mconfig, const char *args)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *w, *w2, *w3;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick const char *errmsg;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if ((parms->override & cmd->req_override) == 0)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ap_pstrcat(parms->pool, cmd->name, " not allowed here", NULL);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick parms->info = cmd->cmd_data;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick parms->cmd = cmd;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick switch (cmd->args_how) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick case RAW_ARGS:
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ((const char *(*)(cmd_parms *, void *, const char *))
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz (cmd->func)) (parms, mconfig, args);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz case NO_ARGS:
95e04bdfdb8fbb70158afd18bbf0acc340615d65jorton if (*args != 0)
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick return ap_pstrcat(parms->pool, cmd->name, " takes no arguments",
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm NULL);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm return ((const char *(*)(cmd_parms *, void *))
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick (cmd->func)) (parms, mconfig);
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick case TAKE1:
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm w = ap_getword_conf(parms->pool, &args);
3568de757bac0b47256647504c186d17ca272f85rbb
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (*w == '\0' || *args != 0)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return ap_pstrcat(parms->pool, cmd->name, " takes one argument",
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
e8f95a682820a599fe41b22977010636be5c2717jim return ((const char *(*)(cmd_parms *, void *, const char *))
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm (cmd->func)) (parms, mconfig, w);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz case TAKE2:
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm w = ap_getword_conf(parms->pool, &args);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm w2 = ap_getword_conf(parms->pool, &args);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (*w == '\0' || *w2 == '\0' || *args != 0)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm return ap_pstrcat(parms->pool, cmd->name, " takes two arguments",
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
36c8049de63c446926139936c3d195330a0539cetrawick
36c8049de63c446926139936c3d195330a0539cetrawick return ((const char *(*)(cmd_parms *, void *, const char *,
36c8049de63c446926139936c3d195330a0539cetrawick const char *)) (cmd->func)) (parms, mconfig, w, w2);
36c8049de63c446926139936c3d195330a0539cetrawick
36c8049de63c446926139936c3d195330a0539cetrawick case TAKE12:
36c8049de63c446926139936c3d195330a0539cetrawick
36c8049de63c446926139936c3d195330a0539cetrawick w = ap_getword_conf(parms->pool, &args);
36c8049de63c446926139936c3d195330a0539cetrawick w2 = ap_getword_conf(parms->pool, &args);
e8f95a682820a599fe41b22977010636be5c2717jim
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (*w == '\0' || *args != 0)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm return ap_pstrcat(parms->pool, cmd->name, " takes 1-2 arguments",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
36c8049de63c446926139936c3d195330a0539cetrawick return ((const char *(*)(cmd_parms *, void *, const char *,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick const char *)) (cmd->func)) (parms, mconfig, w,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *w2 ? w2 : NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick case TAKE3:
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe
36c8049de63c446926139936c3d195330a0539cetrawick w = ap_getword_conf(parms->pool, &args);
36c8049de63c446926139936c3d195330a0539cetrawick w2 = ap_getword_conf(parms->pool, &args);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w3 = ap_getword_conf(parms->pool, &args);
e8f95a682820a599fe41b22977010636be5c2717jim
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (*w == '\0' || *w2 == '\0' || *w3 == '\0' || *args != 0)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ap_pstrcat(parms->pool, cmd->name, " takes three arguments",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ((const char *(*)(cmd_parms *, void *, const char *,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick const char *, const char *)) (cmd->func)) (parms,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick mconfig, w, w2, w3);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick case TAKE23:
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w = ap_getword_conf(parms->pool, &args);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w2 = ap_getword_conf(parms->pool, &args);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (*w == '\0' || *w2 == '\0' || *args != 0)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ap_pstrcat(parms->pool, cmd->name,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick " takes two or three arguments",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ((const char *(*)(cmd_parms *, void *, const char *,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick const char *, const char *)) (cmd->func)) (parms,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick mconfig, w, w2, w3);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick case TAKE123:
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w = ap_getword_conf(parms->pool, &args);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (*w == '\0' || *args != 0)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ap_pstrcat(parms->pool, cmd->name,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick " takes one, two or three arguments",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ((const char *(*)(cmd_parms *, void *, const char *,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick const char *, const char *)) (cmd->func)) (parms,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick mconfig, w, w2, w3);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
e8f95a682820a599fe41b22977010636be5c2717jim case TAKE13:
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
f886987cd0bd4220c14043c4d9be77ec22902e73trawick w = ap_getword_conf(parms->pool, &args);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w2 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick w3 = *args ? ap_getword_conf(parms->pool, &args) : NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
f886987cd0bd4220c14043c4d9be77ec22902e73trawick if (*w == '\0' || (*w2 && !w3) || *args != 0)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm return ap_pstrcat(parms->pool, cmd->name,
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm " takes one or three arguments",
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
3568de757bac0b47256647504c186d17ca272f85rbb return ((const char *(*)(cmd_parms *, void *, const char *,
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim const char *, const char *)) (cmd->func)) (parms,
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim mconfig, w, w2, w3);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick case ITERATE:
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick while (*(w = ap_getword_conf(parms->pool, &args)) != '\0')
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if ((errmsg = ((const char *(*)(cmd_parms *, void *,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick const char *)) (cmd->func)) (parms, mconfig, w)))
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return errmsg;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick case ITERATE2:
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick w = ap_getword_conf(parms->pool, &args);
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton if (*w == '\0' || *args == 0)
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim return ap_pstrcat(parms->pool, cmd->name,
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim " requires at least two arguments",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick cmd->errmsg ? ", " : NULL, cmd->errmsg, NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick while (*(w2 = ap_getword_conf(parms->pool, &args)) != '\0')
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if ((errmsg = ((const char *(*)(cmd_parms *, void *,
36c8049de63c446926139936c3d195330a0539cetrawick const char *, const char *)) (cmd->func)) (parms,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick mconfig, w, w2)))
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return errmsg;
f886987cd0bd4220c14043c4d9be77ec22902e73trawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return NULL;
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick case FLAG:
36c8049de63c446926139936c3d195330a0539cetrawick
36c8049de63c446926139936c3d195330a0539cetrawick w = ap_getword_conf(parms->pool, &args);
36c8049de63c446926139936c3d195330a0539cetrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (*w == '\0' || (strcasecmp(w, "on") && strcasecmp(w, "off")))
e8f95a682820a599fe41b22977010636be5c2717jim return ap_pstrcat(parms->pool, cmd->name, " must be On or Off",
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ((const char *(*)(cmd_parms *, void *, int))
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick (cmd->func)) (parms, mconfig, strcasecmp(w, "off") != 0);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick default:
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return ap_pstrcat(parms->pool, cmd->name,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick " is improperly configured internally (server bug)",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickCORE_EXPORT(const command_rec *) ap_find_command(const char *name, const command_rec *cmds)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick while (cmds->name)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (!strcasecmp(name, cmds->name))
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return cmds;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick else
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick ++cmds;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickCORE_EXPORT(const command_rec *) ap_find_command_in_modules(const char *cmd_name, module **mod)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick const command_rec *cmdp;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick module *modp;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick for (modp = *mod; modp; modp = modp->next)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick if (modp->cmds && (cmdp = ap_find_command(cmd_name, modp->cmds))) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *mod = modp;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return cmdp;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick }
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
e8f95a682820a599fe41b22977010636be5c2717jimCORE_EXPORT(void *) ap_set_config_vectors(cmd_parms *parms, void *config, module *mod)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick void *mconfig = ap_get_module_config(config, mod);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick void *sconfig = ap_get_module_config(parms->server->module_config, mod);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
f886987cd0bd4220c14043c4d9be77ec22902e73trawick if (!mconfig && mod->create_dir_config) {
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick mconfig = (*mod->create_dir_config) (parms->pool, parms->path);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick ap_set_module_config(config, mod, mconfig);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm }
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm if (!sconfig && mod->create_server_config) {
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm sconfig = (*mod->create_server_config) (parms->pool, parms->server);
3568de757bac0b47256647504c186d17ca272f85rbb ap_set_module_config(parms->server->module_config, mod, sconfig);
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim }
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim return mconfig;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
e8f95a682820a599fe41b22977010636be5c2717jim
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickCORE_EXPORT(const char *) ap_handle_command(cmd_parms *parms, void *config, const char *l)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick void *oldconfig;
e8f95a682820a599fe41b22977010636be5c2717jim const char *args, *cmd_name, *retval;
44d2e75323651320b480d8bc2f098448a08de4fcwrowe const command_rec *cmd;
44d2e75323651320b480d8bc2f098448a08de4fcwrowe module *mod = top_module;
44d2e75323651320b480d8bc2f098448a08de4fcwrowe
44d2e75323651320b480d8bc2f098448a08de4fcwrowe if ((l[0] == '#') || (!l[0]))
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim return NULL;
c96bab2ce71bdf8e8b0e0e617ab5f2074ab6e3eejim
44d2e75323651320b480d8bc2f098448a08de4fcwrowe args = l;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim cmd_name = ap_getword_conf(parms->temp_pool, &args);
44d2e75323651320b480d8bc2f098448a08de4fcwrowe if (*cmd_name == '\0')
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return NULL;
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick oldconfig = parms->context;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz parms->context = config;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick do {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (!(cmd = ap_find_command_in_modules(cmd_name, &mod))) {
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe errno = EINVAL;
3568de757bac0b47256647504c186d17ca272f85rbb return ap_pstrcat(parms->pool, "Invalid command '", cmd_name,
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe "', perhaps mis-spelled or defined by a module "
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe "not included in the server configuration", NULL);
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe }
f886987cd0bd4220c14043c4d9be77ec22902e73trawick else {
f886987cd0bd4220c14043c4d9be77ec22902e73trawick void *mconfig = ap_set_config_vectors(parms,config, mod);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick
f886987cd0bd4220c14043c4d9be77ec22902e73trawick retval = invoke_cmd(cmd, parms, mconfig, args);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick mod = mod->next; /* Next time around, skip this one */
f886987cd0bd4220c14043c4d9be77ec22902e73trawick }
f886987cd0bd4220c14043c4d9be77ec22902e73trawick } while (retval && !strcmp(retval, DECLINE_CMD));
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe parms->context = oldconfig;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe return retval;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe}
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzAPI_EXPORT(const char *) ap_srm_command_loop(cmd_parms *parms, void *config)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz char l[MAX_STRING_LEN];
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz while (!(ap_cfg_getline(l, MAX_STRING_LEN, parms->config_file))) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz const char *errmsg = ap_handle_command(parms, config, l);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz if (errmsg) {
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz return errmsg;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
3568de757bac0b47256647504c186d17ca272f85rbb }
3568de757bac0b47256647504c186d17ca272f85rbb
98fb535f829e2a95aabd82420931f476661fa8e3jorton return NULL;
98fb535f829e2a95aabd82420931f476661fa8e3jorton}
e8f95a682820a599fe41b22977010636be5c2717jim
e8f95a682820a599fe41b22977010636be5c2717jim/*
98fb535f829e2a95aabd82420931f476661fa8e3jorton * Generic command functions...
98fb535f829e2a95aabd82420931f476661fa8e3jorton */
e8f95a682820a599fe41b22977010636be5c2717jim
98fb535f829e2a95aabd82420931f476661fa8e3jortonAPI_EXPORT_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
98fb535f829e2a95aabd82420931f476661fa8e3jorton char *struct_ptr, char *arg)
98fb535f829e2a95aabd82420931f476661fa8e3jorton{
3568de757bac0b47256647504c186d17ca272f85rbb /* This one's pretty generic... */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz int offset = (int) (long) cmd->info;
3568de757bac0b47256647504c186d17ca272f85rbb *(char **) (struct_ptr + offset) = arg;
3568de757bac0b47256647504c186d17ca272f85rbb return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingAPI_EXPORT_NONSTD(const char *) ap_set_string_slot_lower(cmd_parms *cmd,
85c5af648e9f414bd4f157490766d2fd5515a9f5rpluem char *struct_ptr, char *arg)
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe{
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe /* This one's pretty generic... */
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe int offset = (int) (long) cmd->info;
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe ap_str_tolower(arg);
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe *(char **) (struct_ptr + offset) = arg;
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe return NULL;
85c5af648e9f414bd4f157490766d2fd5515a9f5rpluem}
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe
3568de757bac0b47256647504c186d17ca272f85rbbAPI_EXPORT_NONSTD(const char *) ap_set_flag_slot(cmd_parms *cmd,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz char *struct_ptr, int arg)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz{
3568de757bac0b47256647504c186d17ca272f85rbb /* This one's pretty generic too... */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz int offset = (int) (long) cmd->info;
3568de757bac0b47256647504c186d17ca272f85rbb *(int *) (struct_ptr + offset) = arg ? 1 : 0;
3568de757bac0b47256647504c186d17ca272f85rbb return NULL;
3568de757bac0b47256647504c186d17ca272f85rbb}
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbAPI_EXPORT_NONSTD(const char *) ap_set_file_slot(cmd_parms *cmd, char *struct_ptr, char *arg)
3568de757bac0b47256647504c186d17ca272f85rbb{
ec020ca384efb30d501a5af796ddc3bb237d7b8fgregames /* Prepend server_root to relative arg.
3568de757bac0b47256647504c186d17ca272f85rbb This allows .htaccess to be independent of server_root,
ce03576b2434cec77f2921db9d5b6a0510581c23rederpj so the server can be moved or mirrored with less pain. */
397df70abe0bdd78a84fb6c38c02641bcfeadceasf char *p;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick int offset = (int) (long) cmd->info;
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick if (ap_os_is_path_absolute(arg))
397df70abe0bdd78a84fb6c38c02641bcfeadceasf p = arg;
397df70abe0bdd78a84fb6c38c02641bcfeadceasf else
397df70abe0bdd78a84fb6c38c02641bcfeadceasf p = ap_make_full_path(cmd->pool, ap_server_root, arg);
397df70abe0bdd78a84fb6c38c02641bcfeadceasf *(char **) (struct_ptr + offset) = p;
397df70abe0bdd78a84fb6c38c02641bcfeadceasf return NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf}
9d0665da83d1e22c0ea0e5f6f940f70f75bf5237ianh
3568de757bac0b47256647504c186d17ca272f85rbb/*****************************************************************
3568de757bac0b47256647504c186d17ca272f85rbb *
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * Reading whole config files...
7cd5419264796cfeaf8215383cf0f89130a81fectrawick */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawickstatic cmd_parms default_parms =
7cd5419264796cfeaf8215383cf0f89130a81fectrawick{NULL, 0, -1, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawickAPI_EXPORT(const char *) ap_server_root_relative(ap_context_t *p, const char *file)
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowe{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if(ap_os_is_path_absolute(file))
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe return file;
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe return ap_make_full_path(p, ap_server_root, file);
3568de757bac0b47256647504c186d17ca272f85rbb}
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick/* This structure and the following functions are needed for the
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * table-based config file reading. They are passed to the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * cfg_open_custom() routine.
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
302dc1f7b3feee23a91ad8f3cf3cb2edd95a557bmanoj/* Structure to be passed to cfg_open_custom(): it contains an
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * index which is incremented from 0 to nelts on each call to
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * cfg_getline() (which in turn calls arr_elts_getstr())
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * and an ap_array_header_t pointer for the string array.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
0cb6873985efbf0cc9644114925df6baa4b32d5awrowetypedef struct {
3568de757bac0b47256647504c186d17ca272f85rbb ap_array_header_t *array;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int curr_idx;
} arr_elts_param_t;
/* arr_elts_getstr() returns the next line from the string array. */
static void *arr_elts_getstr(void *buf, size_t bufsiz, void *param)
{
arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
/* End of array reached? */
if (++arr_param->curr_idx > arr_param->array->nelts)
return NULL;
/* return the line */
ap_cpystrn(buf, ((char **) arr_param->array->elts)[arr_param->curr_idx - 1], bufsiz);
return buf;
}
/* arr_elts_close(): dummy close routine (makes sure no more lines can be read) */
static int arr_elts_close(void *param)
{
arr_elts_param_t *arr_param = (arr_elts_param_t *) param;
arr_param->curr_idx = arr_param->array->nelts;
return 0;
}
static void process_command_config(server_rec *s, ap_array_header_t *arr, ap_context_t *p,
ap_context_t *ptemp)
{
const char *errmsg;
cmd_parms parms;
arr_elts_param_t arr_parms;
arr_parms.curr_idx = 0;
arr_parms.array = arr;
parms = default_parms;
parms.pool = p;
parms.temp_pool = ptemp;
parms.server = s;
parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
parms.config_file = ap_pcfg_open_custom(p, "-c/-C directives",
&arr_parms, NULL,
arr_elts_getstr, arr_elts_close);
errmsg = ap_srm_command_loop(&parms, s->lookup_defaults);
if (errmsg) {
fprintf(stderr, "Syntax error in -C/-c directive:\n%s\n", errmsg);
exit(1);
}
ap_cfg_closefile(parms.config_file);
}
void ap_process_resource_config(server_rec *s, const char *fname, ap_context_t *p, ap_context_t *ptemp)
{
const char *errmsg;
cmd_parms parms;
struct stat finfo;
fname = ap_server_root_relative(p, fname);
if (!(strcmp(fname, ap_server_root_relative(p, RESOURCE_CONFIG_FILE))) ||
!(strcmp(fname, ap_server_root_relative(p, ACCESS_CONFIG_FILE)))) {
if (stat(fname, &finfo) == -1) /* ZZZ can we read the file? ACCESS better here. */
return;
}
/* don't require conf/httpd.conf if we have a -C or -c switch */
if((ap_server_pre_read_config->nelts || ap_server_post_read_config->nelts) &&
!(strcmp(fname, ap_server_root_relative(p, SERVER_CONFIG_FILE)))) {
if (stat(fname, &finfo) == -1) /* ZZZ can we read the file? ACCESS better here. */
return;
}
/* GCC's initialization extensions are soooo nice here... */
parms = default_parms;
parms.pool = p;
parms.temp_pool = ptemp;
parms.server = s;
parms.override = (RSRC_CONF | OR_ALL) & ~(OR_AUTHCFG | OR_LIMIT);
if (!(parms.config_file = ap_pcfg_openfile(p,fname))) {
perror("fopen");
fprintf(stderr, "%s: could not open document config file %s\n",
ap_server_argv0, fname);
exit(1);
}
errmsg = ap_srm_command_loop(&parms, s->lookup_defaults);
if (errmsg) {
fprintf(stderr, "Syntax error on line %d of %s:\n",
parms.config_file->line_number, parms.config_file->name);
fprintf(stderr, "%s\n", errmsg);
exit(1);
}
ap_cfg_closefile(parms.config_file);
}
int ap_parse_htaccess(void **result, request_rec *r, int override,
const char *d, const char *access_name)
{
configfile_t *f = NULL;
cmd_parms parms;
const char *errmsg;
char *filename = NULL;
const struct htaccess_result *cache;
struct htaccess_result *new;
void *dc = NULL;
/* firstly, search cache */
for (cache = r->htaccess; cache != NULL; cache = cache->next)
if (cache->override == override && strcmp(cache->dir, d) == 0) {
if (cache->htaccess != NULL)
*result = cache->htaccess;
return OK;
}
parms = default_parms;
parms.override = override;
parms.pool = r->pool;
parms.temp_pool = r->pool;
parms.server = r->server;
parms.path = ap_pstrdup(r->pool, d);
/* loop through the access names and find the first one */
while (access_name[0]) {
filename = ap_make_full_path(r->pool, d,
ap_getword_conf(r->pool, &access_name));
if ((f = ap_pcfg_openfile(r->pool, filename)) != NULL) {
dc = ap_create_per_dir_config(r->pool);
parms.config_file = f;
errmsg = ap_srm_command_loop(&parms, dc);
ap_cfg_closefile(f);
if (errmsg) {
ap_log_rerror(APLOG_MARK, APLOG_ALERT|APLOG_NOERRNO, r,
"%s: %s", filename, errmsg);
return HTTP_INTERNAL_SERVER_ERROR;
}
*result = dc;
break;
}
else if (errno != ENOENT && errno != ENOTDIR) {
ap_log_rerror(APLOG_MARK, APLOG_CRIT, r,
"%s pcfg_openfile: unable to check htaccess file, "
"ensure it is readable",
filename);
ap_table_setn(r->notes, "error-notes",
"Server unable to read htaccess file, denying "
"access to be safe");
return HTTP_FORBIDDEN;
}
}
/* cache it */
new = ap_palloc(r->pool, sizeof(struct htaccess_result));
new->dir = parms.path;
new->override = override;
new->htaccess = dc;
/* add to head of list */
new->next = r->htaccess;
r->htaccess = new;
return OK;
}
CORE_EXPORT(const char *) ap_init_virtual_host(ap_context_t *p, const char *hostname,
server_rec *main_server, server_rec **ps)
{
server_rec *s = (server_rec *) ap_pcalloc(p, sizeof(server_rec));
#ifdef RLIMIT_NOFILE
struct rlimit limits;
getrlimit(RLIMIT_NOFILE, &limits);
if (limits.rlim_cur < limits.rlim_max) {
limits.rlim_cur += 2;
if (setrlimit(RLIMIT_NOFILE, &limits) < 0) {
perror("setrlimit(RLIMIT_NOFILE)");
fprintf(stderr, "Cannot exceed hard limit for open files");
}
}
#endif
/* TODO: this crap belongs in http_core */
s->server_admin = NULL;
s->server_hostname = NULL;
s->error_fname = NULL;
s->srm_confname = NULL;
s->access_confname = NULL;
s->timeout = 0;
s->keep_alive_timeout = 0;
s->keep_alive = -1;
s->keep_alive_max = -1;
s->error_log = main_server->error_log;
s->loglevel = main_server->loglevel;
/* useful default, otherwise we get a port of 0 on redirects */
s->port = main_server->port;
s->next = NULL;
s->is_virtual = 1;
s->names = ap_make_array(p, 4, sizeof(char **));
s->wild_names = ap_make_array(p, 4, sizeof(char **));
s->module_config = create_empty_config(p);
s->lookup_defaults = ap_create_per_dir_config(p);
#if 0
s->server_uid = ap_user_id;
s->server_gid = ap_group_id;
#endif
s->limit_req_line = main_server->limit_req_line;
s->limit_req_fieldsize = main_server->limit_req_fieldsize;
s->limit_req_fields = main_server->limit_req_fields;
*ps = s;
return ap_parse_vhost_addrs(p, hostname, s);
}
static void fixup_virtual_hosts(ap_context_t *p, server_rec *main_server)
{
server_rec *virt;
for (virt = main_server->next; virt; virt = virt->next) {
merge_server_configs(p, main_server->module_config,
virt->module_config);
virt->lookup_defaults =
ap_merge_per_dir_configs(p, main_server->lookup_defaults,
virt->lookup_defaults);
if (virt->server_admin == NULL)
virt->server_admin = main_server->server_admin;
if (virt->srm_confname == NULL)
virt->srm_confname = main_server->srm_confname;
if (virt->access_confname == NULL)
virt->access_confname = main_server->access_confname;
if (virt->timeout == 0)
virt->timeout = main_server->timeout;
if (virt->keep_alive_timeout == 0)
virt->keep_alive_timeout = main_server->keep_alive_timeout;
if (virt->keep_alive == -1)
virt->keep_alive = main_server->keep_alive;
if (virt->keep_alive_max == -1)
virt->keep_alive_max = main_server->keep_alive_max;
/* XXX: this is really something that should be dealt with by a
* post-config api phase */
ap_core_reorder_directories(p, virt);
}
ap_core_reorder_directories(p, main_server);
}
/*****************************************************************
*
* Getting *everything* configured...
*/
static void init_config_globals(ap_context_t *p)
{
/* Global virtual host hash bucket pointers. Init to null. */
ap_init_vhost_config(p);
}
static server_rec *init_server_config(ap_context_t *p)
{
int errfile = STDERR_FILENO;
server_rec *s = (server_rec *) ap_pcalloc(p, sizeof(server_rec));
s->port = 0;
s->server_admin = DEFAULT_ADMIN;
s->server_hostname = NULL;
s->error_fname = DEFAULT_ERRORLOG;
ap_put_os_file(&s->error_log, &errfile, p);
s->loglevel = DEFAULT_LOGLEVEL;
s->srm_confname = RESOURCE_CONFIG_FILE;
s->access_confname = ACCESS_CONFIG_FILE;
s->limit_req_line = DEFAULT_LIMIT_REQUEST_LINE;
s->limit_req_fieldsize = DEFAULT_LIMIT_REQUEST_FIELDSIZE;
s->limit_req_fields = DEFAULT_LIMIT_REQUEST_FIELDS;
s->timeout = DEFAULT_TIMEOUT; /*ZZZ use AP default timeouts here*/
s->keep_alive_timeout = DEFAULT_KEEPALIVE_TIMEOUT;
s->keep_alive_max = DEFAULT_KEEPALIVE;
s->keep_alive = 1;
s->next = NULL;
s->addrs = ap_pcalloc(p, sizeof(server_addr_rec));
/* NOT virtual host; don't match any real network interface */
/* ZZZ Initialize the Network Address here. */
s->addrs->host_addr.s_addr = htonl(INADDR_ANY);
s->addrs->host_port = 0; /* matches any port */
s->addrs->virthost = ""; /* must be non-NULL */
s->names = s->wild_names = NULL;
s->module_config = create_server_config(p, s);
s->lookup_defaults = create_default_per_dir_config(p);
return s;
}
server_rec *ap_read_config(ap_context_t *p, ap_context_t *ptemp, const char *confname)
{
server_rec *s = init_server_config(p);
init_config_globals(p);
/* All server-wide config files now have the SAME syntax... */
process_command_config(s, ap_server_pre_read_config, p, ptemp);
ap_process_resource_config(s, confname, p, ptemp);
ap_process_resource_config(s, s->srm_confname, p, ptemp);
ap_process_resource_config(s, s->access_confname, p, ptemp);
process_command_config(s, ap_server_post_read_config, p, ptemp);
fixup_virtual_hosts(p, s);
ap_fini_vhost_config(p, s);
return s;
}
void ap_single_module_configure(ap_context_t *p, server_rec *s, module *m)
{
if (m->create_server_config)
ap_set_module_config(s->module_config, m,
(*m->create_server_config)(p, s));
if (m->create_dir_config)
ap_set_module_config(s->lookup_defaults, m,
(*m->create_dir_config)(p, NULL));
}
void ap_post_config_hook(ap_context_t *pconf, ap_context_t *plog, ap_context_t *ptemp, server_rec *s)
{
ap_run_post_config(pconf,plog,ptemp,s);
init_handlers(pconf);
}
void ap_child_init_hook(ap_context_t *pchild, server_rec *s)
{
/* TODO: uh this seems ugly, is there a better way? */
/*ap_child_init_alloc(); PUT THIS BACK IN XXXXX */
ap_run_child_init(pchild,s);
}
/********************************************************************
* Configuration directives are restricted in terms of where they may
* appear in the main configuration files and/or .htaccess files according
* to the bitmask req_override in the command_rec structure.
* If any of the overrides set in req_override are also allowed in the
* context in which the command is read, then the command is allowed.
* The context is determined as follows:
*
* inside *.conf --> override = (RSRC_CONF|OR_ALL)&~(OR_AUTHCFG|OR_LIMIT);
* within <Directory> or <Location> --> override = OR_ALL|ACCESS_CONF;
* within .htaccess --> override = AllowOverride for current directory;
*
* the result is, well, a rather confusing set of possibilities for when
* a particular directive is allowed to be used. This procedure prints
* in English where the given (pc) directive can be used.
*/
static void show_overrides(const command_rec *pc, module *pm)
{
int n = 0;
printf("\tAllowed in *.conf ");
if ((pc->req_override & (OR_OPTIONS | OR_FILEINFO | OR_INDEXES)) ||
((pc->req_override & RSRC_CONF) &&
((pc->req_override & (ACCESS_CONF | OR_AUTHCFG | OR_LIMIT)))))
printf("anywhere");
else if (pc->req_override & RSRC_CONF)
printf("only outside <Directory>, <Files> or <Location>");
else
printf("only inside <Directory>, <Files> or <Location>");
/* Warn if the directive is allowed inside <Directory> or .htaccess
* but module doesn't support per-dir configuration */
if ((pc->req_override & (OR_ALL | ACCESS_CONF)) && !pm->create_dir_config)
printf(" [no per-dir config]");
if (pc->req_override & OR_ALL) {
printf(" and in .htaccess\n\twhen AllowOverride");
if ((pc->req_override & OR_ALL) == OR_ALL)
printf(" isn't None");
else {
printf(" includes ");
if (pc->req_override & OR_AUTHCFG) {
if (n++)
printf(" or ");
printf("AuthConfig");
}
if (pc->req_override & OR_LIMIT) {
if (n++)
printf(" or ");
printf("Limit");
}
if (pc->req_override & OR_OPTIONS) {
if (n++)
printf(" or ");
printf("Options");
}
if (pc->req_override & OR_FILEINFO) {
if (n++)
printf(" or ");
printf("FileInfo");
}
if (pc->req_override & OR_INDEXES) {
if (n++)
printf(" or ");
printf("Indexes");
}
}
}
printf("\n");
}
/* Show the preloaded configuration directives, the help string explaining
* the directive arguments, in what module they are handled, and in
* what parts of the configuration they are allowed. Used for httpd -h.
*/
void ap_show_directives()
{
const command_rec *pc;
int n;
for (n = 0; ap_loaded_modules[n]; ++n)
for (pc = ap_loaded_modules[n]->cmds; pc && pc->name; ++pc) {
printf("%s (%s)\n", pc->name, ap_loaded_modules[n]->name);
if (pc->errmsg)
printf("\t%s\n", pc->errmsg);
show_overrides(pc, ap_loaded_modules[n]);
}
}
/* Show the preloaded module names. Used for httpd -l. */
void ap_show_modules()
{
int n;
printf("Compiled ap_context_t n modules:\n");
for (n = 0; ap_loaded_modules[n]; ++n)
printf(" %s\n", ap_loaded_modules[n]->name);
}