mod_example.c revision fc9b2e8809c305f340d86a789566f8abb1ca8a19
2d2eda71267231c2526be701fe655db125852c1ffielding/* ====================================================================
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * Copyright (c) 1995-1999 The Apache Group. All rights reserved.
f062ed7bd262a37a909dd77ce5fc23b446818823fielding *
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * Redistribution and use in source and binary forms, with or without
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * modification, are permitted provided that the following conditions
2d2eda71267231c2526be701fe655db125852c1ffielding * are met:
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 1. Redistributions of source code must retain the above copyright
2d2eda71267231c2526be701fe655db125852c1ffielding * notice, this list of conditions and the following disclaimer.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 2. Redistributions in binary form must reproduce the above copyright
2d2eda71267231c2526be701fe655db125852c1ffielding * notice, this list of conditions and the following disclaimer in
2d2eda71267231c2526be701fe655db125852c1ffielding * the documentation and/or other materials provided with the
2d2eda71267231c2526be701fe655db125852c1ffielding * distribution.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 3. All advertising materials mentioning features or use of this
2d2eda71267231c2526be701fe655db125852c1ffielding * software must display the following acknowledgment:
2d2eda71267231c2526be701fe655db125852c1ffielding * "This product includes software developed by the Apache Group
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * for use in the Apache HTTP server project (http://www.apache.org/)."
f062ed7bd262a37a909dd77ce5fc23b446818823fielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * 4. The names "Apache Server" and "Apache Group" must not be used to
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * endorse or promote products derived from this software without
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * prior written permission. For written permission, please contact
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * apache@apache.org.
2d2eda71267231c2526be701fe655db125852c1ffielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * 5. Products derived from this software may not be called "Apache"
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * nor may "Apache" appear in their names without prior written
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * permission of the Apache Group.
f062ed7bd262a37a909dd77ce5fc23b446818823fielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * 6. Redistributions of any form whatsoever must retain the following
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * acknowledgment:
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * "This product includes software developed by the Apache Group
64185f9824e42f21ca7b9ae6c004484215c031a7rbb * for use in the Apache HTTP server project (http://www.apache.org/)."
2d2eda71267231c2526be701fe655db125852c1ffielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR
2d2eda71267231c2526be701fe655db125852c1ffielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * OF THE POSSIBILITY OF SUCH DAMAGE.
2d2eda71267231c2526be701fe655db125852c1ffielding * ====================================================================
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * This software consists of voluntary contributions made by many
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * individuals on behalf of the Apache Group and was originally based
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * on public domain software written at the National Center for
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * Supercomputing Applications, University of Illinois, Urbana-Champaign.
2d2eda71267231c2526be701fe655db125852c1ffielding * For more information on the Apache Group and the Apache HTTP server
f062ed7bd262a37a909dd77ce5fc23b446818823fielding * project, please see <http://www.apache.org/>.
f062ed7bd262a37a909dd77ce5fc23b446818823fielding *
f062ed7bd262a37a909dd77ce5fc23b446818823fielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/*
2d2eda71267231c2526be701fe655db125852c1ffielding * Apache example module. Provide demonstrations of how modules do things.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe#include "httpd.h"
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb#include "http_config.h"
92f3af936ce61f25358a3ee4f28df2f6d62040dfdreid#include "http_core.h"
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb#include "http_log.h"
c9a95767fbf0f5fb0976a06b97a256033925e433rbb#include "http_main.h"
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding#include "http_protocol.h"
2d2eda71267231c2526be701fe655db125852c1ffielding#include "util_script.h"
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding#include <stdio.h>
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*--------------------------------------------------------------------------*/
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* Data declarations. */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* */
2d2eda71267231c2526be701fe655db125852c1ffielding/* Here are the static cells and structure declarations private to our */
2d2eda71267231c2526be701fe655db125852c1ffielding/* module. */
2d2eda71267231c2526be701fe655db125852c1ffielding/* */
2d2eda71267231c2526be701fe655db125852c1ffielding/*--------------------------------------------------------------------------*/
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Sample configuration record. Used for both per-directory and per-server
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * configuration data.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * It's perfectly reasonable to have two different structures for the two
2d2eda71267231c2526be701fe655db125852c1ffielding * different environments. The same command handlers will be called for
2d2eda71267231c2526be701fe655db125852c1ffielding * both, though, so the handlers need to be able to tell them apart. One
bfb62a96023822c56c9120e4ee627d4091cc59c2rbb * possibility is for both structures to start with an int which is zero for
bfb62a96023822c56c9120e4ee627d4091cc59c2rbb * one and 1 for the other.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Note that while the per-directory and per-server configuration records are
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * available to most of the module handlers, they should be treated as
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * READ-ONLY by all except the command and merge handlers. Sometimes handlers
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * are handed a record that applies to the current location by implication or
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * inheritance, and modifying it will change the rules for other locations.
3d96ee83babeec32482c9082c9426340cee8c44dwrowe */
2d2eda71267231c2526be701fe655db125852c1ffieldingtypedef struct excfg {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int cmode; /* Environment to which record applies (directory,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * server, or combination).
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#define CONFIG_MODE_SERVER 1
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#define CONFIG_MODE_DIRECTORY 2
61fd0cab072a05b855cbef9c585702401ac5ae29rbb#define CONFIG_MODE_COMBO 3 /* Shouldn't ever happen. */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int local; /* Boolean: "Example" directive declared here? */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb int congenital; /* Boolean: did we inherit an "Example"? */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *trace; /* Pointer to trace string. */
2d2eda71267231c2526be701fe655db125852c1ffielding char *loc; /* Location to which this record applies. */
3d96ee83babeec32482c9082c9426340cee8c44dwrowe} excfg;
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/*
2d2eda71267231c2526be701fe655db125852c1ffielding * Let's set up a module-local static cell to point to the accreting callback
2d2eda71267231c2526be701fe655db125852c1ffielding * trace. As each API callback is made to us, we'll tack on the particulars
000b67449410515eac43e76ef6667915bfd4d2abgstein * to whatever we've already recorded. To avoid massive memory bloat as
2d2eda71267231c2526be701fe655db125852c1ffielding * directories are walked again and again, we record the routine/environment
2d2eda71267231c2526be701fe655db125852c1ffielding * the first time (non-request context only), and ignore subsequent calls for
2d2eda71267231c2526be701fe655db125852c1ffielding * the same routine/environment.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbstatic const char *trace = NULL;
61fd0cab072a05b855cbef9c585702401ac5ae29rbbstatic ap_table_t *static_calls_made = NULL;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * To avoid leaking memory from pools other than the per-request one, we
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * allocate a module-private pool, and then use a sub-pool of that which gets
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * freed each time we modify the trace. That way previous layers of trace
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * data don't get lost.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbstatic ap_context_t *example_pool = NULL;
61fd0cab072a05b855cbef9c585702401ac5ae29rbbstatic ap_context_t *example_subpool = NULL;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * Declare ourselves so the configuration routines can find and know us.
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * We'll fill it in at the end of the module.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbmodule example_module;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*--------------------------------------------------------------------------*/
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* The following pseudo-prototype declarations illustrate the parameters */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* passed to command handlers for the different types of directive */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* syntax. If an argument was specified in the directive definition */
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/* (look for "command_rec" below), it's available to the command handler */
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein/* via the (void *) info field in the cmd_parms argument passed to the */
c9a95767fbf0f5fb0976a06b97a256033925e433rbb/* handler (cmd->info for the examples below). */
c9a95767fbf0f5fb0976a06b97a256033925e433rbb/* */
c9a95767fbf0f5fb0976a06b97a256033925e433rbb/*--------------------------------------------------------------------------*/
c9a95767fbf0f5fb0976a06b97a256033925e433rbb
c9a95767fbf0f5fb0976a06b97a256033925e433rbb/*
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * Command handler for a NO_ARGS directive.
c9a95767fbf0f5fb0976a06b97a256033925e433rbb *
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * static const char *handle_NO_ARGS(cmd_parms *cmd, void *mconfig);
c9a95767fbf0f5fb0976a06b97a256033925e433rbb */
c9a95767fbf0f5fb0976a06b97a256033925e433rbb
c9a95767fbf0f5fb0976a06b97a256033925e433rbb/*
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * Command handler for a RAW_ARGS directive. The "args" argument is the text
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * of the commandline following the directive itself.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * static const char *handle_RAW_ARGS(cmd_parms *cmd, void *mconfig,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * const char *args);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Command handler for a FLAG directive. The single parameter is passed in
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * "bool", which is either zero or not for Off or On respectively.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * static const char *handle_FLAG(cmd_parms *cmd, void *mconfig, int bool);
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Command handler for a TAKE1 directive. The single parameter is passed in
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * "word1".
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * static const char *handle_TAKE1(cmd_parms *cmd, void *mconfig,
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * char *word1);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Command handler for a TAKE2 directive. TAKE2 commands must always have
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * exactly two arguments.
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * static const char *handle_TAKE2(cmd_parms *cmd, void *mconfig,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * char *word1, char *word2);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Command handler for a TAKE3 directive. Like TAKE2, these must have exactly
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * three arguments, or the parser complains and doesn't bother calling us.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * static const char *handle_TAKE3(cmd_parms *cmd, void *mconfig,
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * char *word1, char *word2, char *word3);
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/*
2d2eda71267231c2526be701fe655db125852c1ffielding * Command handler for a TAKE12 directive. These can take either one or two
2d2eda71267231c2526be701fe655db125852c1ffielding * arguments.
2d2eda71267231c2526be701fe655db125852c1ffielding * - word2 is a NULL pointer if no second argument was specified.
2d2eda71267231c2526be701fe655db125852c1ffielding *
2d2eda71267231c2526be701fe655db125852c1ffielding * static const char *handle_TAKE12(cmd_parms *cmd, void *mconfig,
2d2eda71267231c2526be701fe655db125852c1ffielding * char *word1, char *word2);
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding
2d2eda71267231c2526be701fe655db125852c1ffielding/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Command handler for a TAKE123 directive. A TAKE123 directive can be given,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * as might be expected, one, two, or three arguments.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * - word2 is a NULL pointer if no second argument was specified.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * - word3 is a NULL pointer if no third argument was specified.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * static const char *handle_TAKE123(cmd_parms *cmd, void *mconfig,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * char *word1, char *word2, char *word3);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * Command handler for a TAKE13 directive. Either one or three arguments are
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm * permitted - no two-parameters-only syntax is allowed.
7bdef86e15d47d16dcbe7a5611683191774bd5fbgstein * - word2 and word3 are NULL pointers if only one argument was specified.
23ff73a56371e21f16744cb94d06399b877829f1rbb *
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * static const char *handle_TAKE13(cmd_parms *cmd, void *mconfig,
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * char *word1, char *word2, char *word3);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Command handler for a TAKE23 directive. At least two and as many as three
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * arguments must be specified.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * - word3 is a NULL pointer if no third argument was specified.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * static const char *handle_TAKE23(cmd_parms *cmd, void *mconfig,
2d2eda71267231c2526be701fe655db125852c1ffielding * char *word1, char *word2, char *word3);
23ff73a56371e21f16744cb94d06399b877829f1rbb */
2d2eda71267231c2526be701fe655db125852c1ffielding
62db15de4c1f335a64d45821796ae197cff94ef8rbb/*
62db15de4c1f335a64d45821796ae197cff94ef8rbb * Command handler for a ITERATE directive.
62db15de4c1f335a64d45821796ae197cff94ef8rbb * - Handler is called once for each of n arguments given to the directive.
62db15de4c1f335a64d45821796ae197cff94ef8rbb * - word1 points to each argument in turn.
62db15de4c1f335a64d45821796ae197cff94ef8rbb *
62db15de4c1f335a64d45821796ae197cff94ef8rbb * static const char *handle_ITERATE(cmd_parms *cmd, void *mconfig,
62db15de4c1f335a64d45821796ae197cff94ef8rbb * char *word1);
62db15de4c1f335a64d45821796ae197cff94ef8rbb */
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbb/*
62db15de4c1f335a64d45821796ae197cff94ef8rbb * Command handler for a ITERATE2 directive.
62db15de4c1f335a64d45821796ae197cff94ef8rbb * - Handler is called once for each of the second and subsequent arguments
62db15de4c1f335a64d45821796ae197cff94ef8rbb * given to the directive.
62db15de4c1f335a64d45821796ae197cff94ef8rbb * - word1 is the same for each call for a particular directive instance (the
62db15de4c1f335a64d45821796ae197cff94ef8rbb * first argument).
62db15de4c1f335a64d45821796ae197cff94ef8rbb * - word2 points to each of the second and subsequent arguments in turn.
62db15de4c1f335a64d45821796ae197cff94ef8rbb *
62db15de4c1f335a64d45821796ae197cff94ef8rbb * static const char *handle_ITERATE2(cmd_parms *cmd, void *mconfig,
62db15de4c1f335a64d45821796ae197cff94ef8rbb * char *word1, char *word2);
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb */
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbb/*--------------------------------------------------------------------------*/
62db15de4c1f335a64d45821796ae197cff94ef8rbb/* */
62db15de4c1f335a64d45821796ae197cff94ef8rbb/* These routines are strictly internal to this module, and support its */
62db15de4c1f335a64d45821796ae197cff94ef8rbb/* operation. They are not referenced by any external portion of the */
62db15de4c1f335a64d45821796ae197cff94ef8rbb/* server. */
62db15de4c1f335a64d45821796ae197cff94ef8rbb/* */
62db15de4c1f335a64d45821796ae197cff94ef8rbb/*--------------------------------------------------------------------------*/
62db15de4c1f335a64d45821796ae197cff94ef8rbb
62db15de4c1f335a64d45821796ae197cff94ef8rbb/*
62db15de4c1f335a64d45821796ae197cff94ef8rbb * Locate our directory configuration record for the current request.
62db15de4c1f335a64d45821796ae197cff94ef8rbb */
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbbstatic excfg *our_dconfig(request_rec *r)
48d2edbfb84e5559b5da0f8d614ccab805cc67a8rbb{
62db15de4c1f335a64d45821796ae197cff94ef8rbb
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar return (excfg *) ap_get_module_config(r->per_dir_config, &example_module);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar#if 0
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar/*
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * Locate our server configuration record for the specified server.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarstatic excfg *our_sconfig(server_rec *s)
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
3d96ee83babeec32482c9082c9426340cee8c44dwrowe return (excfg *) ap_get_module_config(s->module_config, &example_module);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/*
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick * Likewise for our configuration record for the specified request.
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawick */
a19698aebe10b9d41574e4a73794ba7d4cecd78btrawickstatic excfg *our_rconfig(request_rec *r)
3d96ee83babeec32482c9082c9426340cee8c44dwrowe{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar return (excfg *) ap_get_module_config(r->request_config, &example_module);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar#endif
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar/*
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * This routine sets up some module-wide cells if they haven't been already.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coarstatic void setup_module_cells()
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar{
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar /*
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * If we haven't already allocated our module-private pool, do so now.
3d96ee83babeec32482c9082c9426340cee8c44dwrowe */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if (example_pool == NULL) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar example_pool = ap_make_sub_pool(NULL);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar };
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar /*
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * Likewise for the ap_table_t of routine/environment pairs we visit outside of
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * request context.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar if (static_calls_made == NULL) {
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar static_calls_made = ap_make_table(example_pool, 16);
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar };
3d96ee83babeec32482c9082c9426340cee8c44dwrowe}
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar/*
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * This routine is used to add a trace of a callback to the list. We're
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * passed the server record (if available), the request record (if available),
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * a pointer to our private configuration record (if available) for the
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * environment to which the callback is supposed to apply, and some text. We
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * turn this into a textual representation and add it to the tail of the list.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * The list can be displayed by the example_handler() routine.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar *
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * If the call occurs within a request context (i.e., we're passed a request
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * record), we put the trace into the request ap_context_t and attach it to the
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * request via the notes mechanism. Otherwise, the trace gets added
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * to the static (non-request-specific) list.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar *
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * Note that the r->notes ap_table_t is only for storing strings; if you need to
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * maintain per-request data of any other type, you need to use another
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar * mechanism.
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar */
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
3d96ee83babeec32482c9082c9426340cee8c44dwrowe#define TRACE_NOTE "example-trace"
91f0d8da77152d24e4bbb31ce199282b3fd6e3b2coar
2d2eda71267231c2526be701fe655db125852c1ffieldingstatic void trace_add(server_rec *s, request_rec *r, excfg *mconfig,
2d2eda71267231c2526be701fe655db125852c1ffielding const char *note)
2d2eda71267231c2526be701fe655db125852c1ffielding{
2d2eda71267231c2526be701fe655db125852c1ffielding
61fd0cab072a05b855cbef9c585702401ac5ae29rbb const char *sofar;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *addon;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *where;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_context_t *p;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb const char *trace_copy;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * Make sure our pools and tables are set up - we need 'em.
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb setup_module_cells();
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Now, if we're in request-context, we use the request pool.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (r != NULL) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb p = r->pool;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if ((trace_copy = ap_table_get(r->notes, TRACE_NOTE)) == NULL) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe trace_copy = "";
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb else {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * We're not in request context, so the trace gets attached to our
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * module-wide pool. We do the create/destroy every time we're called
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * in non-request context; this avoids leaking memory in some of
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * the subsequent calls that allocate memory only once (such as the
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * key formation below).
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * Make a new sub-pool and copy any existing trace to it. Point the
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * trace cell at the copied value.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb p = ap_make_sub_pool(example_pool);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (trace != NULL) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb trace = ap_pstrdup(p, trace);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * Now, if we have a sub-pool from before, nuke it and replace with
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * the one we just allocated.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (example_subpool != NULL) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_destroy_pool(example_subpool);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb example_subpool = p;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb trace_copy = trace;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * If we weren't passed a configuration record, we can't figure out to
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * what location this call applies. This only happens for co-routines
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * that don't operate in a particular directory or server context. If we
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * got a valid record, extract the location (directory or server) to which
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * it applies.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb where = (mconfig != NULL) ? mconfig->loc : "nowhere";
61fd0cab072a05b855cbef9c585702401ac5ae29rbb where = (where != NULL) ? where : "";
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Now, if we're not in request context, see if we've been called with
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * this particular combination before. The ap_table_t is allocated in the
2d2eda71267231c2526be701fe655db125852c1ffielding * module's private pool, which doesn't get destroyed.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (r == NULL) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb char *key;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb key = ap_pstrcat(p, note, ":", where, NULL);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (ap_table_get(static_calls_made, key) != NULL) {
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /*
2d2eda71267231c2526be701fe655db125852c1ffielding * Been here, done this.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
2d2eda71267231c2526be701fe655db125852c1ffielding return;
2d2eda71267231c2526be701fe655db125852c1ffielding }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb else {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * First time for this combination of routine and environment -
2d2eda71267231c2526be701fe655db125852c1ffielding * log it so we don't do it again.
3d96ee83babeec32482c9082c9426340cee8c44dwrowe */
2d2eda71267231c2526be701fe655db125852c1ffielding ap_table_set(static_calls_made, key, "been here");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
d839a9822ee53ce00da24c15f2d9fe054233d342gstein }
d839a9822ee53ce00da24c15f2d9fe054233d342gstein addon = ap_pstrcat(p, " <LI>\n", " <DL>\n", " <DT><SAMP>",
d839a9822ee53ce00da24c15f2d9fe054233d342gstein note, "</SAMP>\n", " </DT>\n", " <DD><SAMP>[",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb where, "]</SAMP>\n", " </DD>\n", " </DL>\n",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb " </LI>\n", NULL);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb sofar = (trace_copy == NULL) ? "" : trace_copy;
d839a9822ee53ce00da24c15f2d9fe054233d342gstein trace_copy = ap_pstrcat(p, sofar, addon, NULL);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe if (r != NULL) {
d839a9822ee53ce00da24c15f2d9fe054233d342gstein ap_table_set(r->notes, TRACE_NOTE, trace_copy);
2d2eda71267231c2526be701fe655db125852c1ffielding }
2d2eda71267231c2526be701fe655db125852c1ffielding else {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb trace = trace_copy;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * You *could* change the following if you wanted to see the calling
346029f34d03eb20d84fc35664426d3874b00f9ewrowe * sequence reported in the server's error_log, but beware - almost all of
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * these co-routines are called for every single request, and the impact
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * on the size (and readability) of the error_log is considerable.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
346029f34d03eb20d84fc35664426d3874b00f9ewrowe#define EXAMPLE_LOG_EACH 0
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (EXAMPLE_LOG_EACH && (s != NULL)) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_log_error(APLOG_MARK, APLOG_DEBUG, s, "mod_example: %s", note);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
3d96ee83babeec32482c9082c9426340cee8c44dwrowe}
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*--------------------------------------------------------------------------*/
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* We prototyped the various syntax for command handlers (routines that */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* are called when the configuration parser detects a directive declared */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* by our module) earlier. Now we actually declare a "real" routine that */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* will be invoked by the parser when our "real" directive is */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* encountered. */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* If a command handler encounters a problem processing the directive, it */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* signals this fact by returning a non-NULL pointer to a string */
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/* describing the problem. */
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein/* */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* The magic return value DECLINE_CMD is used to deal with directives */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* that might be declared by multiple modules. If the command handler */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* returns NULL, the directive was processed; if it returns DECLINE_CMD, */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* the next module (if any) that declares the directive is given a chance */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* at it. If it returns any other value, it's treated as the text of an */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* error message. */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*--------------------------------------------------------------------------*/
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
11a7b0dff22d26770b532c174d1cf2e7b56ec244wrowe * Command handler for the NO_ARGS "Example" directive. All we do is mark the
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * call in the trace log, and flag the applicability of the directive to the
11a7b0dff22d26770b532c174d1cf2e7b56ec244wrowe * current location in that location's configuration record.
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbstatic const char *cmd_example(cmd_parms *cmd, void *mconfig)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb excfg *cfg = (excfg *) mconfig;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * "Example Wuz Here"
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb cfg->local = 1;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb trace_add(cmd->server, NULL, cfg, "cmd_example()");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return NULL;
3d96ee83babeec32482c9082c9426340cee8c44dwrowe}
2d2eda71267231c2526be701fe655db125852c1ffielding
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein/*--------------------------------------------------------------------------*/
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* Now we declare our content handlers, which are invoked when the server */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* encounters a document which our module is supposed to have a chance to */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* see. (See mod_mime's SetHandler and AddHandler directives, and the */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* mod_info and mod_status examples, for more details.) */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* Since content handlers are dumping data directly into the connexion */
3d96ee83babeec32482c9082c9426340cee8c44dwrowe/* (using the r*() routines, such as rputs() and rprintf()) without */
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein/* intervention by other parts of the server, they need to make */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* sure any accumulated HTTP headers are sent first. This is done by */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* calling send_http_header(). Otherwise, no header will be sent at all, */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/* and the output sent to the client will actually be HTTP-uncompliant. */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*--------------------------------------------------------------------------*/
61fd0cab072a05b855cbef9c585702401ac5ae29rbb/*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * Sample content handler. All this does is display the call list that has
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * been built up so far.
3d96ee83babeec32482c9082c9426340cee8c44dwrowe *
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * The return value instructs the caller concerning what happened and what to
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * do next:
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * OK ("we did our thing")
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * DECLINED ("this isn't something with which we want to get involved")
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * HTTP_mumble ("an error status should be reported")
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbbstatic int example_handler(request_rec *r)
61fd0cab072a05b855cbef9c585702401ac5ae29rbb{
3d96ee83babeec32482c9082c9426340cee8c44dwrowe
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein excfg *dcfg;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
61fd0cab072a05b855cbef9c585702401ac5ae29rbb dcfg = our_dconfig(r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb trace_add(r->server, r, dcfg, "example_handler()");
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * We're about to start sending content, so we need to force the HTTP
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * headers to be sent at this point. Otherwise, no headers will be sent
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * at all. We can set any we like first, of course. **NOTE** Here's
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * where you set the "Content-type" header, and you do so by putting it in
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * r->content_type, *not* r->headers_out("Content-type"). If you don't
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * set it, it will be filled in with the server's default type (typically
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * "text/plain"). You *must* also ensure that r->content_type is lower
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * case.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb *
3d96ee83babeec32482c9082c9426340cee8c44dwrowe * We also need to start a timer so the server can know if the connexion
2d2eda71267231c2526be701fe655db125852c1ffielding * is broken.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb r->content_type = "text/html";
346029f34d03eb20d84fc35664426d3874b00f9ewrowe ap_send_http_header(r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * If we're only supposed to send header information (HEAD request), we're
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * already there.
346029f34d03eb20d84fc35664426d3874b00f9ewrowe */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb if (r->header_only) {
61fd0cab072a05b855cbef9c585702401ac5ae29rbb return OK;
61fd0cab072a05b855cbef9c585702401ac5ae29rbb }
61fd0cab072a05b855cbef9c585702401ac5ae29rbb
3d96ee83babeec32482c9082c9426340cee8c44dwrowe /*
2d2eda71267231c2526be701fe655db125852c1ffielding * Now send our actual output. Since we tagged this as being
e351a4349a3dcc2e8d9c27bcdf72414bdde0942frbb * "text/html", we need to embed any HTML.
e351a4349a3dcc2e8d9c27bcdf72414bdde0942frbb */
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(DOCTYPE_HTML_3_2, r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs("<HTML>\n", r);
2d2eda71267231c2526be701fe655db125852c1ffielding ap_rputs(" <HEAD>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" <TITLE>mod_example Module Content-Handler Output\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" </TITLE>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" </HEAD>\n", r);
2d2eda71267231c2526be701fe655db125852c1ffielding ap_rputs(" <BODY>\n", r);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe ap_rputs(" <H1><SAMP>mod_example</SAMP> Module Content-Handler Output\n", r);
2d2eda71267231c2526be701fe655db125852c1ffielding ap_rputs(" </H1>\n", r);
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_rputs(" <P>\n", r);
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_rprintf(r, " Apache HTTP Server version: \"%s\"\n",
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_get_server_version());
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_rputs(" <BR>\n", r);
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_rprintf(r, " Server built: \"%s\"\n", ap_get_server_built());
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_rputs(" </P>\n", r);;
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_rputs(" <P>\n", r);
3d96ee83babeec32482c9082c9426340cee8c44dwrowe ap_rputs(" The format for the callback trace is:\n", r);
344f3bc38dfccf6261d5bb8d689794cde113b3d6coar ap_rputs(" </P>\n", r);
d5df46b7972c0c4a5ca0ba5068e238f6053c2e6ftrawick ap_rputs(" <DL>\n", r);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding ap_rputs(" <DT><EM>n</EM>.<SAMP>&lt;routine-name&gt;", r);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding ap_rputs("(&lt;routine-data&gt;)</SAMP>\n", r);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding ap_rputs(" </DT>\n", r);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding ap_rputs(" <DD><SAMP>[&lt;applies-to&gt;]</SAMP>\n", r);
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding ap_rputs(" </DD>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" </DL>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" <P>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" The <SAMP>&lt;routine-data&gt;</SAMP> is supplied by\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" the routine when it requests the trace,\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" and the <SAMP>&lt;applies-to&gt;</SAMP> is extracted\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" from the configuration record at the time of the trace.\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" <STRONG>SVR()</STRONG> indicates a server environment\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" (blank means the main or default server, otherwise it's\n", r);
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm ap_rputs(" the name of the VirtualHost); <STRONG>DIR()</STRONG>\n", r);
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein ap_rputs(" indicates a location in the URL or filesystem\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" namespace.\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" </P>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rprintf(r, " <H2>Static callbacks so far:</H2>\n <OL>\n%s </OL>\n",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb trace);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" <H2>Request-specific callbacks so far:</H2>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rprintf(r, " <OL>\n%s </OL>\n", ap_table_get(r->notes, TRACE_NOTE));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" <H2>Environment for <EM>this</EM> call:</H2>\n", r);
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm ap_rputs(" <UL>\n", r);
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein ap_rprintf(r, " <LI>Applies-to: <SAMP>%s</SAMP>\n </LI>\n", dcfg->loc);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rprintf(r, " <LI>\"Example\" directive declared here: %s\n </LI>\n",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb (dcfg->local ? "YES" : "NO"));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rprintf(r, " <LI>\"Example\" inherited: %s\n </LI>\n",
61fd0cab072a05b855cbef9c585702401ac5ae29rbb (dcfg->congenital ? "YES" : "NO"));
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" </UL>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs(" </BODY>\n", r);
61fd0cab072a05b855cbef9c585702401ac5ae29rbb ap_rputs("</HTML>\n", r);
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm /*
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein * We're all done, so cancel the timeout we set. Since this is probably
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * the end of the request we *could* assume this would be done during
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * post-processing - but it's possible that another handler might be
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * called and inherit our outstanding timer. Not good; to each its own.
61fd0cab072a05b855cbef9c585702401ac5ae29rbb */
dad234382d8424e1c5a30af2838e172aec9d6d1bdreid /*
61fd0cab072a05b855cbef9c585702401ac5ae29rbb * We did what we wanted to do, so tell the rest of the server we
42ce672c516baf6e4eaed18ccc1647de2d456d8edougm * succeeded.
fd0edaa8e3d4dd67d0604ccef2e96b071db96643fielding */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb return OK;
a6b9ed64fdf548c61de9714e2cfb999ec59d149cgstein}
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/*--------------------------------------------------------------------------*/
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* Now let's declare routines for each of the callback phase in order. */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* (That's the order in which they're listed in the callback list, *not */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* the order in which the server calls them! See the command_rec */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* declaration near the bottom of this file.) Note that these may be */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* called for situations that don't relate primarily to our function - in */
8b7047e519340545e6807c9749576a40a76b6d3frbb/* other words, the fixup handler shouldn't assume that the request has */
8b7047e519340545e6807c9749576a40a76b6d3frbb/* to do with "example" stuff. */
8b7047e519340545e6807c9749576a40a76b6d3frbb/* */
6d00a43be9ab145c89e8cc22bad59e3aa746f761jwoolley/* With the exception of the content handler, all of our routines will be */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* called for each request, unless an earlier handler from another module */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* aborted the sequence. */
9484ae61c7cc5fa8d8d9a836efdbdb1e88d3036dwrowe/* */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* Handlers that are declared as "int" can return the following: */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* OK Handler accepted the request and did its thing with it. */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* DECLINED Handler took no action. */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* HTTP_mumble Handler looked at request and found it wanting. */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* What the server does after calling a module handler depends upon the */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* handler's return value. In all cases, if the handler returns */
561e5f16a2f9fb397aac4c283aaa87a752520a4ddougm/* DECLINED, the server will continue to the next module with an handler */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* for the current phase. However, if the handler return a non-OK, */
561e5f16a2f9fb397aac4c283aaa87a752520a4ddougm/* non-DECLINED status, the server aborts the request right there. If */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* the handler returns OK, the server's next action is phase-specific; */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* see the individual handler comments below for details. */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/* */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/*--------------------------------------------------------------------------*/
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/*
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb * This function is called during server initialisation. Any information
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb * that needs to be recorded must be in static cells, since there's no
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb * configuration record.
561e5f16a2f9fb397aac4c283aaa87a752520a4ddougm *
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb * There is no return value.
561e5f16a2f9fb397aac4c283aaa87a752520a4ddougm */
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb
fcc25eda7b150e226d3c1cdaea66a943d3fdee4erbb/*
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * All our module initialiser does is add its trace to the log.
c9a95767fbf0f5fb0976a06b97a256033925e433rbb */
c9a95767fbf0f5fb0976a06b97a256033925e433rbbstatic void example_init(server_rec *s, ap_context_t *p)
c9a95767fbf0f5fb0976a06b97a256033925e433rbb{
c9a95767fbf0f5fb0976a06b97a256033925e433rbb
c9a95767fbf0f5fb0976a06b97a256033925e433rbb char *note;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb char *sname = s->server_hostname;
c9a95767fbf0f5fb0976a06b97a256033925e433rbb
c9a95767fbf0f5fb0976a06b97a256033925e433rbb /*
c9a95767fbf0f5fb0976a06b97a256033925e433rbb * Set up any module cells that ought to be initialised.
c9a95767fbf0f5fb0976a06b97a256033925e433rbb */
c9a95767fbf0f5fb0976a06b97a256033925e433rbb setup_module_cells();
c9a95767fbf0f5fb0976a06b97a256033925e433rbb /*
2d2eda71267231c2526be701fe655db125852c1ffielding * The arbitrary text we add to our trace entry indicates for which server
2d2eda71267231c2526be701fe655db125852c1ffielding * we're being called.
2d2eda71267231c2526be701fe655db125852c1ffielding */
2d2eda71267231c2526be701fe655db125852c1ffielding sname = (sname != NULL) ? sname : "";
2d2eda71267231c2526be701fe655db125852c1ffielding note = ap_pstrcat(p, "example_init(", sname, ")", NULL);
trace_add(s, NULL, NULL, note);
}
/*
* This function is called during server initialisation when an heavy-weight
* process (such as a child) is being initialised. As with the
* module initialisation function, any information that needs to be recorded
* must be in static cells, since there's no configuration record.
*
* There is no return value.
*/
/*
* All our process initialiser does is add its trace to the log.
*/
static void example_child_init(server_rec *s, ap_context_t *p)
{
char *note;
char *sname = s->server_hostname;
/*
* Set up any module cells that ought to be initialised.
*/
setup_module_cells();
/*
* The arbitrary text we add to our trace entry indicates for which server
* we're being called.
*/
sname = (sname != NULL) ? sname : "";
note = ap_pstrcat(p, "example_child_init(", sname, ")", NULL);
trace_add(s, NULL, NULL, note);
}
/*
* This function is called when an heavy-weight process (such as a child) is
* being run down or destroyed. As with the child initialisation function,
* any information that needs to be recorded must be in static cells, since
* there's no configuration record.
*
* There is no return value.
*/
/*
* All our process-death routine does is add its trace to the log.
*/
static void example_child_exit(server_rec *s, ap_context_t *p)
{
char *note;
char *sname = s->server_hostname;
/*
* The arbitrary text we add to our trace entry indicates for which server
* we're being called.
*/
sname = (sname != NULL) ? sname : "";
note = ap_pstrcat(p, "example_child_exit(", sname, ")", NULL);
trace_add(s, NULL, NULL, note);
}
/*
* This function gets called to create up a per-directory configuration
* record. This will be called for the "default" server environment, and for
* each directory for which the parser finds any of our directives applicable.
* If a directory doesn't have any of our directives involved (i.e., they
* aren't in the .htaccess file, or a <Location>, <Directory>, or related
* block), this routine will *not* be called - the configuration for the
* closest ancestor is used.
*
* The return value is a pointer to the created module-specific
* structure.
*/
static void *example_create_dir_config(ap_context_t *p, char *dirspec)
{
excfg *cfg;
char *dname = dirspec;
/*
* Allocate the space for our record from the pool supplied.
*/
cfg = (excfg *) ap_pcalloc(p, sizeof(excfg));
/*
* Now fill in the defaults. If there are any `parent' configuration
* records, they'll get merged as part of a separate callback.
*/
cfg->local = 0;
cfg->congenital = 0;
cfg->cmode = CONFIG_MODE_DIRECTORY;
/*
* Finally, add our trace to the callback list.
*/
dname = (dname != NULL) ? dname : "";
cfg->loc = ap_pstrcat(p, "DIR(", dname, ")", NULL);
trace_add(NULL, NULL, cfg, "example_create_dir_config()");
return (void *) cfg;
}
/*
* This function gets called to merge two per-directory configuration
* records. This is typically done to cope with things like .htaccess files
* or <Location> directives for directories that are beneath one for which a
* configuration record was already created. The routine has the
* responsibility of creating a new record and merging the contents of the
* other two into it appropriately. If the module doesn't declare a merge
* routine, the record for the closest ancestor location (that has one) is
* used exclusively.
*
* The routine MUST NOT modify any of its arguments!
*
* The return value is a pointer to the created module-specific structure
* containing the merged values.
*/
static void *example_merge_dir_config(ap_context_t *p, void *parent_conf,
void *newloc_conf)
{
excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg));
excfg *pconf = (excfg *) parent_conf;
excfg *nconf = (excfg *) newloc_conf;
char *note;
/*
* Some things get copied directly from the more-specific record, rather
* than getting merged.
*/
merged_config->local = nconf->local;
merged_config->loc = ap_pstrdup(p, nconf->loc);
/*
* Others, like the setting of the `congenital' flag, get ORed in. The
* setting of that particular flag, for instance, is TRUE if it was ever
* true anywhere in the upstream configuration.
*/
merged_config->congenital = (pconf->congenital | pconf->local);
/*
* If we're merging records for two different types of environment (server
* and directory), mark the new record appropriately. Otherwise, inherit
* the current value.
*/
merged_config->cmode =
(pconf->cmode == nconf->cmode) ? pconf->cmode : CONFIG_MODE_COMBO;
/*
* Now just record our being called in the trace list. Include the
* locations we were asked to merge.
*/
note = ap_pstrcat(p, "example_merge_dir_config(\"", pconf->loc, "\",\"",
nconf->loc, "\")", NULL);
trace_add(NULL, NULL, merged_config, note);
return (void *) merged_config;
}
/*
* This function gets called to create a per-server configuration
* record. It will always be called for the "default" server.
*
* The return value is a pointer to the created module-specific
* structure.
*/
static void *example_create_server_config(ap_context_t *p, server_rec *s)
{
excfg *cfg;
char *sname = s->server_hostname;
/*
* As with the example_create_dir_config() reoutine, we allocate and fill
* in an empty record.
*/
cfg = (excfg *) ap_pcalloc(p, sizeof(excfg));
cfg->local = 0;
cfg->congenital = 0;
cfg->cmode = CONFIG_MODE_SERVER;
/*
* Note that we were called in the trace list.
*/
sname = (sname != NULL) ? sname : "";
cfg->loc = ap_pstrcat(p, "SVR(", sname, ")", NULL);
trace_add(s, NULL, cfg, "example_create_server_config()");
return (void *) cfg;
}
/*
* This function gets called to merge two per-server configuration
* records. This is typically done to cope with things like virtual hosts and
* the default server configuration The routine has the responsibility of
* creating a new record and merging the contents of the other two into it
* appropriately. If the module doesn't declare a merge routine, the more
* specific existing record is used exclusively.
*
* The routine MUST NOT modify any of its arguments!
*
* The return value is a pointer to the created module-specific structure
* containing the merged values.
*/
static void *example_merge_server_config(ap_context_t *p, void *server1_conf,
void *server2_conf)
{
excfg *merged_config = (excfg *) ap_pcalloc(p, sizeof(excfg));
excfg *s1conf = (excfg *) server1_conf;
excfg *s2conf = (excfg *) server2_conf;
char *note;
/*
* Our inheritance rules are our own, and part of our module's semantics.
* Basically, just note whence we came.
*/
merged_config->cmode =
(s1conf->cmode == s2conf->cmode) ? s1conf->cmode : CONFIG_MODE_COMBO;
merged_config->local = s2conf->local;
merged_config->congenital = (s1conf->congenital | s1conf->local);
merged_config->loc = ap_pstrdup(p, s2conf->loc);
/*
* Trace our call, including what we were asked to merge.
*/
note = ap_pstrcat(p, "example_merge_server_config(\"", s1conf->loc, "\",\"",
s2conf->loc, "\")", NULL);
trace_add(NULL, NULL, merged_config, note);
return (void *) merged_config;
}
/*
* 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.
*
* The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
* further modules are called for this phase.
*/
static int example_post_read_request(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
trace_add(r->server, r, cfg, "example_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.
*
* The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
* further modules are called for this phase.
*/
static int example_translate_handler(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
/*
* We don't actually *do* anything here, except note the fact that we were
* called.
*/
trace_add(r->server, r, cfg, "example_translate_handler()");
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).
*
* The return value is OK, DECLINED, or some HTTP_mumble error (typically
* HTTP_UNAUTHORIZED). If we return OK, no other modules are given a chance
* at the request during this phase.
*/
static int example_check_user_id(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
/*
* Don't do anything except log the call.
*/
trace_add(r->server, r, cfg, "example_check_user_id()");
return DECLINED;
}
/*
* This routine is called to check to see if the resource being requested
* requires authorisation.
*
* 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 example_auth_checker(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
/*
* Log the call and return OK, or access will be denied (even though we
* didn't actually do anything).
*/
trace_add(r->server, r, cfg, "example_auth_checker()");
return DECLINED;
}
/*
* This routine is called to check for any module-specific restrictions placed
* upon the requested resource. (See the mod_access module for an example.)
*
* The return value is OK, DECLINED, or HTTP_mumble. All modules with an
* handler for this phase are called regardless of whether their predecessors
* return OK or DECLINED. The first one to return any other status, however,
* will abort the sequence (and the request) as usual.
*/
static int example_access_checker(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
trace_add(r->server, r, cfg, "example_access_checker()");
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.
*
* The return value is OK, DECLINED, or HTTP_mumble. If we return OK, no
* further modules are given a chance at the request for this phase.
*/
static int example_type_checker(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
/*
* Log the call, but don't do anything else - and report truthfully that
* we didn't do anything.
*/
trace_add(r->server, r, cfg, "example_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.
*
* The return value is OK, DECLINED, or HTTP_mumble. If we return OK, the
* server will still call any remaining modules with an handler for this
* phase.
*/
static int example_fixer_upper(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
/*
* Log the call and exit.
*/
trace_add(r->server, r, cfg, "example_fixer_upper()");
return OK;
}
/*
* This routine is called to perform any module-specific logging activities
* over and above the normal server things.
*
* The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any
* remaining modules with an handler for this phase will still be called.
*/
static int example_logger(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
trace_add(r->server, r, cfg, "example_logger()");
return DECLINED;
}
/*
* This routine is called to give the module a chance to look at the request
* headers and take any appropriate specific actions early in the processing
* sequence.
*
* The return value is OK, DECLINED, or HTTP_mumble. If we return OK, any
* remaining modules with handlers for this phase will still be called.
*/
static int example_header_parser(request_rec *r)
{
excfg *cfg;
cfg = our_dconfig(r);
trace_add(r->server, r, cfg, "example_header_parser()");
return DECLINED;
}
/*--------------------------------------------------------------------------*/
/* */
/* 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 example_cmds[] =
{
{
"Example", /* directive name */
cmd_example, /* config action routine */
NULL, /* argument to include in call */
OR_OPTIONS, /* where available */
NO_ARGS, /* arguments */
"Example directive - no arguments"
/* directive description */
},
{NULL}
};
/*--------------------------------------------------------------------------*/
/* */
/* Now the list of content handlers available from this module. */
/* */
/*--------------------------------------------------------------------------*/
/*
* List of content handlers our module supplies. Each handler is defined by
* two parts: a name by which it can be referenced (such as by
* {Add,Set}Handler), and the actual routine name. The list is terminated by
* a NULL block, since it can be of variable length.
*
* Note that content-handlers are invoked on a most-specific to least-specific
* basis; that is, a handler that is declared for "text/plain" will be
* invoked before one that was declared for "text / *". Note also that
* if a content-handler returns anything except DECLINED, no other
* content-handlers will be called.
*/
static const handler_rec example_handlers[] =
{
{"example-handler", example_handler},
{NULL}
};
/*--------------------------------------------------------------------------*/
/* */
/* Finally, the list of callback routines and data structures that */
/* provide the 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.
*
* 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).
*/
module example_module =
{
STANDARD_MODULE_STUFF,
example_init, /* module initializer */
example_create_dir_config, /* per-directory config creator */
example_merge_dir_config, /* dir config merger */
example_create_server_config, /* server config creator */
example_merge_server_config, /* server config merger */
example_cmds, /* command ap_table_t */
example_handlers, /* [7] list of handlers */
example_translate_handler, /* [2] filename-to-URI translation */
example_check_user_id, /* [5] check/validate user_id */
example_auth_checker, /* [6] check user_id is valid *here* */
example_access_checker, /* [4] check access by host address */
example_type_checker, /* [7] MIME type checker/setter */
example_fixer_upper, /* [8] fixups */
example_logger, /* [10] logger */
#if MODULE_MAGIC_NUMBER >= 19970103
example_header_parser, /* [3] header parser */
#endif
#if MODULE_MAGIC_NUMBER >= 19970719
example_child_init, /* process initializer */
#endif
#if MODULE_MAGIC_NUMBER >= 19970728
example_child_exit, /* process exit/cleanup */
#endif
#if MODULE_MAGIC_NUMBER >= 19970902
example_post_read_request /* [1] post read_request handling */
#endif
};