mod_setenvif.c revision 404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004b
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. 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
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``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 SOFTWARE FOUNDATION 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 Software Foundation. For more
* information on the Apache Software Foundation, please see
*
* Portions of this software are based upon public domain software
* originally written at the National Center for Supercomputing Applications,
* University of Illinois, Urbana-Champaign.
*/
/*
* Set environment variables based on matching request headers or
* attributes against regex strings
*
* Paul Sutton <paul@ukweb.com> 27 Oct 1996
* Based on mod_browser by Alexei Kosut <akosut@organic.com>
*/
/*
* Used to set environment variables based on the incoming request headers,
* or some selected other attributes of the request (e.g., the remote host
* name).
*
* Usage:
*
* SetEnvIf name regex var ...
*
* where name is either a HTTP request header name, or one of the
* special values (see below). The 'value' of the header (or the
* value of the special value from below) are compared against the
* regex argument. If this is a simple string, a simple sub-string
* match is performed. Otherwise, a request expression match is
* done. If the value matches the string or regular expression, the
* environment variables listed as var ... are set. Each var can
* be in one of three formats: var, which sets the named variable
* (the value value "1"); var=value, which sets the variable to
* the given value; or !var, which unsets the variable is it has
* been previously set.
*
* Normally the strings are compared with regard to case. To ignore
* case, use the directive SetEnvIfNoCase instead.
*
* Special values for 'name' are:
*
* remote_host Remote host name (if available)
* remote_addr Remote IP address
* remote_user Remote authenticated user (if any)
* request_method Request method (GET, POST, etc)
* request_uri Requested URI
*
* Examples:
*
* To set the enviroment variable LOCALHOST if the client is the local
* machine:
*
* SetEnvIf remote_addr 127.0.0.1 LOCALHOST
*
* To set LOCAL if the client is the local host, or within our company's
* domain (192.168.10):
*
* SetEnvIf remote_addr 192.168.10. LOCAL
* SetEnvIf remote_addr 127.0.0.1 LOCALHOST
*
* This could be written as:
*
* SetEnvIf remote_addr (127.0.0.1|192.168.10.) LOCAL
*/
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
enum special {
};
typedef struct {
char *name; /* header name */
char *regex; /* regex to match against */
ENUM_BITFIELD( /* is it a "special" header ? */
enum special,
special_type,4);
} sei_entry;
typedef struct {
} sei_cfg_rec;
{
return (void *) new;
}
{
return a;
}
/* any non-NULL magic constant will do... used to indicate if REG_ICASE should
* be used
*/
#define ICASE_MAGIC ((void *)(&setenvif_module))
{
char *regex;
const char *feature;
char *var;
int i;
int beenhere = 0;
unsigned icase;
/* get regex */
if (!*regex) {
}
/*
* If we've already got a sei_entry with the same name we want to
* just copy the name pointer... so that later on we can compare
* two header names just by comparing the pointers.
*/
break;
}
}
/* if the last entry has an idential headername and regex then
* merge with it
*/
if (i < 0
/* no match, create a new entry */
" regex could not be compiled.", NULL);
}
}
}
}
}
}
}
else {
}
}
else {
}
for ( ; ; ) {
if (!*feature) {
break;
}
beenhere++;
if (*feature) {
}
else if (*var == '!') {
}
else {
}
}
if (!beenhere) {
}
return NULL;
}
const char *args)
{
char *fname;
/* get header name */
if (!*fname) {
}
}
/*
* This routine handles the BrowserMatch* directives. It simply turns around
* and feeds them, with the appropriate embellishments, to the general-purpose
* command handler.
*/
{
}
static const command_rec setenvif_module_cmds[] =
{
{ NULL },
};
static int match_headers(request_rec *r)
{
server_rec *s = r->server;
const char *val;
int i, j;
char *last_name;
/* Optimize the case where a bunch of directives in a row use the
* same header. Remember we don't need to strcmp the two header
* names because we made sure the pointers were equal during
* configuration.
*/
switch (b->special_type) {
case SPECIAL_REMOTE_ADDR:
break;
case SPECIAL_REMOTE_HOST:
break;
case SPECIAL_REMOTE_USER:
break;
case SPECIAL_REQUEST_URI:
break;
case SPECIAL_REQUEST_METHOD:
break;
case SPECIAL_REQUEST_PROTOCOL:
break;
case SPECIAL_NOT:
}
break;
}
}
/*
* A NULL value indicates that the header field or special entity
* wasn't present or is undefined. Represent that as an empty string
* so that REs like "^$" will work and allow envariable setting
* based on missing or empty field.
*/
val = "";
}
}
else {
}
}
}
}
return DECLINED;
}
static void register_hooks(void)
{
}
{
NULL, /* dir config creater */
NULL, /* dir merger --- default is to override */
create_setenvif_config, /* server config */
merge_setenvif_config, /* merge server configs */
setenvif_module_cmds, /* command ap_table_t */
NULL, /* handlers */
register_hooks /* register hooks */
};