mod_setenvif.c revision d95a7ac0fe7a06495c3aab5d684b4174f9ab282c
278N/A/* Licensed to the Apache Software Foundation (ASF) under one or more 278N/A * contributor license agreements. See the NOTICE file distributed with 278N/A * this work for additional information regarding copyright ownership. 278N/A * The ASF licenses this file to You under the Apache License, Version 2.0 278N/A * (the "License"); you may not use this file except in compliance with 278N/A * the License. You may obtain a copy of the License at 278N/A * Unless required by applicable law or agreed to in writing, software 278N/A * distributed under the License is distributed on an "AS IS" BASIS, 278N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 278N/A * See the License for the specific language governing permissions and 278N/A * limitations under the License. 278N/A * Set environment variables based on matching request headers or 278N/A * attributes against regex strings 278N/A * Paul Sutton <paul@ukweb.com> 27 Oct 1996 5680N/A * Based on mod_browser by Alexei Kosut <akosut@organic.com> 278N/A * Used to set environment variables based on the incoming request headers, 5738N/A * or some selected other attributes of the request (e.g., the remote host 1509N/A * SetEnvIf name regex var ... 278N/A * where name is either a HTTP request header name, or one of the 5738N/A * special values (see below). 'name' may be a regex when it is used 2899N/A * to specify an HTTP request header name. The 'value' of the header 5680N/A & (or the value of the special value from below) are compared against 3351N/A * the regex argument. If this is a simple string, a simple sub-string 278N/A * match is performed. Otherwise, a request expression match is 3351N/A * done. If the value matches the string or regular expression, the 3351N/A * environment variables listed as var ... are set. Each var can 3351N/A * be in one of three formats: var, which sets the named variable 278N/A * (the value value "1"); var=value, which sets the variable to 5738N/A * the given value; or !var, which unsets the variable is it has 3351N/A * Normally the strings are compared with regard to case. To ignore 278N/A * case, use the directive SetEnvIfNoCase instead. 278N/A * Special values for 'name' are: 3817N/A * server_addr IP address of interface on which request arrived 3817N/A * (analogous to SERVER_ADDR set in ap_add_common_vars()) 3817N/A * remote_host Remote host name (if available) 3817N/A * remote_addr Remote IP address 5738N/A * request_method Request method (GET, POST, etc) * request_uri Requested URI * To set the environment variable LOCALHOST if the client is the local * SetEnvIf remote_addr 127.0.0.1 LOCALHOST * 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 * To set HAVE_TS if the client request contains any header beginning * with "TS" with a value beginning with a lower case alphabet: * SetEnvIf ^TS* ^[a-z].* HAVE_TS char *
name;
/* header name */ char *
regex;
/* regex to match against */ int icase;
/* 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 AP_REG_ICASE should /* If a Header name contains characters other than: * -,_,[A-Z\, [a-z] and [0-9]. * assume the header name is a regular expression. /* If the input string does not take advantage of regular * expression metacharacters, return a pointer to an equivalent * string that can be searched using apr_strmatch(). (The * returned string will often be the input string. But if * the input string contains escaped characters, the returned * string will be a copy with the escapes removed.) * 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 */ " pattern could not be compiled.",
NULL);
" regex could not be compiled.",
NULL);
/* Syntax check and extraction of the OID as a regex: */ "^oid\\(\"?([0-9.]+)\"?\\)$",
/* this can never happen, as long as pcre works: if (new->pnamereg == NULL) return apr_pstrcat(cmd->pool, cmd->cmd->name, "OID regex could not be compiled.", NULL); "OID syntax is: oid(\"1.2.3.4.5\"); error in: ",
/* The name field is used for the stripped oid string */ /* Handle fname as a regular expression. * If fname a simple header string, identify as such * (new->pnamereg = NULL) to avoid the overhead of searching * through headers_in for a regex match. "Header name regex could not be " * 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. * This routine handles the BrowserMatch* directives. It simply turns around * and feeds them, with the appropriate embellishments, to the general-purpose "A header-name, regex and a list of variables."),
"a header-name, regex and a list of variables."),
"an expression and a list of variables."),
"A browser regex and a list of variables."),
"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 * In the case of SPECIAL_OID_VALUE values, each oid string is * dynamically allocated, thus there are no duplicates. /* If mod_ssl is not loaded, the accessor function is NULL */ /* The given oid can occur multiple times. Concatenate the values */ /* pass 1: determine the size of the string */ /* pass 2: fill the string */ /* Matching headers_in against a regex. Iterate through * the headers_in until we find a match or run out of /* Not matching against a regex */ * 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. This is also necessary to make * ap_pregsub work after evaluating an ap_expr_t which does set the /* post config handling */