mod_rewrite.h revision b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697
/* ====================================================================
* Copyright (c) 1996-1999 The Apache Group. 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. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* 4. The names "Apache Server" and "Apache Group" 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 names without prior written
* permission of the Apache Group.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the Apache Group
* for use in the Apache HTTP server project (http://www.apache.org/)."
*
* THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``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 GROUP 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 Group and was originally based
* on public domain software written at the National Center for
* Supercomputing Applications, University of Illinois, Urbana-Champaign.
* For more information on the Apache Group and the Apache HTTP server
* project, please see <http://www.apache.org/>.
*
*/
#ifndef _MOD_REWRITE_H
#define _MOD_REWRITE_H 1
/*
** _ _ _
** _ __ ___ ___ __| | _ __ _____ ___ __(_) |_ ___
** | '_ ` _ \ / _ \ / _` | | '__/ _ \ \ /\ / / '__| | __/ _ \
** | | | | | | (_) | (_| | | | | __/\ V V /| | | | || __/
** |_| |_| |_|\___/ \__,_|___|_| \___| \_/\_/ |_| |_|\__\___|
** |_____|
**
** URL Rewriting Module
**
** This module uses a rule-based rewriting engine (based on a
** regular-expression parser) to rewrite requested URLs on the fly.
**
** It supports an unlimited number of additional rule conditions (which can
** operate on a lot of variables, even on HTTP headers) for granular
** matching and even external database lookups (either via plain text
** tables, DBM hash files or even external processes) for advanced URL
** substitution.
**
** It operates on the full URLs (including the PATH_INFO part) both in
** per-server context (httpd.conf) and per-dir context (.htaccess) and even
** can generate QUERY_STRING parts on result. The rewriting result finally
** can lead to internal subprocessing, external request redirection or even
** to internal proxy throughput.
**
** This module was originally written in April 1996 and
** gifted exclusively to the The Apache Group in July 1997 by
**
** Ralf S. Engelschall
** rse@engelschall.com
** www.engelschall.com
*/
/* Include from the underlaying Unix system ... */
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
#include <ctype.h>
/* Include from the Apache server ... */
#define CORE_PRIVATE
#include "httpd.h"
#include "http_config.h"
#include "http_conf_globals.h"
#include "http_request.h"
#include "http_core.h"
#include "http_log.h"
#include "http_vhost.h"
/*
* The key in the r->notes ap_table_t wherein we store our accumulated
* Vary values, and the one used for per-condition checks in a chain.
*/
#define VARY_KEY "rewrite-Vary"
#define VARY_KEY_THIS "rewrite-Vary-this"
/* The NDBM support:
* We support only NDBM files.
* But we have to stat the file for the mtime,
* so we also need to know the file extension
*/
#ifndef NO_DBM_REWRITEMAP
#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) \
#else
#include <ndbm.h>
#endif
#if defined(DBM_SUFFIX)
#define NDBM_FILE_SUFFIX DBM_SUFFIX
#define NDBM_FILE_SUFFIX ".db"
#else
#define NDBM_FILE_SUFFIX ".pag"
#endif
#endif
/* The locking support:
* Try to determine whether we should use fcntl() or flock().
* Would be better ap_config.h could provide this... :-(
*/
#if defined(USE_FCNTL_SERIALIZED_ACCEPT)
#define USE_FCNTL 1
#include <fcntl.h>
#endif
#if defined(USE_FLOCK_SERIALIZED_ACCEPT)
#define USE_FLOCK 1
#endif
#define USE_FLOCK 1
#endif
#ifndef LOCK_UN
#define USE_FCNTL 1
#include <fcntl.h>
#endif
#endif
#ifdef AIX
#define USE_FCNTL 1
#include <fcntl.h>
#endif
#ifdef WIN32
#define USE_LOCKING
#endif
/*
**
** Some defines
**
*/
#define ENVVAR_SCRIPT_URL "SCRIPT_URL"
#define ENVVAR_SCRIPT_URI "SCRIPT_URI"
#ifndef SUPPORT_DBM_REWRITEMAP
#define SUPPORT_DBM_REWRITEMAP 0
#endif
#define REWRITE_FORCED_MIMETYPE_NOTEVAR "rewrite-forced-mimetype"
#define CONDFLAG_NONE 1<<0
#define RULEFLAG_NONE 1<<0
#define MAPTYPE_TXT 1<<0
#define ENGINE_DISABLED 1<<0
#define OPTION_NONE 1<<0
#define CACHEMODE_TS 1<<0
#define CACHE_TLB_ROWS 1024
#define CACHE_TLB_COLS 4
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NO
#endif
#ifndef RAND_MAX
#define RAND_MAX 32767
#endif
#ifndef LONG_STRING_LEN
#define LONG_STRING_LEN 2048
#endif
#define MAX_ENV_FLAGS 15
#define MAX_NMATCH 10
/*
**
** our private data structures we handle with
**
*/
/* the list structures for holding the mapfile information
* and the rewrite rules
*/
typedef struct {
char *name; /* the name of the map */
char *datafile; /* filename for map data files */
char *checkfile; /* filename to check for map existence */
int type; /* the type of the map */
int fpin; /* in file pointer for program maps */
int fpout; /* out file pointer for program maps */
int fperr; /* err file pointer for program maps */
char *);
typedef struct {
char *input; /* Input string of RewriteCond */
char *pattern; /* the RegExp pattern string */
int flags; /* Flags which control the match */
typedef struct {
char *pattern; /* the RegExp pattern string */
char *output; /* the Substitution string */
int flags; /* Flags which control the substitution */
char *forced_mimetype; /* forced MIME type of substitution */
int forced_responsecode; /* forced HTTP redirect response status */
int skip; /* number of next rules to skip */
/* the per-server or per-virtual-server configuration
* statically generated once on startup for every server
*/
typedef struct {
int state; /* the RewriteEngine state */
int options; /* the RewriteOption state */
char *rewritelogfile; /* the RewriteLog filename */
int rewritelogfp; /* the RewriteLog open filepointer */
int rewriteloglevel; /* the RewriteLog level of verbosity */
/* the per-directory configuration
* generated on-the-fly by Apache server for current request
*/
typedef struct {
int state; /* the RewriteEngine state */
int options; /* the RewriteOption state */
char *directory; /* the directory where it applies */
char *baseurl; /* the base-URL where it applies */
/* the cache structures,
* a 4-way hash ap_table_t with LRU functionality
*/
typedef struct cacheentry {
char *key;
char *value;
} cacheentry;
typedef struct tlbentry {
int t[CACHE_TLB_COLS];
typedef struct cachelist {
char *resource;
} cachelist;
typedef struct cache {
} cache;
/* the regex structure for the
* substitution of backreferences
*/
typedef struct backrefinfo {
char *source;
int nsub;
} backrefinfo;
/*
**
** forward declarations
**
*/
/* config structure handling */
/* config directive handling */
char *option);
char *name);
char *a2);
char *a1);
char *str);
static const char *cmd_rewritecond_parseflagfield(ap_context_t *p,
char *str);
char *str);
static const char *cmd_rewriterule_parseflagfield(ap_context_t *p,
char *str);
/* initialisation */
/* 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 */
char *perdir);
char *perdir);
backrefinfo *briRC);
/* URI transformation function */
static void fully_qualify_uri(request_rec *r);
static void reduce_uri(request_rec *r);
backrefinfo *bri, char c);
/* rewrite map support functions */
#ifndef NO_DBM_REWRITEMAP
#endif
static char *lookup_map_internal(request_rec *r,
char *key);
static void rewrite_rand_init(void);
static int rewrite_rand(int l, int h);
/* rewriting logfile support */
static char *current_logtime(request_rec *r);
/* rewriting lockfile support */
static void rewritelock_remove(void *data);
static void rewritelock_alloc(request_rec *r);
static void rewritelock_free(request_rec *r);
/* program map support */
/* env variable support */
/* caching functions */
char *key);
/* misc functions */
char *subst);
static void add_env_variable(request_rec *r, char *s);
/* File locking */
/* Lexicographic Comparison */
#endif /* _MOD_REWRITE_H */
/*EOF*/