mod_setenvif.c revision d41217398f0e1031adbb6f5bd37f45737c805def
2073N/A/* ==================================================================== 2073N/A * The Apache Software License, Version 1.1 2073N/A * Copyright (c) 2000 The Apache Software Foundation. All rights 2073N/A * Redistribution and use in source and binary forms, with or without 2073N/A * modification, are permitted provided that the following conditions 2073N/A * 1. Redistributions of source code must retain the above copyright 2073N/A * notice, this list of conditions and the following disclaimer. 2073N/A * 2. Redistributions in binary form must reproduce the above copyright 2073N/A * notice, this list of conditions and the following disclaimer in 2073N/A * the documentation and/or other materials provided with the 2073N/A * 3. The end-user documentation included with the redistribution, 2073N/A * if any, must include the following acknowledgment: 2073N/A * "This product includes software developed by the 5680N/A * Alternately, this acknowledgment may appear in the software itself, 2073N/A * if and wherever such third-party acknowledgments normally appear. 2073N/A * 4. The names "Apache" and "Apache Software Foundation" must 2073N/A * not be used to endorse or promote products derived from this 2073N/A * software without prior written permission. For written 2073N/A * permission, please contact apache@apache.org. 2073N/A * 5. Products derived from this software may not be called "Apache", 2073N/A * nor may "Apache" appear in their name, without prior written 2073N/A * permission of the Apache Software Foundation. 2899N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 2899N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 5680N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 5680N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 2073N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3414N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3414N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2073N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 2073N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2073N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 5680N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2073N/A * ==================================================================== 2073N/A * This software consists of voluntary contributions made by many 2073N/A * individuals on behalf of the Apache Software Foundation. For more 2073N/A * information on the Apache Software Foundation, please see 2073N/A * Portions of this software are based upon public domain software 5680N/A * originally written at the National Center for Supercomputing Applications, 2073N/A * University of Illinois, Urbana-Champaign. 2073N/A * Set environment variables based on matching request headers or 3414N/A * attributes against regex strings 3414N/A * Paul Sutton <paul@ukweb.com> 27 Oct 1996 3414N/A * Based on mod_browser by Alexei Kosut <akosut@organic.com> 3414N/A * Used to set environment variables based on the incoming request headers, 3414N/A * or some selected other attributes of the request (e.g., the remote host 3414N/A * SetEnvIf name regex var ... 3414N/A * where name is either a HTTP request header name, or one of the 3414N/A * special values (see below). The 'value' of the header (or the 3414N/A * value of the special value from below) are compared against the 3414N/A * regex argument. If this is a simple string, a simple sub-string 3414N/A * match is performed. Otherwise, a request expression match is 3588N/A * done. If the value matches the string or regular expression, the 3588N/A * environment variables listed as var ... are set. Each var can 3588N/A * be in one of three formats: var, which sets the named variable 3588N/A * (the value value "1"); var=value, which sets the variable to 4766N/A * the given value; or !var, which unsets the variable is it has 4766N/A * Normally the strings are compared with regard to case. To ignore 4766N/A * case, use the directive SetEnvIfNoCase instead. 4766N/A * Special values for 'name' are: 4766N/A * remote_host Remote host name (if available) 4766N/A * remote_addr Remote IP address 4766N/A * remote_user Remote authenticated user (if any) 4766N/A * request_method Request method (GET, POST, etc) 4766N/A * request_uri Requested URI 4766N/A * To set the enviroment variable LOCALHOST if the client is the local 4766N/A * SetEnvIf remote_addr 127.0.0.1 LOCALHOST 3817N/A * To set LOCAL if the client is the local host, or within our company's * 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 char *
name;
/* header name */ char *
regex;
/* regex to match against */ unsigned icase :
1;
/* ignoring case? */ * These routines, the create- and merge-config functions, are called * for both the server-wide and the per-directory contexts. This is * because the different definitions are used at different times; the * server-wide ones are used in the post-read-request phase, and the * per-directory ones are used during the header-parse phase (after * the URI has been mapped to a file and we have anything from the * .htaccess file and <Directory> and <Files> containers). * any non-NULL magic constant will do... used to indicate if REG_ICASE should * Determine from our context into which record to put the entry. * cmd->path == NULL means we're in server-wide context; otherwise, * we're dealing with a per-directory setting. * 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. /* if the last entry has an identical headername and regex then /* no match, create a new entry */ " regex could not be compiled.",
NULL);
* This routine handles the BrowserMatch* directives. It simply turns around * and feeds them, with the appropriate embellishments, to the general-purpose OR_FILEINFO,
"A header-name, regex and a list of variables."),
OR_FILEINFO,
"a header-name, regex and a list of variables."),
OR_FILEINFO,
"A browser regex and a list of variables."),
OR_FILEINFO,
"A browser regex and a list of variables."),
* This routine gets called at two different points in request processing: * once before the URI has been translated (during the post-read-request * phase) and once after (during the header-parse phase). We use different * config records for the two different calls to reduce overhead (by not * re-doing the server-wide settings during directory processing), and * signal which call it is by having the earlier one pass a flag to the /* 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 * 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.