httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@decus.org (Rodent of Unusual Size)
Subject Prototype template module..?
Date Fri, 28 Feb 1997 03:46:15 GMT
    Suddenly utterly fed with continually flipping back and forth to see
    the calling sequence for module callbacks, I succumbed to yet
    another mad fit of obsessing.  When I emerged, the attached lay
    beneath my fingers.

    [There's a certain amount of seriousness to that.. :->]

    Does this seem like a good sort of thing to include in the
    distribution?  Once properly fleshed out and accurised? 

    #ken    :-)}

mod_template.c:
/* ====================================================================
 * Copyright (c) 1995-1997 The Apache Group.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer. 
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. All advertising materials mentioning features or use of this
 *    software must display the following acknowledgment:
 *    "This product includes software developed by the Apache Group
 *    for use in the Apache HTTP server project (http://www.apache.org/)."
 *
 * 4. The names "Apache Server" and "Apache Group" must not be used to
 *    endorse or promote products derived from this software without
 *    prior written permission.
 *
 * 5. Redistributions of any form whatsoever must retain the following
 *    acknowledgment:
 *    "This product includes software developed by the Apache Group
 *    for use in the Apache HTTP server project (http://www.apache.org/)."
 *
 * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Group and was originally based
 * on public domain software written at the National Center for
 * Supercomputing Applications, University of Illinois, Urbana-Champaign.
 * For more information on the Apache Group and the Apache HTTP server
 * project, please see <http://www.apache.org/>.
 *
 */

/* 
 * Apache template module.  Provide examples of how modules do things.
 *
 */

#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"
#include "util_script.h"

#include <stdio.h>

/*
 * Sample configuration record.  Used for both per-directory and per-server
 * configuration data.
 */
typedef struct template_dir_config {
    char    *args;
} template_dir_config;

/*
 * Declare ourselves so the configuration routines can find and know us.
 * We'll fill it in at the end of the module.
 */
module template_module;

/*
 * The following pseudo-prototype declarations illustrate the parameters
 * passed to command handlers for the different types of directive syntax.
 */

/*
 * Command handler for a NO_ARGS directive.
 */
static const char *handle_NO_ARGS
	(cmd_parms *cmd, void *mconfig);

/*
 * Command handler for a RAW_ARGS directive.
 */
static const char *handle_RAW_ARGS
	(cmd_parms *cmd, void *mconfig, const char *args);

/*
 * Command handler for a TAKE1 directive.
 */
static const char *handle_TAKE1
	(cmd_parms *cmd, void *mconfig, char *word1);

/*
 * Command handler for a TAKE2 directive.
 */
static const char *handle_TAKE2
	(cmd_parms *cmd, void *mconfig, char *word1, char *word2);

/*
 * Command handler for a TAKE3 directive.
 */
static const char *handle_TAKE3
	(cmd_parms *cmd, void *mconfig, char *word1, char *word2, char *word3);

/*
 * Command handler for a TAKE12 directive.
 * - word2 is a NULL pointer if no second argument was specified.
 */
static const char *handle_TAKE12
	(cmd_parms *cmd, void *mconfig, char *word1, char *word2);

/*
 * Command handler for a TAKE123 directive.
 * - word2 is a NULL pointer if no second argument was specified.
 * - word3 is a NULL pointer if no third argument was specified.
 */
static const char *handle_TAKE123
	(cmd_parms *cmd, void *mconfig, char *word1, char *word2, char *word3);

/*
 * Command handler for a TAKE13 directive.
 * - word2 and word3 are NULL pointers if only one argument was specified.
 */
static const char *handle_TAKE13
	(cmd_parms *cmd, void *mconfig, char *word1, char *word2, char *word3);

/*
 * Command handler for a TAKE23 directive.
 * - word3 is a NULL pointer if no third argument was specified.
 */
static const char *handle_TAKE23
	(cmd_parms *cmd, void *mconfig, char *word1, char *word2, char *word3);

/*
 * Command handler for a ITERATE directive.
 * - Handler is called once for each of n arguments given to the directive.
 * - word1 points to each argument in turn.
 */
static const char *handle_ITERATE
	(cmd_parms *cmd, void *mconfig, char *word1);

/*
 * Command handler for a ITERATE2 directive.
 * - Handler is called once for each of the second and subsequent arguments
 *   given to the directive.
 * - word1 is the same for each call for a particular directive instance (the
 *   first argument).
 * - word2 points to each of the second and subsequent arguments in turn.
 */
static const char *handle_ITERATE2
	(cmd_parms *cmd, void *mconfig, char *word1, char *word2);

/*
 * Now some `real' routines.
 */

/*
 * Command handler for the NO_ARGS "Template" directive.
 */
static const char *cmd_template
	(cmd_parms *cmd, void *mconfig) {

    template_dir_config *cfg;

    cfg = (template_dir_config *) mconfig;

    return NULL;
}

/*
 * This function gets called to create up a per-directory configuration
 * record.
 */
void *template_dir_create
	(pool *p, char *dirspec) {

    template_dir_config
	    *cfg;

    cfg = (template_dir_config *) pcalloc (p, sizeof(template_dir_config));
    cfg->args = pstrcat (p, "directory config for ", dirspec, NULL);
    return (void *) cfg;
}

/*
 * This function gets called to create a per-server configuration
 * record.
 */
void *template_server_create
	(pool *p, server_rec *s) {

    template_dir_config
	    *cfg;

    cfg = (template_dir_config *) pcalloc (p, sizeof(template_dir_config));
    cfg->args = pstrcat (p, "server config for ", s->server_hostname, NULL);
    return (void *) cfg;
}

/*
 * Sample no-op handler (enabled by mod_mime via "AddHandler template ext" or
 * "SetHandler template").
 */
static int template_handler
	(request_rec *r) {

    return DECLINED;
}

/*
 * List of directives specific to our module.
 */
command_rec template_commands[] = {
    {
	"Template",			/* directive name */
	cmd_template,			/* action routine for directive */
	NULL,				/* argument to include in call */
	ACCESS_CONF,			/* where available */
	NO_ARGS,			/* arguments */
	"Template directive - no arguments"
					/* directive description */
    },
    { NULL }
};

/*
 * List of handlers our module supplies.
 */
handler_rec template_handlers[] = {
    { "template", template_handler },
    { NULL }
};

/*
 * Module definition for configuration.
 */
module template_module = {
    STANDARD_MODULE_STUFF,
    NULL,			/* initializer */
    template_dir_create,	/* per-directory config creater */
    NULL,			/* dir config merger - default is to override */
    template_server_create,	/* server config creator */
    NULL,			/* server config merger */
    template_commands,		/* command table */
    template_handlers,		/* handlers */
    NULL,			/* filename translation */
    NULL,			/* check_user_id */
    NULL,			/* check auth */
    NULL,			/* check access */
    NULL,			/* type_checker */
    NULL,			/* fixups */
    NULL,			/* logger */
    NULL			/* header parser */
};

Mime
View raw message