mod_rewrite.h revision 0bbb249eafe9ef9508821f0ef58e7440625ecd62
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive/* ====================================================================
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * The Apache Software License, Version 1.1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * reserved.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * Redistribution and use in source and binary forms, with or without
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * modification, are permitted provided that the following conditions
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * are met:
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * 1. Redistributions of source code must retain the above copyright
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * notice, this list of conditions and the following disclaimer.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * 2. Redistributions in binary form must reproduce the above copyright
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * notice, this list of conditions and the following disclaimer in
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * the documentation and/or other materials provided with the
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * distribution.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * 3. The end-user documentation included with the redistribution,
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * if any, must include the following acknowledgment:
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * "This product includes software developed by the
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * Apache Software Foundation (http://www.apache.org/)."
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * Alternately, this acknowledgment may appear in the software itself,
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * if and wherever such third-party acknowledgments normally appear.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * 4. The names "Apache" and "Apache Software Foundation" must
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * not be used to endorse or promote products derived from this
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * software without prior written permission. For written
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * permission, please contact apache@apache.org.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * 5. Products derived from this software may not be called "Apache",
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * nor may "Apache" appear in their name, without prior written
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * permission of the Apache Software Foundation.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * SUCH DAMAGE.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * ====================================================================
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * This software consists of voluntary contributions made by many
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * individuals on behalf of the Apache Software Foundation. For more
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * information on the Apache Software Foundation, please see
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * <http://www.apache.org/>.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive *
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * Portions of this software are based upon public domain software
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * originally written at the National Center for Supercomputing Applications,
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * University of Illinois, Urbana-Champaign.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#ifndef MOD_REWRITE_H
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MOD_REWRITE_H 1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive/*
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** _ _ _
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** _ __ ___ ___ __| | _ __ _____ ___ __(_) |_ ___
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** | '_ ` _ \ / _ \ / _` | | '__/ _ \ \ /\ / / '__| | __/ _ \
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** | | | | | | (_) | (_| | | | | __/\ V V /| | | | || __/
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** |_| |_| |_|\___/ \__,_|___|_| \___| \_/\_/ |_| |_|\__\___|
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** |_____|
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** URL Rewriting Module
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** This module uses a rule-based rewriting engine (based on a
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** regular-expression parser) to rewrite requested URLs on the fly.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** It supports an unlimited number of additional rule conditions (which can
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** operate on a lot of variables, even on HTTP headers) for granular
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** matching and even external database lookups (either via plain text
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** tables, DBM hash files or even external processes) for advanced URL
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** substitution.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** It operates on the full URLs (including the PATH_INFO part) both in
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** per-server context (httpd.conf) and per-dir context (.htaccess) and even
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** can generate QUERY_STRING parts on result. The rewriting result finally
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** can lead to internal subprocessing, external request redirection or even
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** to internal proxy throughput.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** This module was originally written in April 1996 and
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** gifted exclusively to the The Apache Software Foundation in July 1997 by
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** Ralf S. Engelschall
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** rse@engelschall.com
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** www.engelschall.com
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive*/
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "apr.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define APR_WANT_STRFUNC
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define APR_WANT_MEMFUNC
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "apr_want.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive /* Include from the underlaying Unix system ... */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#if APR_HAVE_STDARG_H
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include <stdarg.h>
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#if APR_HAVE_STDLIB_H
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include <stdlib.h>
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#if APR_HAVE_CTYPE_H
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include <ctype.h>
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#if APR_HAVE_SYS_TYPES_H
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include <sys/types.h>
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#if APR_HAS_THREADS
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "apr_thread_mutex.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "apr_optional.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "apr_dbm.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "ap_config.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive /* Include from the Apache server ... */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CORE_PRIVATE
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "httpd.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "http_config.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "http_request.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "http_core.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "http_log.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#include "http_vhost.h"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive /*
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * The key in the r->notes apr_table_t wherein we store our accumulated
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * Vary values, and the one used for per-condition checks in a chain.
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define VARY_KEY "rewrite-Vary"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define VARY_KEY_THIS "rewrite-Vary-this"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive/*
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** Some defines
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive*/
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define ENVVAR_SCRIPT_URL "SCRIPT_URL"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define ENVVAR_SCRIPT_URI "SCRIPT_URI"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define REWRITE_FORCED_MIMETYPE_NOTEVAR "rewrite-forced-mimetype"
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CONDFLAG_NONE 1<<0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CONDFLAG_NOCASE 1<<1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CONDFLAG_NOTMATCH 1<<2
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CONDFLAG_ORNEXT 1<<3
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_NONE 1<<0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_FORCEREDIRECT 1<<1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_LASTRULE 1<<2
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_NEWROUND 1<<3
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_CHAIN 1<<4
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_IGNOREONSUBREQ 1<<5
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_NOTMATCH 1<<6
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_PROXY 1<<7
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_PASSTHROUGH 1<<8
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_FORBIDDEN 1<<9
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_GONE 1<<10
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_QSAPPEND 1<<11
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_NOCASE 1<<12
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RULEFLAG_NOESCAPE 1<<13
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define ACTION_NORMAL 1<<0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define ACTION_NOESCAPE 1<<1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAPTYPE_TXT 1<<0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAPTYPE_DBM 1<<1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAPTYPE_PRG 1<<2
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAPTYPE_INT 1<<3
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAPTYPE_RND 1<<4
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define ENGINE_DISABLED 1<<0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define ENGINE_ENABLED 1<<1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define OPTION_NONE 1<<0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define OPTION_INHERIT 1<<1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CACHEMODE_TS 1<<0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CACHEMODE_TTL 1<<1
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CACHE_TLB_ROWS 1024
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define CACHE_TLB_COLS 4
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#ifndef FALSE
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define FALSE 0
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define TRUE !FALSE
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#ifndef NO
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define NO FALSE
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define YES TRUE
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#ifndef RAND_MAX
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define RAND_MAX 32767
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#ifndef LONG_STRING_LEN
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define LONG_STRING_LEN 2048
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#endif
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAX_ENV_FLAGS 15
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAX_COOKIE_FLAGS 15
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive/*** max cookie size in rfc 2109 ***/
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAX_COOKIE_LEN 4096
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive#define MAX_NMATCH 10
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive/*
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive** our private data structures we handle with
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive**
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive*/
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive /* the list structures for holding the mapfile information
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * and the rewrite rules
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslivetypedef struct {
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive const char *name; /* the name of the map */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive const char *datafile; /* filename for map data files */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive const char *dbmtype; /* dbm type for dbm map data files */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive const char *checkfile; /* filename to check for map existence */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int type; /* the type of the map */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_file_t *fpin; /* in file pointer for program maps */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_file_t *fpout; /* out file pointer for program maps */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_file_t *fperr; /* err file pointer for program maps */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *(*func)(request_rec *, /* function pointer for internal maps */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *);
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char **argv;
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive} rewritemap_entry;
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslivetypedef struct {
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *input; /* Input string of RewriteCond */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *pattern; /* the RegExp pattern string */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive regex_t *regexp;
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int flags; /* Flags which control the match */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive} rewritecond_entry;
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslivetypedef struct {
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_array_header_t *rewriteconds; /* the corresponding RewriteCond entries */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *pattern; /* the RegExp pattern string */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive regex_t *regexp; /* the RegExp pattern compilation */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *output; /* the Substitution string */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int flags; /* Flags which control the substitution */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *forced_mimetype; /* forced MIME type of substitution */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int forced_responsecode; /* forced HTTP redirect response status */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *env[MAX_ENV_FLAGS+1]; /* added environment variables */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive char *cookie[MAX_COOKIE_FLAGS+1]; /* added cookies */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int skip; /* number of next rules to skip */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive} rewriterule_entry;
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive /* the per-server or per-virtual-server configuration
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * statically generated once on startup for every server
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslivetypedef struct {
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int state; /* the RewriteEngine state */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int options; /* the RewriteOption state */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive const char *rewritelogfile; /* the RewriteLog filename */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_file_t *rewritelogfp; /* the RewriteLog open filepointer */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive int rewriteloglevel; /* the RewriteLog level of verbosity */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_array_header_t *rewritemaps; /* the RewriteMap entries */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_array_header_t *rewriteconds; /* the RewriteCond entries (temporary) */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive apr_array_header_t *rewriterules; /* the RewriteRule entries */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive server_rec *server; /* the corresponding server indicator */
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive} rewrite_server_conf;
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive /* the per-directory configuration
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive * generated on-the-fly by Apache server for current request
3fa58e00171aebf3b2cfa90035ed530f5b1f651dslive */
typedef struct {
int state; /* the RewriteEngine state */
int options; /* the RewriteOption state */
apr_array_header_t *rewriteconds; /* the RewriteCond entries (temporary) */
apr_array_header_t *rewriterules; /* the RewriteRule entries */
char *directory; /* the directory where it applies */
const char *baseurl; /* the base-URL where it applies */
} rewrite_perdir_conf;
/* the cache structures,
* a 4-way hash apr_table_t with LRU functionality
*/
typedef struct cacheentry {
apr_time_t time;
char *key;
char *value;
} cacheentry;
typedef struct tlbentry {
int t[CACHE_TLB_COLS];
} cachetlbentry;
typedef struct cachelist {
char *resource;
apr_array_header_t *entries;
apr_array_header_t *tlb;
} cachelist;
typedef struct cache {
apr_pool_t *pool;
apr_array_header_t *lists;
#if APR_HAS_THREADS
apr_thread_mutex_t *lock;
#endif
} cache;
/* the regex structure for the
* substitution of backreferences
*/
typedef struct backrefinfo {
char *source;
int nsub;
regmatch_t regmatch[10];
} backrefinfo;
/*
**
** forward declarations
**
*/
/* config structure handling */
static void *config_server_create(apr_pool_t *p, server_rec *s);
static void *config_server_merge (apr_pool_t *p, void *basev, void *overridesv);
static void *config_perdir_create(apr_pool_t *p, char *path);
static void *config_perdir_merge (apr_pool_t *p, void *basev, void *overridesv);
/* config directive handling */
static const char *cmd_rewriteengine(cmd_parms *cmd,
void *dconf, int flag);
static const char *cmd_rewriteoptions(cmd_parms *cmd,
void *dconf,
const char *option);
static const char *cmd_rewriteoptions_setoption(apr_pool_t *p, int *options,
const char *name);
static const char *cmd_rewritelog (cmd_parms *cmd, void *dconf, const char *a1);
static const char *cmd_rewriteloglevel(cmd_parms *cmd, void *dconf, const char *a1);
static const char *cmd_rewritemap (cmd_parms *cmd, void *dconf,
const char *a1, const char *a2);
static const char *cmd_rewritelock(cmd_parms *cmd, void *dconf, const char *a1);
static const char *cmd_rewritebase(cmd_parms *cmd, void *dconf,
const char *a1);
static const char *cmd_rewritecond(cmd_parms *cmd, void *dconf,
const char *str);
static const char *cmd_rewritecond_parseflagfield(apr_pool_t *p,
rewritecond_entry *new,
char *str);
static const char *cmd_rewritecond_setflag(apr_pool_t *p, rewritecond_entry *cfg,
char *key, char *val);
static const char *cmd_rewriterule(cmd_parms *cmd, void *dconf,
const char *str);
static const char *cmd_rewriterule_parseflagfield(apr_pool_t *p,
rewriterule_entry *new,
char *str);
static const char *cmd_rewriterule_setflag(apr_pool_t *p, rewriterule_entry *cfg,
char *key, char *val);
/* initialisation */
static int pre_config(apr_pool_t *pconf,
apr_pool_t *plog,
apr_pool_t *ptemp);
static int post_config(apr_pool_t *pconf,
apr_pool_t *plog,
apr_pool_t *ptemp,
server_rec *s);
static void init_child(apr_pool_t *p, server_rec *s);
/* runtime hooks */
static int hook_uri2file (request_rec *r);
static int hook_mimetype (request_rec *r);
static int hook_fixup (request_rec *r);
static int handler_redirect(request_rec *r);
/* rewriting engine */
static int apply_rewrite_list(request_rec *r, apr_array_header_t *rewriterules,
char *perdir);
static int apply_rewrite_rule(request_rec *r, rewriterule_entry *p,
char *perdir);
static int apply_rewrite_cond(request_rec *r, rewritecond_entry *p,
char *perdir, backrefinfo *briRR,
backrefinfo *briRC);
static void do_expand(request_rec *r, char *input, char *buffer, int nbuf,
backrefinfo *briRR, backrefinfo *briRC);
static void do_expand_env(request_rec *r, char *env[],
backrefinfo *briRR, backrefinfo *briRC);
static void do_expand_cookie(request_rec *r, char *cookie[],
backrefinfo *briRR, backrefinfo *briRC);
/* URI transformation function */
static void splitout_queryargs(request_rec *r, int qsappend);
static void fully_qualify_uri(request_rec *r);
static void reduce_uri(request_rec *r);
static int is_absolute_uri(char *uri);
static char *expand_tildepaths(request_rec *r, char *uri);
/* rewrite map support functions */
static char *lookup_map(request_rec *r, char *name, char *key);
static char *lookup_map_txtfile(request_rec *r, const char *file, char *key);
static char *lookup_map_dbmfile(request_rec *r, const char *file,
const char *dbmtype, char *key);
static char *lookup_map_program(request_rec *r, apr_file_t *fpin,
apr_file_t *fpout, char *key);
typedef char *(rewrite_mapfunc_t)(request_rec *r, char *key);
static void ap_register_rewrite_mapfunc(char *name, rewrite_mapfunc_t *func);
APR_DECLARE_OPTIONAL_FN(void, ap_register_rewrite_mapfunc,
(char *name, rewrite_mapfunc_t *func));
static char *rewrite_mapfunc_toupper(request_rec *r, char *key);
static char *rewrite_mapfunc_tolower(request_rec *r, char *key);
static char *rewrite_mapfunc_escape(request_rec *r, char *key);
static char *rewrite_mapfunc_unescape(request_rec *r, char *key);
static char *select_random_value_part(request_rec *r, char *value);
static void rewrite_rand_init(void);
static int rewrite_rand(int l, int h);
/* rewriting logfile support */
static void open_rewritelog(server_rec *s, apr_pool_t *p);
static void rewritelog(request_rec *r, int level, const char *text, ...)
__attribute__((format(printf,3,4)));
static char *current_logtime(request_rec *r);
/* rewriting lockfile support */
static apr_status_t rewritelock_create(server_rec *s, apr_pool_t *p);
static apr_status_t rewritelock_remove(void *data);
/* program map support */
static apr_status_t run_rewritemap_programs(server_rec *s, apr_pool_t *p);
static apr_status_t rewritemap_program_child(apr_pool_t *p,
const char *progname, char **argv,
apr_file_t **fpout,
apr_file_t **fpin);
/* env variable support */
static char *lookup_variable(request_rec *r, char *var);
static char *lookup_header(request_rec *r, const char *name);
/* caching functions */
static cache *init_cache(apr_pool_t *p);
static char *get_cache_string(cache *c, const char *res, int mode, apr_time_t mtime,
char *key);
static void set_cache_string(cache *c, const char *res, int mode, apr_time_t mtime,
char *key, char *value);
static cacheentry *retrieve_cache_string(cache *c, const char *res, char *key);
static void store_cache_string(cache *c, const char *res, cacheentry *ce);
/* misc functions */
static char *subst_prefix_path(request_rec *r, char *input, char *match,
const char *subst);
static int parseargline(char *str, char **a1, char **a2, char **a3);
static int prefix_stat(const char *path, apr_finfo_t *sb);
static void add_env_variable(request_rec *r, char *s);
static void add_cookie(request_rec *r, char *s);
static int subreq_ok(request_rec *r);
/* Lexicographic Comparison */
static int compare_lexicography(char *cpNum1, char *cpNum2);
/* Bracketed expression handling */
static char *find_closing_bracket(char *s, int left, int right);
static char *find_char_in_brackets(char *s, int c, int left, int right);
#endif /* MOD_REWRITE_H */