mod_setenvif.c revision 68dfc95acc4fde241e0124dd29cdda973bd6ec2c
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Licensed to the Apache Software Foundation (ASF) under one or more
842ae4bd224140319ae7feec1872b93dfd491143fielding * contributor license agreements. See the NOTICE file distributed with
842ae4bd224140319ae7feec1872b93dfd491143fielding * this work for additional information regarding copyright ownership.
842ae4bd224140319ae7feec1872b93dfd491143fielding * The ASF licenses this file to You under the Apache License, Version 2.0
842ae4bd224140319ae7feec1872b93dfd491143fielding * (the "License"); you may not use this file except in compliance with
842ae4bd224140319ae7feec1872b93dfd491143fielding * the License. You may obtain a copy of the License at
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * Unless required by applicable law or agreed to in writing, software
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * distributed under the License is distributed on an "AS IS" BASIS,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * See the License for the specific language governing permissions and
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd * limitations under the License.
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * Set environment variables based on matching request headers or
e8f95a682820a599fe41b22977010636be5c2717jim * attributes against regex strings
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * Paul Sutton <paul@ukweb.com> 27 Oct 1996
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * Based on mod_browser by Alexei Kosut <akosut@organic.com>
f0f24fc0cd692d203ba4754dc215581d7a88b5c7rbb * Used to set environment variables based on the incoming request headers,
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * or some selected other attributes of the request (e.g., the remote host
6802e2ec90893c9cf0c89149d429ad49927594a6rbb * SetEnvIf name regex var ...
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * where name is either a HTTP request header name, or one of the
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * special values (see below). 'name' may be a regex when it is used
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * to specify an HTTP request header name. The 'value' of the header
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb & (or the value of the special value from below) are compared against
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * the regex argument. If this is a simple string, a simple sub-string
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * match is performed. Otherwise, a request expression match is
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * done. If the value matches the string or regular expression, the
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * environment variables listed as var ... are set. Each var can
f0f24fc0cd692d203ba4754dc215581d7a88b5c7rbb * be in one of three formats: var, which sets the named variable
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * (the value value "1"); var=value, which sets the variable to
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * the given value; or !var, which unsets the variable is it has
c1a9af42c178bed7efa0a6bb7f45f46ffb269719rbb * been previously set.
#include "apr.h"
#include "apr_strings.h"
#include "apr_strmatch.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
#include "mod_ssl.h"
enum special {
} sei_entry;
} sei_cfg_rec;
return (void *) new;
return create_setenvif_config(p);
return create_setenvif_config(p);
const char *src = s;
int escapes_found = 0;
int in_escape = 0;
while (*src) {
switch (*src) {
if (!in_escape) {
return NULL;
in_escape = 0;
if (!in_escape) {
in_escape = 0;
if (in_escape) {
return NULL;
src++;
if (!escapes_found) {
src = s;
src++;
return unescaped;
const char *feature;
int beenhere = 0;
char *var;
if (!*feature) {
beenhere++;
if (*feature) {
if (!beenhere) {
return NULL;
char *regex;
const char *simple_pattern;
int icase;
if (!*regex) {
| AP_REG_ICASE));
const char *args)
char *fname;
if (!*fname) {
const char *args)
char *expr;
const char *err;
if (!*expr) {
if (err)
{ NULL },
char *last_name;
if (!b->expr) {
switch (b->special_type) {
case SPECIAL_REMOTE_ADDR:
case SPECIAL_SERVER_ADDR:
case SPECIAL_REMOTE_HOST:
case SPECIAL_REQUEST_URI:
case SPECIAL_REQUEST_METHOD:
case SPECIAL_REQUEST_PROTOCOL:
case SPECIAL_OID_VALUE:
char **oid_value;
int j, len = 0;
case SPECIAL_NOT:
if (b->pnamereg) {
const apr_array_header_t
val_len = 0;
if (!b->pattern) {
if (replaced) {
replaced);
if (APLOGrtrace2(r)) {
return DECLINED;
return OK;