mod_example_hooks.c revision a9a941ed6ca86039137d64bdc7b1c4fda9d07d12
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * http://www.apache.org/licenses/LICENSE-2.0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * Unless required by applicable law or agreed to in writing, software
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * distributed under the License is distributed on an "AS IS" BASIS,
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * See the License for the specific language governing permissions and
04891cf70e0bfc38bfb027541dc821f04c754ff7nd * limitations under the License.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb * Apache example module. Provide demonstrations of how modules do things.
3568de757bac0b47256647504c186d17ca272f85rbb * It is not meant to be used in a production server. Since it participates
3568de757bac0b47256647504c186d17ca272f85rbb * in all of the processing phases, it could conceivable interfere with
3568de757bac0b47256647504c186d17ca272f85rbb * the proper operation of other modules -- particularly the ones related
3568de757bac0b47256647504c186d17ca272f85rbb * to security.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * In the interest of brevity, all functions and structures internal to
3568de757bac0b47256647504c186d17ca272f85rbb * this module, but which may have counterparts in *real* modules, are
3568de757bac0b47256647504c186d17ca272f85rbb * prefixed with 'x_' instead of 'example_'.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * To use mod_example_hooks, configure the Apache build with
3568de757bac0b47256647504c186d17ca272f85rbb * --enable-example and compile. Set up a <Location> block in your
3568de757bac0b47256647504c186d17ca272f85rbb * configuration file like so:
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * <Location /example>
3568de757bac0b47256647504c186d17ca272f85rbb * SetHandler example-hooks-handler
3568de757bac0b47256647504c186d17ca272f85rbb * </Location>
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * When you look at that location on your server, you will see a backtrace of
3568de757bac0b47256647504c186d17ca272f85rbb * the callbacks that have been invoked up to that point. See the ErrorLog for
3568de757bac0b47256647504c186d17ca272f85rbb * more information on code paths that touch mod_example_hooks.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * IMPORTANT NOTES
3568de757bac0b47256647504c186d17ca272f85rbb * ===============
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * Do NOT use this module on a production server. It attaches itself to every
3568de757bac0b47256647504c186d17ca272f85rbb * phase of the server runtime operations including startup, shutdown and
3568de757bac0b47256647504c186d17ca272f85rbb * request processing, and produces copious amounts of logging data. This will
3568de757bac0b47256647504c186d17ca272f85rbb * negatively affect server performance.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * Do NOT use mod_example_hooks as the basis for your own code. This module
3568de757bac0b47256647504c186d17ca272f85rbb * implements every callback hook offered by the Apache core, and your
3568de757bac0b47256647504c186d17ca272f85rbb * module will almost certainly not have to implement this much. If you
3568de757bac0b47256647504c186d17ca272f85rbb * want a simple module skeleton to start development, use apxs -g.
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * XXX TO DO XXX
3568de757bac0b47256647504c186d17ca272f85rbb * =============
3568de757bac0b47256647504c186d17ca272f85rbb *
3568de757bac0b47256647504c186d17ca272f85rbb * * Enable HTML backtrace entries for more callbacks that are not directly
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * associated with a request
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * * Make sure every callback that posts an HTML backtrace entry does so in the * right category, so nothing gets overwritten
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * * Implement some logic to show what happens in the parent, and what in the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * child(ren)
3568de757bac0b47256647504c186d17ca272f85rbb */
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick
3568de757bac0b47256647504c186d17ca272f85rbb#include "httpd.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "http_config.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "http_core.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "http_log.h"
98fb535f829e2a95aabd82420931f476661fa8e3jorton#include "http_main.h"
db12cd62083041bf90945eeb90cc40fbd2340797trawick#include "http_protocol.h"
db12cd62083041bf90945eeb90cc40fbd2340797trawick#include "http_request.h"
db12cd62083041bf90945eeb90cc40fbd2340797trawick#include "util_script.h"
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawick#include "http_connection.h"
333eac96e4fb7d6901cb75e6ca7bb22b2ccb84cetrawick#ifdef HAVE_UNIX_SUEXEC
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem#include "unixd.h"
3568de757bac0b47256647504c186d17ca272f85rbb#endif
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "scoreboard.h"
3568de757bac0b47256647504c186d17ca272f85rbb#include "mpm_common.h"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#include "apr_strings.h"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include <stdio.h>
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*--------------------------------------------------------------------------*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Data declarations. */
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb/* */
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb/* Here are the static cells and structure declarations private to our */
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/* module. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/*--------------------------------------------------------------------------*/
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick/*
98fb535f829e2a95aabd82420931f476661fa8e3jorton * Sample configuration record. Used for both per-directory and per-server
f0e395a55abfcad3d2bd7c63470003b08a93d567nd * configuration data.
f0e395a55abfcad3d2bd7c63470003b08a93d567nd *
f0e395a55abfcad3d2bd7c63470003b08a93d567nd * It's perfectly reasonable to have two different structures for the two
f0e395a55abfcad3d2bd7c63470003b08a93d567nd * different environments. The same command handlers will be called for
98fb535f829e2a95aabd82420931f476661fa8e3jorton * both, though, so the handlers need to be able to tell them apart. One
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * possibility is for both structures to start with an int which is 0 for
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * one and 1 for the other.
7cd5419264796cfeaf8215383cf0f89130a81fectrawick *
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * Note that while the per-directory and per-server configuration records are
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * available to most of the module handlers, they should be treated as
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * READ-ONLY by all except the command and merge handlers. Sometimes handlers
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * are handed a record that applies to the current location by implication or
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * inheritance, and modifying it will change the rules for other locations.
3568de757bac0b47256647504c186d17ca272f85rbb */
41634f717c623556a16b27b25d7d909a66fe20f8wrowetypedef struct x_cfg {
3568de757bac0b47256647504c186d17ca272f85rbb int cmode; /* Environment to which record applies
3568de757bac0b47256647504c186d17ca272f85rbb * (directory, server, or combination).
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
3568de757bac0b47256647504c186d17ca272f85rbb#define CONFIG_MODE_SERVER 1
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz#define CONFIG_MODE_DIRECTORY 2
3568de757bac0b47256647504c186d17ca272f85rbb#define CONFIG_MODE_COMBO 3 /* Shouldn't ever happen. */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz int local; /* Boolean: "Example" directive declared
3568de757bac0b47256647504c186d17ca272f85rbb * here?
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
3568de757bac0b47256647504c186d17ca272f85rbb int congenital; /* Boolean: did we inherit an "Example"? */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *trace; /* Pointer to trace string. */
41634f717c623556a16b27b25d7d909a66fe20f8wrowe char *loc; /* Location to which this record applies. */
3568de757bac0b47256647504c186d17ca272f85rbb} x_cfg;
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/*
3568de757bac0b47256647504c186d17ca272f85rbb * String pointer to hold the startup trace. No harm working with a global until
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * the server is (may be) multi-threaded.
3568de757bac0b47256647504c186d17ca272f85rbb */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzstatic const char *trace = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * Declare ourselves so the configuration routines can find and know us.
3568de757bac0b47256647504c186d17ca272f85rbb * We'll fill it in at the end of the module.
fc1efab92032301e317f07e1b3a00082d9d71f3frbb */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzmodule AP_MODULE_DECLARE_DATA example_hooks_module;
24b534291150023e6b68eca89ddd33e475ccddc0wrowe
3568de757bac0b47256647504c186d17ca272f85rbb/*--------------------------------------------------------------------------*/
24b534291150023e6b68eca89ddd33e475ccddc0wrowe/* */
3568de757bac0b47256647504c186d17ca272f85rbb/* The following pseudo-prototype declarations illustrate the parameters */
24b534291150023e6b68eca89ddd33e475ccddc0wrowe/* passed to command handlers for the different types of directive */
24b534291150023e6b68eca89ddd33e475ccddc0wrowe/* syntax. If an argument was specified in the directive definition */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* (look for "command_rec" below), it's available to the command handler */
3568de757bac0b47256647504c186d17ca272f85rbb/* via the (void *) info field in the cmd_parms argument passed to the */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* handler (cmd->info for the examples below). */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* */
3568de757bac0b47256647504c186d17ca272f85rbb/*--------------------------------------------------------------------------*/
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/*
3568de757bac0b47256647504c186d17ca272f85rbb * Command handler for a NO_ARGS directive. Declared in the command_rec
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * list with
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * AP_INIT_NO_ARGS("directive", function, mconfig, where, help)
3568de757bac0b47256647504c186d17ca272f85rbb *
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * static const char *handle_NO_ARGS(cmd_parms *cmd, void *mconfig);
3568de757bac0b47256647504c186d17ca272f85rbb */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb * Command handler for a RAW_ARGS directive. The "args" argument is the text
3568de757bac0b47256647504c186d17ca272f85rbb * of the commandline following the directive itself. Declared in the
3568de757bac0b47256647504c186d17ca272f85rbb * command_rec list with
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * AP_INIT_RAW_ARGS("directive", function, mconfig, where, help)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz *
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * static const char *handle_RAW_ARGS(cmd_parms *cmd, void *mconfig,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * const char *args);
3568de757bac0b47256647504c186d17ca272f85rbb */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb * Command handler for a FLAG directive. The single parameter is passed in
3568de757bac0b47256647504c186d17ca272f85rbb * "bool", which is either zero or not for Off or On respectively.
3568de757bac0b47256647504c186d17ca272f85rbb * Declared in the command_rec list with
3568de757bac0b47256647504c186d17ca272f85rbb * AP_INIT_FLAG("directive", function, mconfig, where, help)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz *
3568de757bac0b47256647504c186d17ca272f85rbb * static const char *handle_FLAG(cmd_parms *cmd, void *mconfig, int bool);
3568de757bac0b47256647504c186d17ca272f85rbb */
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb * Command handler for a TAKE1 directive. The single parameter is passed in
3568de757bac0b47256647504c186d17ca272f85rbb * "word1". Declared in the command_rec list with
3568de757bac0b47256647504c186d17ca272f85rbb * AP_INIT_TAKE1("directive", function, mconfig, where, help)
3fa816e4832a1c70600bdfd6fc5ef60e9f1c18bbsf *
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * static const char *handle_TAKE1(cmd_parms *cmd, void *mconfig,
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * char *word1);
397df70abe0bdd78a84fb6c38c02641bcfeadceasf */
397df70abe0bdd78a84fb6c38c02641bcfeadceasf
3568de757bac0b47256647504c186d17ca272f85rbb/*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Command handler for a TAKE2 directive. TAKE2 commands must always have
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * exactly two arguments. Declared in the command_rec list with
3568de757bac0b47256647504c186d17ca272f85rbb * AP_INIT_TAKE2("directive", function, mconfig, where, help)
239f998fbee5ac5b114b965bb76e217cce0003edstoddard *
78ae889ffe0fdfab72f56c6993b0f302cb48da55rbb * static const char *handle_TAKE2(cmd_parms *cmd, void *mconfig,
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick * char *word1, char *word2);
6653a33e820463abd4f81915b7a1eba0f602e200brianp */
6653a33e820463abd4f81915b7a1eba0f602e200brianp
6653a33e820463abd4f81915b7a1eba0f602e200brianp/*
41634f717c623556a16b27b25d7d909a66fe20f8wrowe * Command handler for a TAKE3 directive. Like TAKE2, these must have exactly
41634f717c623556a16b27b25d7d909a66fe20f8wrowe * three arguments, or the parser complains and doesn't bother calling us.
6653a33e820463abd4f81915b7a1eba0f602e200brianp * Declared in the command_rec list with
3568de757bac0b47256647504c186d17ca272f85rbb * AP_INIT_TAKE3("directive", function, mconfig, where, help)
6653a33e820463abd4f81915b7a1eba0f602e200brianp *
6653a33e820463abd4f81915b7a1eba0f602e200brianp * static const char *handle_TAKE3(cmd_parms *cmd, void *mconfig,
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * char *word1, char *word2, char *word3);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm */
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick
36c8049de63c446926139936c3d195330a0539cetrawick/*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Command handler for a TAKE12 directive. These can take either one or two
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * arguments.
3568de757bac0b47256647504c186d17ca272f85rbb * - word2 is a NULL pointer if no second argument was specified.
dd028aa8111afb6534fece555e8c2d408894671etrawick * Declared in the command_rec list with
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * AP_INIT_TAKE12("directive", function, mconfig, where, help)
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin *
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * static const char *handle_TAKE12(cmd_parms *cmd, void *mconfig,
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * char *word1, char *word2);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin/*
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * Command handler for a TAKE123 directive. A TAKE123 directive can be given,
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * as might be expected, one, two, or three arguments.
ca53a74f4012a45cbad48e940eddf27d866981f9dougm * - word2 is a NULL pointer if no second argument was specified.
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * - word3 is a NULL pointer if no third argument was specified.
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * Declared in the command_rec list with
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin * AP_INIT_TAKE123("directive", function, mconfig, where, help)
d90b36a9e6f6ea9a583694f4db5e5edd54a750b3minfrin *
dd028aa8111afb6534fece555e8c2d408894671etrawick * static const char *handle_TAKE123(cmd_parms *cmd, void *mconfig,
dd028aa8111afb6534fece555e8c2d408894671etrawick * char *word1, char *word2, char *word3);
6653a33e820463abd4f81915b7a1eba0f602e200brianp */
6653a33e820463abd4f81915b7a1eba0f602e200brianp
6653a33e820463abd4f81915b7a1eba0f602e200brianp/*
6653a33e820463abd4f81915b7a1eba0f602e200brianp * Command handler for a TAKE13 directive. Either one or three arguments are
6653a33e820463abd4f81915b7a1eba0f602e200brianp * permitted - no two-parameters-only syntax is allowed.
6653a33e820463abd4f81915b7a1eba0f602e200brianp * - word2 and word3 are NULL pointers if only one argument was specified.
6653a33e820463abd4f81915b7a1eba0f602e200brianp * Declared in the command_rec list with
6653a33e820463abd4f81915b7a1eba0f602e200brianp * AP_INIT_TAKE13("directive", function, mconfig, where, help)
6653a33e820463abd4f81915b7a1eba0f602e200brianp *
6653a33e820463abd4f81915b7a1eba0f602e200brianp * static const char *handle_TAKE13(cmd_parms *cmd, void *mconfig,
6653a33e820463abd4f81915b7a1eba0f602e200brianp * char *word1, char *word2, char *word3);
6653a33e820463abd4f81915b7a1eba0f602e200brianp */
6653a33e820463abd4f81915b7a1eba0f602e200brianp
6653a33e820463abd4f81915b7a1eba0f602e200brianp/*
6653a33e820463abd4f81915b7a1eba0f602e200brianp * Command handler for a TAKE23 directive. At least two and as many as three
6653a33e820463abd4f81915b7a1eba0f602e200brianp * arguments must be specified.
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick * - word3 is a NULL pointer if no third argument was specified.
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick * Declared in the command_rec list with
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * AP_INIT_TAKE23("directive", function, mconfig, where, help)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * static const char *handle_TAKE23(cmd_parms *cmd, void *mconfig,
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * char *word1, char *word2, char *word3);
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick */
239f998fbee5ac5b114b965bb76e217cce0003edstoddard
3568de757bac0b47256647504c186d17ca272f85rbb/*
3568de757bac0b47256647504c186d17ca272f85rbb * Command handler for a ITERATE directive.
3568de757bac0b47256647504c186d17ca272f85rbb * - Handler is called once for each of n arguments given to the directive.
185aa71728867671e105178b4c66fbc22b65ae26sf * - word1 points to each argument in turn.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Declared in the command_rec list with
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * AP_INIT_ITERATE("directive", function, mconfig, where, help)
3568de757bac0b47256647504c186d17ca272f85rbb *
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * static const char *handle_ITERATE(cmd_parms *cmd, void *mconfig,
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb * char *word1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton * Command handler for a ITERATE2 directive.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * - Handler is called once for each of the second and subsequent arguments
3568de757bac0b47256647504c186d17ca272f85rbb * given to the directive.
3568de757bac0b47256647504c186d17ca272f85rbb * - word1 is the same for each call for a particular directive instance (the
3568de757bac0b47256647504c186d17ca272f85rbb * first argument).
3568de757bac0b47256647504c186d17ca272f85rbb * - word2 points to each of the second and subsequent arguments in turn.
3568de757bac0b47256647504c186d17ca272f85rbb * Declared in the command_rec list with
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * AP_INIT_ITERATE2("directive", function, mconfig, where, help)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard *
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * static const char *handle_ITERATE2(cmd_parms *cmd, void *mconfig,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * char *word1, char *word2);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem/*--------------------------------------------------------------------------*/
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem/* */
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem/* These routines are strictly internal to this module, and support its */
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem/* operation. They are not referenced by any external portion of the */
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem/* server. */
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem/* */
e2de0e939faab767454a164c7d2e8ea710fd1a26sf/*--------------------------------------------------------------------------*/
e2de0e939faab767454a164c7d2e8ea710fd1a26sf
e2de0e939faab767454a164c7d2e8ea710fd1a26sf/*
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Locate our directory configuration record for the current request.
9f979f5c8061f6f6f560d1824e0e378ff5b91931rpluem */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardstatic x_cfg *our_dconfig(const request_rec *r)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard{
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard return (x_cfg *) ap_get_module_config(r->per_dir_config, &example_hooks_module);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard}
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/*
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * The following utility routines are not used in the module. Don't
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * compile them so -Wall doesn't complain about functions that are
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * defined but not used.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard#if 0
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/*
3568de757bac0b47256647504c186d17ca272f85rbb * Locate our server configuration record for the specified server.
3568de757bac0b47256647504c186d17ca272f85rbb */
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawickstatic x_cfg *our_sconfig(const server_rec *s)
7cd5419264796cfeaf8215383cf0f89130a81fectrawick{
7cd5419264796cfeaf8215383cf0f89130a81fectrawick return (x_cfg *) ap_get_module_config(s->module_config, &example_hooks_module);
7cd5419264796cfeaf8215383cf0f89130a81fectrawick}
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
e8f95a682820a599fe41b22977010636be5c2717jim/*
98cd3186185bb28ae6c95a3f159899fcf56a663ftrawick * Likewise for our configuration record for the specified request.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfstatic x_cfg *our_rconfig(const request_rec *r)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf{
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf return (x_cfg *) ap_get_module_config(r->request_config, &example_hooks_module);
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick}
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick#endif /* if 0 */
3568de757bac0b47256647504c186d17ca272f85rbb
a72ba68ecbbc61e4b513e50d6000245c33f753dcwrowe/*
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * Likewise for our configuration record for a connection.
397df70abe0bdd78a84fb6c38c02641bcfeadceasf */
397df70abe0bdd78a84fb6c38c02641bcfeadceasfstatic x_cfg *our_cconfig(const conn_rec *c)
397df70abe0bdd78a84fb6c38c02641bcfeadceasf{
397df70abe0bdd78a84fb6c38c02641bcfeadceasf return (x_cfg *) ap_get_module_config(c->conn_config, &example_hooks_module);
397df70abe0bdd78a84fb6c38c02641bcfeadceasf}
397df70abe0bdd78a84fb6c38c02641bcfeadceasf
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/*
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * You *could* change the following if you wanted to see the calling
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * sequence reported in the server's error_log, but beware - almost all of
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * these co-routines are called for every single request, and the impact
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * on the size (and readability) of the error_log is considerable.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf#ifndef EXAMPLE_LOG_EACH
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf#define EXAMPLE_LOG_EACH 0
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf#endif
3cbd177a6c885562f9ad0cf11695f044489c881dgregames
3cbd177a6c885562f9ad0cf11695f044489c881dgregames#if EXAMPLE_LOG_EACH
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfstatic void example_log_each(apr_pool_t *p, server_rec *s, const char *note)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard{
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf if (s != NULL) {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "mod_example: %s",
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf note);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf } else {
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf apr_file_t *out = NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf apr_file_open_stderr(&out, p);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf apr_file_printf(out, "mod_example traced in non-loggable "
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames "context: %s\n", note);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz }
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames}
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames#endif
5a0f707b48da7703cbe6bc087f13a6735b1c742dgregames
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/*
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * This utility routine traces the hooks called when the server starts up.
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * It leaves a trace in a global variable, so it should not be called from
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * a hook handler that runs in a multi-threaded situation.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard
7cd5419264796cfeaf8215383cf0f89130a81fectrawickstatic void trace_startup(apr_pool_t *p, server_rec *s, x_cfg *mconfig,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick const char *note)
7cd5419264796cfeaf8215383cf0f89130a81fectrawick{
7cd5419264796cfeaf8215383cf0f89130a81fectrawick const char *sofar;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick char *where, *addon;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick#if EXAMPLE_LOG_EACH
7cd5419264796cfeaf8215383cf0f89130a81fectrawick example_log_each(p, s, note);
7cd5419264796cfeaf8215383cf0f89130a81fectrawick#endif
4f017cb91aa6591385966ccaf0c326e6b2f2c2b8sf
7cd5419264796cfeaf8215383cf0f89130a81fectrawick /*
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * If we weren't passed a configuration record, we can't figure out to
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * what location this call applies. This only happens for co-routines
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * that don't operate in a particular directory or server context. If we
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * got a valid record, extract the location (directory or server) to which
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * it applies.
7cd5419264796cfeaf8215383cf0f89130a81fectrawick */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick where = (mconfig != NULL) ? mconfig->loc : "nowhere";
7cd5419264796cfeaf8215383cf0f89130a81fectrawick where = (where != NULL) ? where : "";
4f017cb91aa6591385966ccaf0c326e6b2f2c2b8sf
7cd5419264796cfeaf8215383cf0f89130a81fectrawick addon = apr_pstrcat(p,
7cd5419264796cfeaf8215383cf0f89130a81fectrawick " <li>\n"
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard " <dl>\n"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz " <dt><samp>", note, "</samp></dt>\n"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard " <dd><samp>[", where, "]</samp></dd>\n"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard " </dl>\n"
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz " </li>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard NULL);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /*
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Make sure that we start with a valid string, even if we have never been
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * called.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
3568de757bac0b47256647504c186d17ca272f85rbb sofar = (trace == NULL) ? "" : trace;
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick trace = apr_pstrcat(p, sofar, addon, NULL);
7cd5419264796cfeaf8215383cf0f89130a81fectrawick}
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick/*
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * This utility route traces the hooks called as a request is handled.
3568de757bac0b47256647504c186d17ca272f85rbb * It takes the current request as argument
3568de757bac0b47256647504c186d17ca272f85rbb */
74fd6d9aeadb9022086259c5c1ae00bc0dda9c9astoddard#define TRACE_NOTE "example-hooks-trace"
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianpstatic void trace_request(const request_rec *r, const char *note)
3568de757bac0b47256647504c186d17ca272f85rbb{
3568de757bac0b47256647504c186d17ca272f85rbb const char *trace_copy, *sofar;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard char *addon, *where;
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf x_cfg *cfg;
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf#if EXAMPLE_LOG_EACH
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf example_log_each(r->pool, r->server, note);
ddf3c03e4798f13fe6eea22039864261ea09da18sf#endif
b5ffe4f30780fb159db08bd9f628980d2a092711sf
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard if ((sofar = apr_table_get(r->notes, TRACE_NOTE)) == NULL) {
1ce78cf71b5baaf2c1ab48e818cb1f2397df5010trawick sofar = "";
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard }
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard cfg = our_dconfig(r);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz where = (cfg != NULL) ? cfg->loc : "nowhere";
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard where = (where != NULL) ? where : "";
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz addon = apr_pstrcat(r->pool,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz " <li>\n"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard " <dl>\n"
01d315c948a50cb511dbaee108b9571ee9a4d287jim " <dt><samp>", note, "</samp></dt>\n"
01d315c948a50cb511dbaee108b9571ee9a4d287jim " <dd><samp>[", where, "]</samp></dd>\n"
01d315c948a50cb511dbaee108b9571ee9a4d287jim " </dl>\n"
dd028aa8111afb6534fece555e8c2d408894671etrawick " </li>\n",
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard NULL);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trace_copy = apr_pstrcat(r->pool, sofar, addon, NULL);
3568de757bac0b47256647504c186d17ca272f85rbb apr_table_set(r->notes, TRACE_NOTE, trace_copy);
3568de757bac0b47256647504c186d17ca272f85rbb}
3568de757bac0b47256647504c186d17ca272f85rbb
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard/*
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * This utility routine traces the hooks called while processing a
f714f1a7002928d785e53e70349700a7f595fee3trawick * Connection. Its trace is kept in the pool notes of the pool associated
f714f1a7002928d785e53e70349700a7f595fee3trawick * with the Connection.
3568de757bac0b47256647504c186d17ca272f85rbb */
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh/*
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh * Key to get and set the userdata. We should be able to get away
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh * with a constant key, since in prefork mode the process will have
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh * the connection and its pool to itself entirely, and in
3568de757bac0b47256647504c186d17ca272f85rbb * multi-threaded mode each connection will have its own pool.
3568de757bac0b47256647504c186d17ca272f85rbb */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard#define CONN_NOTE "example-hooks-connection"
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddardstatic void trace_connection(conn_rec *c, const char *note)
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard{
3568de757bac0b47256647504c186d17ca272f85rbb const char *trace_copy, *sofar;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard char *addon, *where;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard void *data;
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim x_cfg *cfg;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard#if EXAMPLE_LOG_EACH
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard example_log_each(c->pool, c->base_server, note);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard#endif
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard cfg = our_cconfig(c);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard where = (cfg != NULL) ? cfg->loc : "nowhere";
3568de757bac0b47256647504c186d17ca272f85rbb where = (where != NULL) ? where : "";
ad83978f20c7d1a4323059d9af122e56fcd353bdstoddard
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh addon = apr_pstrcat(c->pool,
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard " <li>\n"
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard " <dl>\n"
3568de757bac0b47256647504c186d17ca272f85rbb " <dt><samp>", note, "</samp></dt>\n"
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh " <dd><samp>[", where, "]</samp></dd>\n"
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh " </dl>\n"
4a13940dc2990df0a798718d3a3f9cf1566c2217bjh " </li>\n",
3568de757bac0b47256647504c186d17ca272f85rbb NULL);
3568de757bac0b47256647504c186d17ca272f85rbb
663237d6bcc59ac0997d71d48a1baa55fa29a3d8jim /* Find existing notes and copy */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_pool_userdata_get(&data, CONN_NOTE, c->pool);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard sofar = (data == NULL) ? "" : (const char *) data;
3568de757bac0b47256647504c186d17ca272f85rbb
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /* Tack addon onto copy */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard trace_copy = apr_pstrcat(c->pool, sofar, addon, NULL);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /*
3568de757bac0b47256647504c186d17ca272f85rbb * Stash copy back into pool notes. This call has a cleanup
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * parameter, but we're not using it because the string has been
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * allocated from that same pool. There is also an unused return
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * value: we have nowhere to communicate any error that might
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * occur, and will have to check for the existence of this data on
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * the other end.
3568de757bac0b47256647504c186d17ca272f85rbb */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard apr_pool_userdata_set((const void *) trace_copy, CONN_NOTE,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz NULL, c->pool);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz}
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbbstatic void trace_nocontext(apr_pool_t *p, const char *file, int line,
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz const char *note)
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz{
3568de757bac0b47256647504c186d17ca272f85rbb /*
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Since we have no request or connection to trace, or any idea
3568de757bac0b47256647504c186d17ca272f85rbb * from where this routine was called, there's really not much we
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * can do. If we are not logging everything by way of the
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * EXAMPLE_LOG_EACH constant, do nothing in this routine.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf#ifdef EXAMPLE_LOG_EACH
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf ap_log_perror(file, line, APLOG_MODULE_INDEX, APLOG_NOTICE, 0, p, "%s", note);
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf#endif
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf}
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/*--------------------------------------------------------------------------*/
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* We prototyped the various syntax for command handlers (routines that */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* are called when the configuration parser detects a directive declared */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* by our module) earlier. Now we actually declare a "real" routine that */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* will be invoked by the parser when our "real" directive is */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* encountered. */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* If a command handler encounters a problem processing the directive, it */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* signals this fact by returning a non-NULL pointer to a string */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* describing the problem. */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* The magic return value DECLINE_CMD is used to deal with directives */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* that might be declared by multiple modules. If the command handler */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* returns NULL, the directive was processed; if it returns DECLINE_CMD, */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* the next module (if any) that declares the directive is given a chance */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* at it. If it returns any other value, it's treated as the text of an */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/* error message. */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/*--------------------------------------------------------------------------*/
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * Command handler for the NO_ARGS "Example" directive. All we do is mark the
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * call in the trace log, and flag the applicability of the directive to the
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * current location in that location's configuration record.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfstatic const char *cmd_example(cmd_parms *cmd, void *mconfig)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf{
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf x_cfg *cfg = (x_cfg *) mconfig;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf /*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * "Example Wuz Here"
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf cfg->local = 1;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf trace_startup(cmd->pool, cmd->server, cfg, "cmd_example()");
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf return NULL;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf}
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf/*
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * This function gets called to create a per-directory configuration
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * record. This will be called for the "default" server environment, and for
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * each directory for which the parser finds any of our directives applicable.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * If a directory doesn't have any of our directives involved (i.e., they
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * aren't in the .htaccess file, or a <Location>, <Directory>, or related
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * block), this routine will *not* be called - the configuration for the
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * closest ancestor is used.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf *
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * The return value is a pointer to the created module-specific
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * structure.
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf */
49aa87d735a13ae3d04012ee0df91ddb51f7c36esfstatic void *x_create_dir_config(apr_pool_t *p, char *dirspec)
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf{
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf x_cfg *cfg;
3568de757bac0b47256647504c186d17ca272f85rbb char *dname = dirspec;
3568de757bac0b47256647504c186d17ca272f85rbb char *note;
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf
3568de757bac0b47256647504c186d17ca272f85rbb /*
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Allocate the space for our record from the pool supplied.
3568de757bac0b47256647504c186d17ca272f85rbb */
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick cfg = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick /*
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick * Now fill in the defaults. If there are any `parent' configuration
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick * records, they'll get merged as part of a separate callback.
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick */
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick cfg->local = 0;
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick cfg->congenital = 0;
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick cfg->cmode = CONFIG_MODE_DIRECTORY;
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick /*
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick * Finally, add our trace to the callback list.
d69e1ed15b5db3d832c1f6c8c403ef397248857atrawick */
beb70d51e435dc36c56a72b6cd83556c04db9283wrowe dname = (dname != NULL) ? dname : "";
fe6baec9bbcd36f932b71a355120cd7b5a685d6cfielding cfg->loc = apr_pstrcat(p, "DIR(", dname, ")", NULL);
3568de757bac0b47256647504c186d17ca272f85rbb note = apr_psprintf(p, "x_create_dir_config(p == %pp, dirspec == %s)",
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf (void*) p, dirspec);
3568de757bac0b47256647504c186d17ca272f85rbb trace_startup(p, NULL, cfg, note);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard return (void *) cfg;
3568de757bac0b47256647504c186d17ca272f85rbb}
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf/*
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * This function gets called to merge two per-directory configuration
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * records. This is typically done to cope with things like .htaccess files
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * or <Location> directives for directories that are beneath one for which a
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * configuration record was already created. The routine has the
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * responsibility of creating a new record and merging the contents of the
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * other two into it appropriately. If the module doesn't declare a merge
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * routine, the record for the closest ancestor location (that has one) is
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * used exclusively.
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf *
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * The routine MUST NOT modify any of its arguments!
ee3abe0378785ceef4780586ca309ef2ef60f431trawick *
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * The return value is a pointer to the created module-specific structure
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * containing the merged values.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
8e9734d1a4af74c141e2a0f880bb51bb061fa03atrawickstatic void *x_merge_dir_config(apr_pool_t *p, void *parent_conf,
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf void *newloc_conf)
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf{
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick x_cfg *merged_config = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick x_cfg *pconf = (x_cfg *) parent_conf;
3568de757bac0b47256647504c186d17ca272f85rbb x_cfg *nconf = (x_cfg *) newloc_conf;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard char *note;
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick /*
0f113d7123e8bd3e3e2e9b6373461a1a773bfccatrawick * Some things get copied directly from the more-specific record, rather
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * than getting merged.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard merged_config->local = nconf->local;
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard merged_config->loc = apr_pstrdup(p, nconf->loc);
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard /*
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * Others, like the setting of the `congenital' flag, get ORed in. The
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * setting of that particular flag, for instance, is TRUE if it was ever
3568de757bac0b47256647504c186d17ca272f85rbb * true anywhere in the upstream configuration.
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz merged_config->congenital = (pconf->congenital | pconf->local);
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf /*
8dfa8c6f60f12e0b65eebbb652b629f911f0f84bsf * If we're merging records for two different types of environment (server
c0659e61002e9d6ff77b2dca72540e0af1b2ca64stoddard * and directory), mark the new record appropriately. Otherwise, inherit
3568de757bac0b47256647504c186d17ca272f85rbb * the current value.
3568de757bac0b47256647504c186d17ca272f85rbb */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick merged_config->cmode =
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick (pconf->cmode == nconf->cmode) ? pconf->cmode : CONFIG_MODE_COMBO;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Now just record our being called in the trace list. Include the
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * locations we were asked to merge.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick note = apr_psprintf(p, "x_merge_dir_config(p == %pp, parent_conf == "
f886987cd0bd4220c14043c4d9be77ec22902e73trawick "%pp, newloc_conf == %pp)", (void*) p,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick (void*) parent_conf, (void*) newloc_conf);
f886987cd0bd4220c14043c4d9be77ec22902e73trawick trace_startup(p, NULL, merged_config, note);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return (void *) merged_config;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/*
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * This function gets called to create a per-server configuration
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * record. It will always be called for the "default" server.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz *
a72ba68ecbbc61e4b513e50d6000245c33f753dcwrowe * The return value is a pointer to the created module-specific
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick * structure.
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougmstatic void *x_create_server_config(apr_pool_t *p, server_rec *s)
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm{
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick x_cfg *cfg;
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick char *sname = s->server_hostname;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
3568de757bac0b47256647504c186d17ca272f85rbb /*
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * As with the x_create_dir_config() reoutine, we allocate and fill
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * in an empty record.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz cfg = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
e8f95a682820a599fe41b22977010636be5c2717jim cfg->local = 0;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm cfg->congenital = 0;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz cfg->cmode = CONFIG_MODE_SERVER;
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz /*
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * Note that we were called in the trace list.
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm sname = (sname != NULL) ? sname : "";
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm cfg->loc = apr_pstrcat(p, "SVR(", sname, ")", NULL);
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm trace_startup(p, s, cfg, "x_create_server_config()");
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm return (void *) cfg;
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm}
36c8049de63c446926139936c3d195330a0539cetrawick
36c8049de63c446926139936c3d195330a0539cetrawick/*
36c8049de63c446926139936c3d195330a0539cetrawick * This function gets called to merge two per-server configuration
36c8049de63c446926139936c3d195330a0539cetrawick * records. This is typically done to cope with things like virtual hosts and
36c8049de63c446926139936c3d195330a0539cetrawick * the default server configuration The routine has the responsibility of
36c8049de63c446926139936c3d195330a0539cetrawick * creating a new record and merging the contents of the other two into it
36c8049de63c446926139936c3d195330a0539cetrawick * appropriately. If the module doesn't declare a merge routine, the more
36c8049de63c446926139936c3d195330a0539cetrawick * specific existing record is used exclusively.
e8f95a682820a599fe41b22977010636be5c2717jim *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * The routine MUST NOT modify any of its arguments!
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * The return value is a pointer to the created module-specific structure
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * containing the merged values.
36c8049de63c446926139936c3d195330a0539cetrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickstatic void *x_merge_server_config(apr_pool_t *p, void *server1_conf,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick void *server2_conf)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe x_cfg *merged_config = (x_cfg *) apr_pcalloc(p, sizeof(x_cfg));
36c8049de63c446926139936c3d195330a0539cetrawick x_cfg *s1conf = (x_cfg *) server1_conf;
36c8049de63c446926139936c3d195330a0539cetrawick x_cfg *s2conf = (x_cfg *) server2_conf;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *note;
e8f95a682820a599fe41b22977010636be5c2717jim
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Our inheritance rules are our own, and part of our module's semantics.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Basically, just note whence we came.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick merged_config->cmode =
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick (s1conf->cmode == s2conf->cmode) ? s1conf->cmode : CONFIG_MODE_COMBO;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick merged_config->local = s2conf->local;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick merged_config->congenital = (s1conf->congenital | s1conf->local);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick merged_config->loc = apr_pstrdup(p, s2conf->loc);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Trace our call, including what we were asked to merge.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick note = apr_pstrcat(p, "x_merge_server_config(\"", s1conf->loc, "\",\"",
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick s2conf->loc, "\")", NULL);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick trace_startup(p, NULL, merged_config, note);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return (void *) merged_config;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/*--------------------------------------------------------------------------*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Now let's declare routines for each of the callback hooks in order. *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * (That's the order in which they're listed in the callback list, *not *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * the order in which the server calls them! See the command_rec *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * declaration near the bottom of this file.) Note that these may be *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * called for situations that don't relate primarily to our function - in *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * other words, the fixup handler shouldn't assume that the request has *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * to do with "example" stuff. *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * With the exception of the content handler, all of our routines will be *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * called for each request, unless an earlier handler from another module *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * aborted the sequence. *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * There are three types of hooks (see include/ap_config.h): *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * VOID : No return code, run all handlers declared by any module *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * RUN_FIRST : Run all handlers until one returns something other *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * than DECLINED. Hook runner result is result of last callback *
e8f95a682820a599fe41b22977010636be5c2717jim * RUN_ALL : Run all handlers until one returns something other than OK *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * or DECLINED. The hook runner returns that other value. If *
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * all hooks run, the hook runner returns OK. *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * *
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * Handlers that are declared as "int" can return the following: *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * *
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * OK Handler accepted the request and did its thing with it. *
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * DECLINED Handler took no action. *
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * HTTP_mumble Handler looked at request and found it wanting. *
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * *
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * See include/httpd.h for a list of HTTP_mumble status codes. Handlers *
3568de757bac0b47256647504c186d17ca272f85rbb * that are not declared as int return a valid pointer, or NULL if they *
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp * DECLINE to handle their phase for that specific request. Exceptions, if *
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp * any, are noted with each routine. *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *--------------------------------------------------------------------------*/
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * This routine is called before the server processes the configuration
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * files. There is no return value.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickstatic int x_pre_config(apr_pool_t *pconf, apr_pool_t *plog,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_pool_t *ptemp)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Log the call and exit.
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick trace_startup(ptemp, NULL, NULL, "x_pre_config()");
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton
f2e009134c7e279f99dfca5bd421f721bf1f7840jorton return OK;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * This routine is called after the server processes the configuration
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * files. At this point the module may review and adjust its configuration
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick * settings in relation to one another and report any problems. On restart,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * this routine will be called twice, once in the startup process (which
36c8049de63c446926139936c3d195330a0539cetrawick * exits shortly after this phase) and once in the running server process.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * server will still call any remaining modules with an handler for this
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * phase.
cb97ae2ff6969c2789b8e03f1bc4187fa73b6bafwrowe */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickstatic int x_check_config(apr_pool_t *pconf, apr_pool_t *plog,
36c8049de63c446926139936c3d195330a0539cetrawick apr_pool_t *ptemp, server_rec *s)
36c8049de63c446926139936c3d195330a0539cetrawick{
36c8049de63c446926139936c3d195330a0539cetrawick /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Log the call and exit.
e8f95a682820a599fe41b22977010636be5c2717jim */
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm trace_startup(ptemp, s, NULL, "x_check_config()");
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick return OK;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * This routine is called when the -t command-line option is supplied.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * It executes only once, in the startup process, after the check_config
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * phase and just before the process exits. At this point the module
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * may output any information useful in configuration testing.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * This is a VOID hook: all defined handlers get called.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickstatic void x_test_config(apr_pool_t *pconf, server_rec *s)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_file_t *out = NULL;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_file_open_stderr(&out, pconf);
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_file_printf(out, "Example module configuration test routine\n");
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick trace_startup(pconf, s, NULL, "x_test_config()");
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick/*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * This routine is called to perform any module-specific log file
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * openings. It is invoked just before the post_config phase
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick *
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * server will still call any remaining modules with an handler for this
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * phase.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawickstatic int x_open_logs(apr_pool_t *pconf, apr_pool_t *plog,
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick apr_pool_t *ptemp, server_rec *s)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Log the call and exit.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick trace_startup(ptemp, s, NULL, "x_open_logs()");
e8f95a682820a599fe41b22977010636be5c2717jim return OK;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick}
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick
f886987cd0bd4220c14043c4d9be77ec22902e73trawick/*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * This routine is called after the server finishes the configuration
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * process. At this point the module may review and adjust its configuration
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * settings in relation to one another and report any problems. On restart,
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * this routine will be called only once, in the running server process.
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm *
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * server will still call any remaining modules with an handler for this
64c351fd973428b5bb4c28e983fa86875ea4e60fdougm * phase.
3568de757bac0b47256647504c186d17ca272f85rbb */
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianpstatic int x_post_config(apr_pool_t *pconf, apr_pool_t *plog,
72b6f1cf3e616473e1c26464b3193b13c2c09e87brianp apr_pool_t *ptemp, server_rec *s)
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick{
e8f95a682820a599fe41b22977010636be5c2717jim /*
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * Log the call and exit.
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick */
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick trace_startup(ptemp, s, NULL, "x_post_config()");
e8f95a682820a599fe41b22977010636be5c2717jim return OK;
44d2e75323651320b480d8bc2f098448a08de4fcwrowe}
44d2e75323651320b480d8bc2f098448a08de4fcwrowe
44d2e75323651320b480d8bc2f098448a08de4fcwrowe/*
44d2e75323651320b480d8bc2f098448a08de4fcwrowe * All our process-death routine does is add its trace to the log.
44d2e75323651320b480d8bc2f098448a08de4fcwrowe */
44d2e75323651320b480d8bc2f098448a08de4fcwrowestatic apr_status_t x_child_exit(void *data)
44d2e75323651320b480d8bc2f098448a08de4fcwrowe{
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim char *note;
44d2e75323651320b480d8bc2f098448a08de4fcwrowe server_rec *s = data;
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick char *sname = s->server_hostname;
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick
2e7f1d7da527c09e717251e186deffe55e6fbd0ftrawick /*
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * The arbitrary text we add to our trace entry indicates for which server
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * we're being called.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe sname = (sname != NULL) ? sname : "";
3568de757bac0b47256647504c186d17ca272f85rbb note = apr_pstrcat(s->process->pool, "x_child_exit(", sname, ")", NULL);
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe trace_startup(s->process->pool, s, NULL, note);
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe return APR_SUCCESS;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe}
f886987cd0bd4220c14043c4d9be77ec22902e73trawick
f886987cd0bd4220c14043c4d9be77ec22902e73trawick/*
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * All our process initialiser does is add its trace to the log.
f886987cd0bd4220c14043c4d9be77ec22902e73trawick *
f886987cd0bd4220c14043c4d9be77ec22902e73trawick * This is a VOID hook: all defined handlers get called.
f886987cd0bd4220c14043c4d9be77ec22902e73trawick */
f886987cd0bd4220c14043c4d9be77ec22902e73trawickstatic void x_child_init(apr_pool_t *p, server_rec *s)
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe{
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe char *note;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe char *sname = s->server_hostname;
1ec8bd0373f11c07688ec9afbbf778cf78a0bc52wrowe
3568de757bac0b47256647504c186d17ca272f85rbb /*
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * The arbitrary text we add to our trace entry indicates for which server
8bfe865d8d61be4ba4a89e45427a3c4211ebabdctrawick * we're being called.
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
3568de757bac0b47256647504c186d17ca272f85rbb sname = (sname != NULL) ? sname : "";
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz note = apr_pstrcat(p, "x_child_init(", sname, ")", NULL);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz trace_startup(p, s, NULL, note);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz apr_pool_cleanup_register(p, s, x_child_exit, x_child_exit);
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz}
3568de757bac0b47256647504c186d17ca272f85rbb
3568de757bac0b47256647504c186d17ca272f85rbb/*
98fb535f829e2a95aabd82420931f476661fa8e3jorton * The hook runner for ap_hook_http_scheme is aliased to ap_http_scheme(),
98fb535f829e2a95aabd82420931f476661fa8e3jorton * a routine that the core and other modules call when they need to know
e8f95a682820a599fe41b22977010636be5c2717jim * the URL scheme for the request. For instance, mod_ssl returns "https"
e8f95a682820a599fe41b22977010636be5c2717jim * if the server_rec associated with the request has SSL enabled.
98fb535f829e2a95aabd82420931f476661fa8e3jorton *
98fb535f829e2a95aabd82420931f476661fa8e3jorton * This hook was named 'ap_hook_http_method' in httpd 2.0.
e8f95a682820a599fe41b22977010636be5c2717jim *
98fb535f829e2a95aabd82420931f476661fa8e3jorton * This is a RUN_FIRST hook: the first handler to return a non NULL
98fb535f829e2a95aabd82420931f476661fa8e3jorton * value aborts the handler chain. The http_core module inserts a
98fb535f829e2a95aabd82420931f476661fa8e3jorton * fallback handler (with APR_HOOK_REALLY_LAST preference) that returns
3568de757bac0b47256647504c186d17ca272f85rbb * "http".
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantzstatic const char *x_http_scheme(const request_rec *r)
3568de757bac0b47256647504c186d17ca272f85rbb{
3568de757bac0b47256647504c186d17ca272f85rbb /*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Log the call and exit.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding trace_request(r, "x_http_scheme()");
85c5af648e9f414bd4f157490766d2fd5515a9f5rpluem
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe /* We have no claims to make about the request scheme */
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe return NULL;
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe}
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe/*
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe * The runner for this hook is aliased to ap_default_port(), which the
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe * core and other modules call when they need to know the default port
85c5af648e9f414bd4f157490766d2fd5515a9f5rpluem * for a particular server. This is used for instance to omit the
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe * port number from a Redirect response Location header URL if the port
3568de757bac0b47256647504c186d17ca272f85rbb * number is equal to the default port for the service (like 80 for http).
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz *
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * This is a RUN_FIRST hook: the first handler to return a non-zero
3568de757bac0b47256647504c186d17ca272f85rbb * value is the last one executed. The http_core module inserts a
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * fallback handler (with APR_HOOK_REALLY_LAST order specifier) that
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz * returns 80.
3568de757bac0b47256647504c186d17ca272f85rbb */
3568de757bac0b47256647504c186d17ca272f85rbbstatic apr_port_t x_default_port(const request_rec *r)
3568de757bac0b47256647504c186d17ca272f85rbb{
3568de757bac0b47256647504c186d17ca272f85rbb /*
3568de757bac0b47256647504c186d17ca272f85rbb * Log the call and exit.
3568de757bac0b47256647504c186d17ca272f85rbb */
ec020ca384efb30d501a5af796ddc3bb237d7b8fgregames trace_request(r, "x_default_port()");
3568de757bac0b47256647504c186d17ca272f85rbb return 0;
ce03576b2434cec77f2921db9d5b6a0510581c23rederpj}
397df70abe0bdd78a84fb6c38c02641bcfeadceasf
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick/*
cd8f8c995d415473f3bfb0b329b2450f2a722c3atrawick * This routine is called just before the handler gets invoked. It allows
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * a module to insert a previously defined filter into the filter chain.
397df70abe0bdd78a84fb6c38c02641bcfeadceasf *
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * No filter has been defined by this module, so we just log the call
397df70abe0bdd78a84fb6c38c02641bcfeadceasf * and exit.
397df70abe0bdd78a84fb6c38c02641bcfeadceasf *
49aa87d735a13ae3d04012ee0df91ddb51f7c36esf * This is a VOID hook: all defined handlers get called.
9d0665da83d1e22c0ea0e5f6f940f70f75bf5237ianh */
3568de757bac0b47256647504c186d17ca272f85rbbstatic void x_insert_filter(request_rec *r)
3568de757bac0b47256647504c186d17ca272f85rbb{
7cd5419264796cfeaf8215383cf0f89130a81fectrawick /*
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * Log the call and exit.
7cd5419264796cfeaf8215383cf0f89130a81fectrawick */
7cd5419264796cfeaf8215383cf0f89130a81fectrawick trace_request(r, "x_insert_filter()");
7cd5419264796cfeaf8215383cf0f89130a81fectrawick}
7cd5419264796cfeaf8215383cf0f89130a81fectrawick
7cd5419264796cfeaf8215383cf0f89130a81fectrawick/*
73e8b26287de5c06fa470d36162e103dbac9c7e5wrowe * This routine is called to insert a previously defined error filter into
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the filter chain as the request is being processed.
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe *
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe * For the purpose of this example, we don't have a filter to insert,
3568de757bac0b47256647504c186d17ca272f85rbb * so just add to the trace and exit.
7cd5419264796cfeaf8215383cf0f89130a81fectrawick *
7cd5419264796cfeaf8215383cf0f89130a81fectrawick * This is a VOID hook: all defined handlers get called.
7cd5419264796cfeaf8215383cf0f89130a81fectrawick */
ca53a74f4012a45cbad48e940eddf27d866981f9dougmstatic void x_insert_error_filter(request_rec *r)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
36ef8f77bffe75d1aa327882be1b5bdbe2ff567asf trace_request(r, "x_insert_error_filter()");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
302dc1f7b3feee23a91ad8f3cf3cb2edd95a557bmanoj
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/*--------------------------------------------------------------------------*/
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* Now we declare our content handlers, which are invoked when the server */
28c170ac8e99644de58cad454c6e0f9b4b359be6jerenkrantz/* encounters a document which our module is supposed to have a chance to */
0cb6873985efbf0cc9644114925df6baa4b32d5awrowe/* see. (See mod_mime's SetHandler and AddHandler directives, and the */
3568de757bac0b47256647504c186d17ca272f85rbb/* mod_info and mod_status examples, for more details.) */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* */
3568de757bac0b47256647504c186d17ca272f85rbb/* Since content handlers are dumping data directly into the connection */
/* (using the r*() routines, such as rputs() and rprintf()) without */
/* intervention by other parts of the server, they need to make */
/* sure any accumulated HTTP headers are sent first. This is done by */
/* calling send_http_header(). Otherwise, no header will be sent at all, */
/* and the output sent to the client will actually be HTTP-uncompliant. */
/*--------------------------------------------------------------------------*/
/*
* Sample content handler. All this does is display the call list that has
* been built up so far.
*
* This routine gets called for every request, unless another handler earlier
* in the callback chain has already handled the request. It is up to us to
* test the request_rec->handler field and see whether we are meant to handle
* this request.
*
* The content handler gets to write directly to the client using calls like
* ap_rputs() and ap_rprintf()
*
* This is a RUN_FIRST hook.
*/
static int x_handler(request_rec *r)
{
x_cfg *dcfg;
char *note;
void *conn_data;
apr_status_t status;
dcfg = our_dconfig(r);
/*
* Add our trace to the log, and whether we get to write
* content for this request.
*/
note = apr_pstrcat(r->pool, "x_handler(), handler is \"",
r->handler, "\"", NULL);
trace_request(r, note);
/* If it's not for us, get out as soon as possible. */
if (strcmp(r->handler, "example-hooks-handler")) {
return DECLINED;
}
/*
* Set the Content-type header. Note that we do not actually have to send
* the headers: this is done by the http core.
*/
ap_set_content_type(r, "text/html");
/*
* If we're only supposed to send header information (HEAD request), we're
* already there.
*/
if (r->header_only) {
return OK;
}
/*
* Now send our actual output. Since we tagged this as being
* "text/html", we need to embed any HTML.
*/
ap_rputs(DOCTYPE_HTML_3_2, r);
ap_rputs("<HTML>\n", r);
ap_rputs(" <HEAD>\n", r);
ap_rputs(" <TITLE>mod_example_hooks Module Content-Handler Output\n", r);
ap_rputs(" </TITLE>\n", r);
ap_rputs(" </HEAD>\n", r);
ap_rputs(" <BODY>\n", r);
ap_rputs(" <H1><SAMP>mod_example_hooks</SAMP> Module Content-Handler Output\n", r);
ap_rputs(" </H1>\n", r);
ap_rputs(" <P>\n", r);
ap_rprintf(r, " Apache HTTP Server version: \"%s\"\n",
ap_get_server_banner());
ap_rputs(" <BR>\n", r);
ap_rprintf(r, " Server built: \"%s\"\n", ap_get_server_built());
ap_rputs(" </P>\n", r);;
ap_rputs(" <P>\n", r);
ap_rputs(" The format for the callback trace is:\n", r);
ap_rputs(" </P>\n", r);
ap_rputs(" <DL>\n", r);
ap_rputs(" <DT><EM>n</EM>.<SAMP>&lt;routine-name&gt;", r);
ap_rputs("(&lt;routine-data&gt;)</SAMP>\n", r);
ap_rputs(" </DT>\n", r);
ap_rputs(" <DD><SAMP>[&lt;applies-to&gt;]</SAMP>\n", r);
ap_rputs(" </DD>\n", r);
ap_rputs(" </DL>\n", r);
ap_rputs(" <P>\n", r);
ap_rputs(" The <SAMP>&lt;routine-data&gt;</SAMP> is supplied by\n", r);
ap_rputs(" the routine when it requests the trace,\n", r);
ap_rputs(" and the <SAMP>&lt;applies-to&gt;</SAMP> is extracted\n", r);
ap_rputs(" from the configuration record at the time of the trace.\n", r);
ap_rputs(" <STRONG>SVR()</STRONG> indicates a server environment\n", r);
ap_rputs(" (blank means the main or default server, otherwise it's\n", r);
ap_rputs(" the name of the VirtualHost); <STRONG>DIR()</STRONG>\n", r);
ap_rputs(" indicates a location in the URL or filesystem\n", r);
ap_rputs(" namespace.\n", r);
ap_rputs(" </P>\n", r);
ap_rprintf(r, " <H2>Startup callbacks so far:</H2>\n <OL>\n%s </OL>\n",
trace);
ap_rputs(" <H2>Connection-specific callbacks so far:</H2>\n", r);
status = apr_pool_userdata_get(&conn_data, CONN_NOTE,
r->connection->pool);
if ((status == APR_SUCCESS) && conn_data) {
ap_rprintf(r, " <OL>\n%s </OL>\n", (char *) conn_data);
} else {
ap_rputs(" <P>No connection-specific callback information was "
"retrieved.</P>\n", r);
}
ap_rputs(" <H2>Request-specific callbacks so far:</H2>\n", r);
ap_rprintf(r, " <OL>\n%s </OL>\n", apr_table_get(r->notes, TRACE_NOTE));
ap_rputs(" <H2>Environment for <EM>this</EM> call:</H2>\n", r);
ap_rputs(" <UL>\n", r);
ap_rprintf(r, " <LI>Applies-to: <SAMP>%s</SAMP>\n </LI>\n", dcfg->loc);
ap_rprintf(r, " <LI>\"Example\" directive declared here: %s\n </LI>\n",
(dcfg->local ? "YES" : "NO"));
ap_rprintf(r, " <LI>\"Example\" inherited: %s\n </LI>\n",
(dcfg->congenital ? "YES" : "NO"));
ap_rputs(" </UL>\n", r);
ap_rputs(" </BODY>\n", r);
ap_rputs("</HTML>\n", r);
/*
* We're all done, so cancel the timeout we set. Since this is probably
* the end of the request we *could* assume this would be done during
* post-processing - but it's possible that another handler might be
* called and inherit our outstanding timer. Not good; to each its own.
*/
/*
* We did what we wanted to do, so tell the rest of the server we
* succeeded.
*/
return OK;
}
/*
* The quick_handler hook presents modules with a very powerful opportunity to
* serve their content in a very early request phase. Note that this handler
* can not serve any requests from the file system because hooks like
* map_to_storage have not run. The quick_handler hook also runs before any
* authentication and access control.
*
* This hook is used by mod_cache to serve cached content.
*
* This is a RUN_FIRST hook. Return OK if you have served the request,
* DECLINED if you want processing to continue, or a HTTP_* error code to stop
* processing the request.
*/
static int x_quick_handler(request_rec *r, int lookup_uri)
{
/*
* Log the call and exit.
*/
trace_request(r, "x_quick_handler()");
return DECLINED;
}
/*
* This routine is called just after the server accepts the connection,
* but before it is handed off to a protocol module to be served. The point
* of this hook is to allow modules an opportunity to modify the connection
* as soon as possible. The core server uses this phase to setup the
* connection record based on the type of connection that is being used.
*
* This is a RUN_ALL hook.
*/
static int x_pre_connection(conn_rec *c, void *csd)
{
char *note;
/*
* Log the call and exit.
*/
note = apr_psprintf(c->pool, "x_pre_connection(c = %pp, p = %pp)",
(void*) c, (void*) c->pool);
trace_connection(c, note);
return OK;
}
/* This routine is used to actually process the connection that was received.
* Only protocol modules should implement this hook, as it gives them an
* opportunity to replace the standard HTTP processing with processing for
* some other protocol. Both echo and POP3 modules are available as
* examples.
*
* This is a RUN_FIRST hook.
*/
static int x_process_connection(conn_rec *c)
{
trace_connection(c, "x_process_connection()");
return DECLINED;
}
/*
* This routine is called after the request has been read but before any other
* phases have been processed. This allows us to make decisions based upon
* the input header fields.
*
* This is a HOOK_VOID hook.
*/
static void x_pre_read_request(request_rec *r, conn_rec *c)
{
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
trace_request(r, "x_pre_read_request()");
}
/*
* This routine is called after the request has been read but before any other
* phases have been processed. This allows us to make decisions based upon
* the input header fields.
*
* This is a RUN_ALL hook.
*/
static int x_post_read_request(request_rec *r)
{
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
trace_request(r, "x_post_read_request()");
return DECLINED;
}
/*
* This routine gives our module an opportunity to translate the URI into an
* actual filename. If we don't do anything special, the server's default
* rules (Alias directives and the like) will continue to be followed.
*
* This is a RUN_FIRST hook.
*/
static int x_translate_name(request_rec *r)
{
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
trace_request(r, "x_translate_name()");
return DECLINED;
}
/*
* This routine maps r->filename to a physical file on disk. Useful for
* overriding default core behavior, including skipping mapping for
* requests that are not file based.
*
* This is a RUN_FIRST hook.
*/
static int x_map_to_storage(request_rec *r)
{
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
trace_request(r, "x_map_to_storage()");
return DECLINED;
}
/*
* this routine gives our module another chance to examine the request
* headers and to take special action. This is the first phase whose
* hooks' configuration directives can appear inside the <Directory>
* and similar sections, because at this stage the URI has been mapped
* to the filename. For example this phase can be used to block evil
* clients, while little resources were wasted on these.
*
* This is a RUN_ALL hook.
*/
static int x_header_parser(request_rec *r)
{
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
trace_request(r, "x_header_parser()");
return DECLINED;
}
/*
* This routine is called to check for any module-specific restrictions placed
* upon the requested resource. (See the mod_access_compat module for an
* example.)
*
* This is a RUN_ALL hook. The first handler to return a status other than OK
* or DECLINED (for instance, HTTP_FORBIDDEN) aborts the callback chain.
*/
static int x_check_access(request_rec *r)
{
trace_request(r, "x_check_access()");
return DECLINED;
}
/*
* This routine is called to check the authentication information sent with
* the request (such as looking up the user in a database and verifying that
* the [encrypted] password sent matches the one in the database).
*
* This is a RUN_FIRST hook. The return value is OK, DECLINED, or some
* HTTP_mumble error (typically HTTP_UNAUTHORIZED).
*/
static int x_check_authn(request_rec *r)
{
/*
* Don't do anything except log the call.
*/
trace_request(r, "x_check_authn()");
return DECLINED;
}
/*
* This routine is called to check to see if the resource being requested
* requires authorisation.
*
* This is a RUN_FIRST hook. The return value is OK, DECLINED, or
* HTTP_mumble. If we return OK, no other modules are called during this
* phase.
*
* If *all* modules return DECLINED, the request is aborted with a server
* error.
*/
static int x_check_authz(request_rec *r)
{
/*
* Log the call and return OK, or access will be denied (even though we
* didn't actually do anything).
*/
trace_request(r, "x_check_authz()");
return DECLINED;
}
/*
* This routine is called to determine and/or set the various document type
* information bits, like Content-type (via r->content_type), language, et
* cetera.
*
* This is a RUN_FIRST hook.
*/
static int x_type_checker(request_rec *r)
{
/*
* Log the call, but don't do anything else - and report truthfully that
* we didn't do anything.
*/
trace_request(r, "x_type_checker()");
return DECLINED;
}
/*
* This routine is called to perform any module-specific fixing of header
* fields, et cetera. It is invoked just before any content-handler.
*
* This is a RUN_ALL HOOK.
*/
static int x_fixups(request_rec *r)
{
/*
* Log the call and exit.
*/
trace_request(r, "x_fixups()");
return DECLINED;
}
/*
* This routine is called to perform any module-specific logging activities
* over and above the normal server things.
*
* This is a RUN_ALL hook.
*/
static int x_log_transaction(request_rec *r)
{
trace_request(r, "x_log_transaction()");
return DECLINED;
}
#ifdef HAVE_UNIX_SUEXEC
/*
* This routine is called to find out under which user id to run suexec
* Unless our module runs CGI programs, there is no reason for us to
* mess with this information.
*
* This is a RUN_FIRST hook. The return value is a pointer to an
* ap_unix_identity_t or NULL.
*/
static ap_unix_identity_t *x_get_suexec_identity(const request_rec *r)
{
trace_request(r, "x_get_suexec_identity()");
return NULL;
}
#endif
/*
* This routine is called to create a connection. This hook is implemented
* by the Apache core: there is no known reason a module should override
* it.
*
* This is a RUN_FIRST hook.
*
* Return NULL to decline, a valid conn_rec pointer to accept.
*/
static conn_rec *x_create_connection(apr_pool_t *p, server_rec *server,
apr_socket_t *csd, long conn_id,
void *sbh, apr_bucket_alloc_t *alloc)
{
trace_nocontext(p, __FILE__, __LINE__, "x_create_connection()");
return NULL;
}
/*
* This hook is defined in server/core.c, but it is not actually called
* or documented.
*
* This is a RUN_ALL hook.
*/
static int x_get_mgmt_items(apr_pool_t *p, const char *val, apr_hash_t *ht)
{
/* We have nothing to do here but trace the call, and no context
* in which to trace it.
*/
trace_nocontext(p, __FILE__, __LINE__, "x_check_config()");
return DECLINED;
}
/*
* This routine gets called shortly after the request_rec structure
* is created. It provides the opportunity to manipulae the request
* at a very early stage.
*
* This is a RUN_ALL hook.
*/
static int x_create_request(request_rec *r)
{
/*
* We have a request_rec, but it is not filled in enough to give
* us a usable configuration. So, add a trace without context.
*/
trace_nocontext( r->pool, __FILE__, __LINE__, "x_create_request()");
return DECLINED;
}
/*
* This routine gets called during the startup of the MPM.
* No known existing module implements this hook.
*
* This is a RUN_ALL hook.
*/
static int x_pre_mpm(apr_pool_t *p, ap_scoreboard_e sb_type)
{
trace_nocontext(p, __FILE__, __LINE__, "x_pre_mpm()");
return DECLINED;
}
/*
* This hook gets run periodically by a maintenance function inside
* the MPM. Its exact purpose is unknown and undocumented at this time.
*
* This is a RUN_ALL hook.
*/
static int x_monitor(apr_pool_t *p, server_rec *s)
{
trace_nocontext(p, __FILE__, __LINE__, "x_monitor()");
return DECLINED;
}
/*--------------------------------------------------------------------------*/
/* */
/* Which functions are responsible for which hooks in the server. */
/* */
/*--------------------------------------------------------------------------*/
/*
* Each function our module provides to handle a particular hook is
* specified here. The functions are registered using
* ap_hook_foo(name, predecessors, successors, position)
* where foo is the name of the hook.
*
* The args are as follows:
* name -> the name of the function to call.
* predecessors -> a list of modules whose calls to this hook must be
* invoked before this module.
* successors -> a list of modules whose calls to this hook must be
* invoked after this module.
* position -> The relative position of this module. One of
* APR_HOOK_FIRST, APR_HOOK_MIDDLE, or APR_HOOK_LAST.
* Most modules will use APR_HOOK_MIDDLE. If multiple
* modules use the same relative position, Apache will
* determine which to call first.
* If your module relies on another module to run first,
* or another module running after yours, use the
* predecessors and/or successors.
*
* The number in brackets indicates the order in which the routine is called
* during request processing. Note that not all routines are necessarily
* called (such as if a resource doesn't have access restrictions).
* The actual delivery of content to the browser [9] is not handled by
* a hook; see the handler declarations below.
*/
static void x_register_hooks(apr_pool_t *p)
{
ap_hook_pre_config(x_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_check_config(x_check_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_test_config(x_test_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_open_logs(x_open_logs, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(x_post_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(x_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(x_handler, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_quick_handler(x_quick_handler, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_pre_connection(x_pre_connection, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_process_connection(x_process_connection, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_pre_read_request(x_pre_read_request, NULL, NULL,
APR_HOOK_MIDDLE);
/* [1] post read_request handling */
ap_hook_post_read_request(x_post_read_request, NULL, NULL,
APR_HOOK_MIDDLE);
ap_hook_log_transaction(x_log_transaction, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_http_scheme(x_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_default_port(x_default_port, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_translate_name(x_translate_name, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_map_to_storage(x_map_to_storage, NULL,NULL, APR_HOOK_MIDDLE);
ap_hook_header_parser(x_header_parser, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_fixups(x_fixups, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_type_checker(x_type_checker, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_check_access(x_check_access, NULL, NULL, APR_HOOK_MIDDLE,
AP_AUTH_INTERNAL_PER_CONF);
ap_hook_check_authn(x_check_authn, NULL, NULL, APR_HOOK_MIDDLE,
AP_AUTH_INTERNAL_PER_CONF);
ap_hook_check_authz(x_check_authz, NULL, NULL, APR_HOOK_MIDDLE,
AP_AUTH_INTERNAL_PER_CONF);
ap_hook_insert_filter(x_insert_filter, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_insert_error_filter(x_insert_error_filter, NULL, NULL, APR_HOOK_MIDDLE);
#ifdef HAVE_UNIX_SUEXEC
ap_hook_get_suexec_identity(x_get_suexec_identity, NULL, NULL, APR_HOOK_MIDDLE);
#endif
ap_hook_create_connection(x_create_connection, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_get_mgmt_items(x_get_mgmt_items, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_create_request(x_create_request, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_pre_mpm(x_pre_mpm, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_monitor(x_monitor, NULL, NULL, APR_HOOK_MIDDLE);
}
/*--------------------------------------------------------------------------*/
/* */
/* All of the routines have been declared now. Here's the list of */
/* directives specific to our module, and information about where they */
/* may appear and how the command parser should pass them to us for */
/* processing. Note that care must be taken to ensure that there are NO */
/* collisions of directive names between modules. */
/* */
/*--------------------------------------------------------------------------*/
/*
* List of directives specific to our module.
*/
static const command_rec x_cmds[] =
{
AP_INIT_NO_ARGS(
"Example", /* directive name */
cmd_example, /* config action routine */
NULL, /* argument to include in call */
OR_OPTIONS, /* where available */
"Example directive - no arguments" /* directive description */
),
{NULL}
};
/*--------------------------------------------------------------------------*/
/* */
/* Finally, the list of callback routines and data structures that provide */
/* the static hooks into our module from the other parts of the server. */
/* */
/*--------------------------------------------------------------------------*/
/*
* Module definition for configuration. If a particular callback is not
* needed, replace its routine name below with the word NULL.
*/
AP_DECLARE_MODULE(example_hooks) =
{
STANDARD20_MODULE_STUFF,
x_create_dir_config, /* per-directory config creator */
x_merge_dir_config, /* dir config merger */
x_create_server_config, /* server config creator */
x_merge_server_config, /* server config merger */
x_cmds, /* command table */
x_register_hooks, /* set up other request processing hooks */
};