#ifndef _MOD_REWRITE_H
#define _MOD_REWRITE_H 1
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <signal.h>
#include <errno.h>
#include <ctype.h>
#ifndef NETWARE
#include <sys/types.h>
#endif
#include <sys/stat.h>
#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"
#define VARY_KEY "rewrite-Vary"
#define VARY_KEY_THIS "rewrite-Vary-this"
#ifndef NO_DBM_REWRITEMAP
#include <ndbm.h>
#if defined(DBM_SUFFIX)
#define NDBM_FILE_SUFFIX DBM_SUFFIX
#elif defined(__FreeBSD__) || (defined(DB_LOCK) && defined(DB_SHMEM))
#define NDBM_FILE_SUFFIX ".db"
#else
#define NDBM_FILE_SUFFIX ".pag"
#endif
#endif
#if defined(HAVE_FCNTL_SERIALIZED_ACCEPT) && !defined(USE_FLOCK_SERIALIZED_ACCEPT)
#define USE_FCNTL 1
#include <fcntl.h>
#elif defined(HAVE_FLOCK_SERIALIZED_ACCEPT)
#define USE_FLOCK 1
#include <sys/file.h>
#endif
#if !defined(USE_FCNTL) && !defined(USE_FLOCK)
#define USE_FLOCK 1
#if !defined(MPE) && !defined(WIN32) && !defined(__TANDEM) && !defined(NETWARE)
#include <sys/file.h>
#endif
#ifndef LOCK_UN
#undef USE_FLOCK
#define USE_FCNTL 1
#include <fcntl.h>
#endif
#endif
#if defined(AIX) || defined(AIXIA64)
#undef USE_FLOCK
#define USE_FCNTL 1
#include <fcntl.h>
#endif
#ifdef WIN32
#undef USE_FCNTL
#define USE_LOCKING
#include <sys/locking.h>
#endif
#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 CONDFLAG_NOCASE 1<<1
#define CONDFLAG_NOTMATCH 1<<2
#define CONDFLAG_ORNEXT 1<<3
#define RULEFLAG_NONE 1<<0
#define RULEFLAG_FORCEREDIRECT 1<<1
#define RULEFLAG_LASTRULE 1<<2
#define RULEFLAG_NEWROUND 1<<3
#define RULEFLAG_CHAIN 1<<4
#define RULEFLAG_IGNOREONSUBREQ 1<<5
#define RULEFLAG_NOTMATCH 1<<6
#define RULEFLAG_PROXY 1<<7
#define RULEFLAG_PASSTHROUGH 1<<8
#define RULEFLAG_FORBIDDEN 1<<9
#define RULEFLAG_GONE 1<<10
#define RULEFLAG_QSAPPEND 1<<11
#define RULEFLAG_NOCASE 1<<12
#define RULEFLAG_NOESCAPE 1<<13
#define ACTION_NORMAL 1<<0
#define ACTION_NOESCAPE 1<<1
#define MAPTYPE_TXT 1<<0
#define MAPTYPE_DBM 1<<1
#define MAPTYPE_PRG 1<<2
#define MAPTYPE_INT 1<<3
#define MAPTYPE_RND 1<<4
#define ENGINE_DISABLED 1<<0
#define ENGINE_ENABLED 1<<1
#define OPTION_NONE 1<<0
#define OPTION_INHERIT 1<<1
#define CACHEMODE_TS 1<<0
#define CACHEMODE_TTL 1<<1
#define CACHE_TLB_ROWS 1024
#define CACHE_TLB_COLS 4
#ifndef FALSE
#define FALSE 0
#define TRUE !FALSE
#endif
#ifndef NO
#define NO FALSE
#define YES TRUE
#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
typedef
struct
{
char
*name;
char
*datafile;
char
*checkfile;
int
type;
int
fpin;
int
fpout;
int
fperr;
char
*(*func)(request_rec *,
char
*);
} rewritemap_entry;
typedef
struct
{
char
*input;
char
*pattern;
regex_t *regexp;
int
flags;
} rewritecond_entry;
typedef
struct
{
array_header *rewriteconds;
char
*pattern;
regex_t *regexp;
char
*output;
int
flags;
char
*forced_mimetype;
int
forced_responsecode;
char
*env[MAX_ENV_FLAGS+1];
int
skip;
} rewriterule_entry;
typedef
struct
{
int
state;
int
options;
char
*rewritelogfile;
int
rewritelogfp;
int
rewriteloglevel;
array_header *rewritemaps;
array_header *rewriteconds;
array_header *rewriterules;
server_rec *server;
} rewrite_server_conf;
typedef
struct
{
int
state;
int
options;
array_header *rewriteconds;
array_header *rewriterules;
char
*directory;
char
*baseurl;
} rewrite_perdir_conf;
typedef
struct
cacheentry {
time_t
time
;
char
*key;
char
*value;
} cacheentry;
typedef
struct
tlbentry {
int
t[CACHE_TLB_COLS];
} cachetlbentry;
typedef
struct
cachelist {
char
*resource;
array_header *entries;
array_header *tlb;
} cachelist;
typedef
struct
cache {
pool *pool;
array_header *lists;
} cache;
typedef
struct
backrefinfo {
char
*source;
int
nsub;
regmatch_t regmatch[10];
} backrefinfo;
static
void
*config_server_create(pool *p, server_rec *s);
static
void
*config_server_merge (pool *p,
void
*basev,
void
*overridesv);
static
void
*config_perdir_create(pool *p,
char
*path);
static
void
*config_perdir_merge (pool *p,
void
*basev,
void
*overridesv);
static
const
char
*cmd_rewriteengine(cmd_parms *cmd,
rewrite_perdir_conf *dconf,
int
flag);
static
const
char
*cmd_rewriteoptions(cmd_parms *cmd,
rewrite_perdir_conf *dconf,
char
*option);
static
const
char
*cmd_rewriteoptions_setoption(pool *p,
int
*options,
char
*name);
static
const
char
*cmd_rewritelog (cmd_parms *cmd,
void
*dconf,
char
*a1);
static
const
char
*cmd_rewriteloglevel(cmd_parms *cmd,
void
*dconf,
char
*a1);
static
const
char
*cmd_rewritemap (cmd_parms *cmd,
void
*dconf,
char
*a1,
char
*a2);
static
const
char
*cmd_rewritelock(cmd_parms *cmd,
void
*dconf,
char
*a1);
static
const
char
*cmd_rewritebase(cmd_parms *cmd, rewrite_perdir_conf *dconf,
char
*a1);
static
const
char
*cmd_rewritecond(cmd_parms *cmd, rewrite_perdir_conf *dconf,
char
*str);
static
const
char
*cmd_rewritecond_parseflagfield(pool *p,
rewritecond_entry *
new
,
char
*str);
static
const
char
*cmd_rewritecond_setflag(pool *p, rewritecond_entry *cfg,
char
*key,
char
*val);
static
const
char
*cmd_rewriterule(cmd_parms *cmd, rewrite_perdir_conf *dconf,
char
*str);
static
const
char
*cmd_rewriterule_parseflagfield(pool *p,
rewriterule_entry *
new
,
char
*str);
static
const
char
*cmd_rewriterule_setflag(pool *p, rewriterule_entry *cfg,
char
*key,
char
*val);
static
void
init_module(server_rec *s, pool *p);
static
void
init_child(server_rec *s, pool *p);
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);
static
int
apply_rewrite_list(request_rec *r, array_header *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
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);
static
char
*lookup_map(request_rec *r,
char
*name,
char
*key);
static
char
*lookup_map_txtfile(request_rec *r,
char
*file,
char
*key);
#ifndef NO_DBM_REWRITEMAP
static
char
*lookup_map_dbmfile(request_rec *r,
char
*file,
char
*key);
#endif
static
char
*lookup_map_program(request_rec *r,
int
fpin,
int
fpout,
char
*key);
static
char
*lookup_map_internal(request_rec *r,
char
*(*func)(request_rec *r,
char
*key),
char
*key);
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);
static
void
open_rewritelog(server_rec *s, pool *p);
static
void
rewritelog(request_rec *r,
int
level,
const
char
*text, ...)
__attribute__((format(
printf
,3,4)));
static
char
*current_logtime(request_rec *r);
static
void
rewritelock_create(server_rec *s, pool *p);
static
void
rewritelock_open(server_rec *s, pool *p);
static
void
rewritelock_remove(
void
*data);
static
void
rewritelock_alloc(request_rec *r);
static
void
rewritelock_free(request_rec *r);
static
void
run_rewritemap_programs(server_rec *s, pool *p);
static
int
rewritemap_program_child(
void
*cmd, child_info *pinfo);
static
char
*lookup_variable(request_rec *r,
char
*var);
static
char
*lookup_header(request_rec *r,
const
char
*name);
static
cache *init_cache(pool *p);
static
char
*get_cache_string(cache *c,
char
*res,
int
mode,
time_t
mtime,
char
*key);
static
void
set_cache_string(cache *c,
char
*res,
int
mode,
time_t
mtime,
char
*key,
char
*value);
static
cacheentry *retrieve_cache_string(cache *c,
char
*res,
char
*key);
static
void
store_cache_string(cache *c,
char
*res, cacheentry *ce);
static
char
*subst_prefix_path(request_rec *r,
char
*input,
char
*match,
char
*subst);
static
int
parseargline(
char
*str,
char
**a1,
char
**a2,
char
**a3);
static
int
prefix_stat(
const
char
*path,
struct
stat *sb);
static
void
add_env_variable(request_rec *r,
char
*s);
static
int
subreq_ok(request_rec *r);
static
void
fd_lock(request_rec *r,
int
fd);
static
void
fd_unlock(request_rec *r,
int
fd);
static
int
compare_lexicography(
char
*cpNum1,
char
*cpNum2);
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 */