mod_include.c revision 08cb74ca432a8c24e39f17dedce527e6a47b8001
/* Copyright 1999-2005 The Apache Software Foundation or its licensors, as
* applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_thread_proc.h"
#include "apr_hash.h"
#include "apr_user.h"
#include "apr_lib.h"
#include "apr_optional.h"
#define APR_WANT_STRFUNC
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#include "ap_config.h"
#include "util_filter.h"
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_request.h"
#include "http_core.h"
#include "http_protocol.h"
#include "http_log.h"
#include "http_main.h"
#include "util_script.h"
#include "http_core.h"
#include "mod_include.h"
/* helper for Latin1 <-> entity encoding */
#include "util_ebcdic.h"
(unsigned char)ch)
#else /* APR_CHARSET_EBCDIC */
#endif /* !APR_CHARSET_EBCDIC */
/*
* +-------------------------------------------------------+
* | |
* | Types and Structures
* | |
* +-------------------------------------------------------+
*/
/* sll used for string expansion */
typedef struct result_item {
struct result_item *next;
const char *string;
/* conditional expression parser stuff */
typedef enum {
} token_type_t;
typedef struct {
const char *value;
#ifdef DEBUG_INCLUDE
const char *s;
#endif
} token_t;
typedef struct parse_node {
struct parse_node *parent;
struct parse_node *left;
struct parse_node *right;
int value;
int done;
#ifdef DEBUG_INCLUDE
int dump_done;
#endif
} parse_node_t;
typedef enum {
} xbithack_t;
typedef struct {
const char *default_error_msg;
const char *default_time_fmt;
const char *undefined_echo;
typedef struct {
const char *default_start_tag;
const char *default_end_tag;
/* main parser states */
typedef enum {
typedef struct arg_item {
char *name;
char *value;
} arg_item_t;
typedef struct {
const char *source;
const char *rexp;
} backref_t;
typedef struct {
unsigned int T[256];
unsigned int x;
} bndm_t;
struct ssi_internal_ctx {
int seen_eos;
int error;
char quote; /* quote character value (or \0) */
request_rec *r;
const char *start_seq;
const char *end_seq;
char *directive; /* name of the current directive */
const char *undefined_echo;
#ifdef DEBUG_INCLUDE
struct {
ap_filter_t *f;
} debug;
#endif
};
/*
* +-------------------------------------------------------+
* | |
* | Debugging Utilities
* | |
* +-------------------------------------------------------+
*/
#ifdef DEBUG_INCLUDE
} while(0)
} while(0)
{
char *debug__str;
}
if (d__c) { \
"NULL.\n"); \
} \
else { \
"points to another node (of type %s)!\n", \
} \
return; \
} \
continue; \
} \
} \
else { \
} \
}
{
char *is;
if (!root) {
return;
}
is = " ";
while (current) {
case TOKEN_STRING:
case TOKEN_RE:
continue;
case TOKEN_NOT:
case TOKEN_GROUP:
case TOKEN_RBRACE:
case TOKEN_LBRACE:
}
}
continue;
default:
}
}
continue;
}
}
/* it is possible to call this function within the parser loop, to see
* how the tree is built. That way, we must cleanup after us to dump
* always the whole tree
*/
return;
}
} while(0)
\
} \
else { \
} \
} while(0)
char c = '"'; \
case TOKEN_STRING: \
break; \
case TOKEN_AND: \
case TOKEN_OR: \
: "short circuited"), \
: "short circuited"), \
break; \
case TOKEN_EQ: \
case TOKEN_NE: \
case TOKEN_GT: \
case TOKEN_GE: \
case TOKEN_LT: \
case TOKEN_LE: \
break; \
default: \
break; \
} \
} while(0)
if (unmatched) { \
} \
} while(0)
#else /* DEBUG_INCLUDE */
} while(0)
#define DEBUG_PRINTF(arg)
#endif /* !DEBUG_INCLUDE */
/*
* +-------------------------------------------------------+
* | |
* | Static Module Data
* | |
* +-------------------------------------------------------+
*/
/* global module structure */
/* function handlers for include directives */
static apr_hash_t *include_handlers;
/* forward declaration of handler registry */
/* Sentinel value to store in subprocess_env for items that
*/
static const char lazy_eval_sentinel;
#define LAZY_VALUE (&lazy_eval_sentinel)
/* default values */
#define DEFAULT_START_SEQUENCE "<!--#"
#define DEFAULT_END_SEQUENCE "-->"
#define DEFAULT_ERROR_MSG "[an error occurred while processing this directive]"
#define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
#define DEFAULT_UNDEFINED_ECHO "(none)"
#ifdef XBITHACK
#define DEFAULT_XBITHACK XBITHACK_FULL
#else
#define DEFAULT_XBITHACK XBITHACK_OFF
#endif
/*
* +-------------------------------------------------------+
* | |
* | Environment/Expansion Functions
* | |
* +-------------------------------------------------------+
*/
/*
* decodes a string containing html entities or numeric character references.
* 's' is overwritten with the decoded string.
* If 's' is syntatically incorrect, then the followed fixups will be made:
* unknown entities will be left undecoded;
* references to unused numeric characters will be deleted.
* In particular, � will not be decoded, but will be deleted.
*/
/* maximum length of any ISO-LATIN-1 HTML entity name. */
#define MAXENTLEN (6)
/* The following is a shrinking transformation, therefore safe. */
static void decodehtml(char *s)
{
int val, i, j;
char *p;
const char *ents;
{
NULL, /* 0 */
NULL, /* 1 */
"lt\074gt\076", /* 2 */
"amp\046ETH\320eth\360", /* 3 */
"quot\042Auml\304Euml\313Iuml\317Ouml\326Uuml\334auml\344euml"
"\353iuml\357ouml\366uuml\374yuml\377", /* 4 */
"Acirc\302Aring\305AElig\306Ecirc\312Icirc\316Ocirc\324Ucirc"
"\333THORN\336szlig\337acirc\342aring\345aelig\346ecirc\352"
"icirc\356ocirc\364ucirc\373thorn\376", /* 5 */
"Agrave\300Aacute\301Atilde\303Ccedil\307Egrave\310Eacute\311"
"Igrave\314Iacute\315Ntilde\321Ograve\322Oacute\323Otilde"
"\325Oslash\330Ugrave\331Uacute\332Yacute\335agrave\340"
"aacute\341atilde\343ccedil\347egrave\350eacute\351igrave"
"\354iacute\355ntilde\361ograve\362oacute\363otilde\365"
"oslash\370ugrave\371uacute\372yacute\375" /* 6 */
};
/* Do a fast scan through the string until we find anything
* that needs more complicated handling
*/
for (; *s != '&'; s++) {
if (*s == '\0') {
return;
}
}
for (p = s; *s != '\0'; s++, p++) {
if (*s != '&') {
*p = *s;
continue;
}
/* find end of entity */
for (i = 1; s[i] != ';' && s[i] != '\0'; i++) {
continue;
}
if (s[i] == '\0') { /* treat as normal data */
*p = *s;
continue;
}
/* is it numeric ? */
if (s[1] == '#') {
}
s += i;
p--; /* no data to output */
}
else {
*p = RAW_ASCII_CHAR(val);
}
}
else {
j = i - 1;
/* wrong length */
*p = '&';
continue; /* skip it */
}
break;
}
}
if (*ents == '\0') {
*p = '&'; /* unknown */
}
else {
*p = RAW_ASCII_CHAR(((const unsigned char *) ents)[j]);
s += i;
}
}
}
*p = '\0';
}
{
apr_table_t *e = r->subprocess_env;
char *t;
}
apr_table_setn(e, "DOCUMENT_NAME", ++t);
}
else {
}
if (r->args) {
apr_table_setn(e, "QUERY_STRING_UNESCAPED",
}
}
{
char *val;
}
}
}
val = "<unknown>";
}
}
else {
}
if (val) {
}
return val;
}
{
const char *val;
/* Handle $0 .. $9 from the last regex evaluated.
* The choice of returning NULL strings on not-found,
* v.s. empty strings on an empty match is deliberate.
*/
if (!re) {
return NULL;
}
else {
"regex capture $%" APR_SIZE_T_FMT
" is out of range (last regex was: '%s') in %s",
return NULL;
}
return NULL;
}
}
}
else {
if (val == LAZY_VALUE) {
}
}
return val;
}
/*
* Do variable substitution on strings
*
* (Note: If out==NULL, this function allocs a buffer for the resulting
* string from ctx->pool. The return value is always the parsed string)
*/
{
const char *p;
if (out) {
/* sanity check, out && !length is not supported */
}
/* fast exit */
if (out) {
}
else {
}
return ret;
}
/* well, actually something to do */
if (out) {
if (span) {
}
}
else {
}
/* loop for specials */
do {
break;
}
/* prepare next entry */
}
/*
* escaped character
*/
if (*p == '\\') {
if (out) {
++p;
}
else {
++p;
++outlen;
}
}
/*
* variable expansion
*/
else { /* *p == '$' */
if (*++p == '{') {
if (!ep) {
"variable \"%s\" in %s", p, r->filename);
break;
}
if (p < ep) {
}
p -= 2;
}
else {
ep = p;
++ep;
}
if (p < ep) {
}
--p;
}
/* empty name results in a copy of '$' in the output string */
if (!key) {
if (out) {
*out++ = *p++;
}
else {
++outlen;
}
}
else {
apr_size_t len = 0;
if (val) {
}
else if (leave_name) {
val = p;
}
if (out) {
}
else {
}
}
p = newp;
}
}
break;
}
/* check the remainder */
}
if (out) {
}
else {
}
p += span;
}
/* assemble result */
if (out) {
*eout = '\0';
}
else {
*out = '\0';
}
}
else {
const char *ep;
}
do {
}
}
return ret;
}
/*
* +-------------------------------------------------------+
* | |
* | Conditional Expression Parser
* | |
* +-------------------------------------------------------+
*/
const char *rexp)
{
int rc;
if (!compiled) {
"compile pattern \"%s\"", rexp);
return -1;
}
if (!re) {
}
return rc;
}
{
const char *p;
int unmatched;
if (!*parse) {
return 0;
}
/* Skip leading white space */
while (apr_isspace(**parse)) {
++*parse;
}
if (!**parse) {
return 0;
}
p = *parse;
unmatched = 0;
switch (*(*parse)++) {
case '(':
return 0;
case ')':
return 0;
case '=':
return 0;
case '!':
if (**parse == '=') {
++*parse;
return 0;
}
return 0;
case '\'':
unmatched = '\'';
break;
case '/':
unmatched = '/';
break;
case '|':
if (**parse == '|') {
++*parse;
return 0;
}
break;
case '&':
if (**parse == '&') {
++*parse;
return 0;
}
break;
case '>':
if (**parse == '=') {
++*parse;
return 0;
}
return 0;
case '<':
if (**parse == '=') {
++*parse;
return 0;
}
return 0;
}
/* It's a string or regex token
* Now search for the next token, which finishes this string
*/
shift = 0;
if (**parse == '\\') {
if (!*(++*parse)) {
p = *parse;
break;
}
++shift;
}
else {
if (unmatched) {
unmatched = 0;
++*parse;
break;
}
} else if (apr_isspace(**parse)) {
break;
}
else {
int found = 0;
switch (**parse) {
case '(':
case ')':
case '=':
case '!':
case '<':
case '>':
++found;
break;
case '|':
case '&':
++found;
}
break;
}
if (found) {
break;
}
}
}
}
if (unmatched) {
}
else {
while (shift--) {
const char *e = ap_strchr_c(p, '\\');
memcpy(c, p, e-p);
c += e-p;
*c++ = *++e;
len -= e-p;
p = e+1;
}
if (len) {
}
c[len] = '\0';
}
return unmatched;
}
{
const char *error = "Invalid expression \"%s\" in file %s";
int was_unmatched = 0;
unsigned regex = 0;
*was_error = 0;
if (!parse) {
return 0;
}
/* Create Parse Tree */
while (1) {
/* uncomment this to see how the tree a built:
*
* DEBUG_DUMP_TREE(ctx, root);
*/
if (!parse) {
break;
}
if (!current) {
case TOKEN_STRING:
case TOKEN_NOT:
case TOKEN_LBRACE:
continue;
default:
r->filename);
*was_error = 1;
return 0;
}
}
case TOKEN_STRING:
case TOKEN_STRING:
continue;
case TOKEN_RE:
case TOKEN_RBRACE:
case TOKEN_GROUP:
break;
default:
continue;
}
break;
case TOKEN_RE:
case TOKEN_EQ:
case TOKEN_NE:
++regex;
continue;
default:
break;
}
break;
case TOKEN_AND:
case TOKEN_OR:
case TOKEN_STRING:
case TOKEN_RE:
case TOKEN_GROUP:
while (current) {
case TOKEN_AND:
case TOKEN_OR:
case TOKEN_LBRACE:
break;
default:
continue;
}
break;
}
if (!current) {
continue;
}
continue;
default:
break;
}
break;
case TOKEN_EQ:
case TOKEN_NE:
case TOKEN_GE:
case TOKEN_GT:
case TOKEN_LE:
case TOKEN_LT:
if (!current) {
continue;
}
case TOKEN_LBRACE:
case TOKEN_AND:
case TOKEN_OR:
continue;
default:
break;
}
}
break;
case TOKEN_RBRACE:
}
if (current) {
continue;
}
error = "Unmatched ')' in \"%s\" in file %s";
break;
case TOKEN_NOT:
case TOKEN_LBRACE:
case TOKEN_STRING:
case TOKEN_RE:
case TOKEN_RBRACE:
case TOKEN_GROUP:
break;
default:
continue;
}
break;
default:
break;
}
*was_error = 1;
return 0;
}
/* Evaluate Parse Tree */
while (current) {
case TOKEN_STRING:
break;
case TOKEN_AND:
case TOKEN_OR:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return 0;
}
case TOKEN_STRING:
NULL, 0, SSI_EXPAND_DROP_NAME);
break;
default:
continue;
}
}
/* short circuit evaluation */
}
else {
case TOKEN_STRING:
NULL, 0, SSI_EXPAND_DROP_NAME);
break;
default:
continue;
}
}
}
else {
}
}
break;
case TOKEN_EQ:
case TOKEN_NE:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return 0;
}
--regex;
}
else {
}
}
break;
case TOKEN_GE:
case TOKEN_GT:
case TOKEN_LE:
case TOKEN_LT:
"Invalid expression \"%s\" in file %s",
*was_error = 1;
return 0;
}
}
break;
case TOKEN_NOT:
case TOKEN_GROUP:
continue;
}
}
else {
}
}
break;
case TOKEN_RE:
if (!error) {
error = "No operator before regex in expr \"%s\" in file %s";
}
case TOKEN_LBRACE:
if (!error) {
error = "Unmatched '(' in \"%s\" in file %s";
}
default:
if (!error) {
error = "internal parser error in \"%s\" in file %s";
}
*was_error = 1;
return 0;
}
}
}
/*
* +-------------------------------------------------------+
* | |
* | Action Handlers
* | |
* +-------------------------------------------------------+
*/
/*
* Extract the next tag name and value.
* If there are no more tags, set the tag name to NULL.
* The tag value is html decoded if dodecode is non-zero.
* The tag value may be NULL if there is no tag value..
*/
{
return;
}
}
return;
}
{
int ret=0;
char *newpath;
/* be safe; only files in this directory or below allowed */
APR_FILEPATH_NOTABSOLUTE, r->pool);
if (rv != APR_SUCCESS) {
error_fmt = "unable to access file \"%s\" "
"in parsed file %s";
}
else {
/* note: it is okay to pass NULL for the "next filter" since
we never attempt to "run" this sub request. */
&& rv != APR_INCOMPLETE) {
error_fmt = "unable to get information about \"%s\" "
"in parsed file %s";
}
}
else {
error_fmt = "unable to lookup information about \"%s\" "
"in parsed file %s";
}
}
if (error_fmt) {
ret = -1;
}
return ret;
}
/* note: it is okay to pass NULL for the "next filter" since
we never attempt to "run" this sub request. */
return 0;
}
else {
"information about \"%s\" in parsed file %s",
return -1;
}
}
else {
return -1;
}
}
/*
* <!--#include virtual|file="..." [virtual|file="..."] ... -->
*/
{
request_rec *r = f->r;
? APLOG_ERR : APLOG_WARNING,
0, r, "missing argument for include element in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
while (1) {
char *parsed_string;
break;
}
break;
}
if (tag[0] == 'f') {
char *newpath;
/* be safe; only files in this directory or below allowed */
if (rv != APR_SUCCESS) {
error_fmt = "unable to include file \"%s\" in parsed file %s";
}
else {
}
}
else {
}
error_fmt = "unable to include \"%s\" in parsed file %s";
}
error_fmt = "unable to include potential exec \"%s\" in parsed "
"file %s";
}
/* See the Kludge in includes_filter for why.
* Basically, it puts a bread crumb in here, then looks
* for the crumb later to see if its been here.
*/
if (rr) {
}
error_fmt = "unable to include \"%s\" in parsed file %s";
}
if (error_fmt) {
r->filename);
}
/* destroy the sub request */
if (rr) {
}
if (error_fmt) {
break;
}
}
return APR_SUCCESS;
}
/*
* <!--#echo [encoding="..."] var="..." [encoding="..."] var="..." ... -->
*/
{
request_rec *r = f->r;
? APLOG_ERR : APLOG_WARNING,
0, r, "missing argument for echo element in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
while (1) {
break;
}
const char *val;
0, SSI_EXPAND_DROP_NAME),
ctx);
if (val) {
switch(encode) {
case E_NONE:
break;
case E_URL:
break;
case E_ENTITY:
break;
}
}
else {
}
}
}
}
}
else {
"\"%s\" to parameter \"encoding\" of tag echo in "
break;
}
}
else {
break;
}
}
return APR_SUCCESS;
}
/*
* <!--#config [timefmt="..."] [sizefmt="..."] [errmsg="..."]
* [echomsg="..."] -->
*/
{
request_rec *r = f->r;
? APLOG_ERR : APLOG_WARNING,
0, r, "missing argument for config element in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
while (1) {
break;
}
}
}
}
char *parsed_string;
}
}
else {
"\"%s\" to parameter \"sizefmt\" of tag config "
break;
}
}
else {
break;
}
}
return APR_SUCCESS;
}
/*
* <!--#fsize virtual|file="..." [virtual|file="..."] ... -->
*/
{
request_rec *r = f->r;
? APLOG_ERR : APLOG_WARNING,
0, r, "missing argument for fsize element in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
while (1) {
char *parsed_string;
break;
}
char *buf;
}
else {
apr_size_t l, x, pos;
char *tmp;
for (x = 0; x < l; ++x) {
if (x && !((l - x) % 3)) {
++len;
}
}
if (len == l) {
}
else {
for (pos = x = 0; x < l; ++x) {
if (x && !((l - x) % 3)) {
}
}
}
}
}
else {
break;
}
}
return APR_SUCCESS;
}
/*
* <!--#flastmod virtual|file="..." [virtual|file="..."] ... -->
*/
{
request_rec *r = f->r;
? APLOG_ERR : APLOG_WARNING,
0, r, "missing argument for flastmod element in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
while (1) {
char *parsed_string;
break;
}
char *t_val;
}
else {
break;
}
}
return APR_SUCCESS;
}
/*
* <!--#if expr="..." -->
*/
{
request_rec *r = f->r;
? APLOG_ERR : APLOG_WARNING,
? "too many arguments for if element in %s"
: "missing expr argument for if element in %s",
r->filename);
}
++(ctx->if_nesting_level);
return APR_SUCCESS;
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
if (!expr) {
"element in %s", r->filename);
return APR_SUCCESS;
}
if (was_error) {
return APR_SUCCESS;
}
if (expr_ret) {
}
else {
}
ctx->if_nesting_level = 0;
return APR_SUCCESS;
}
/*
* <!--#elif expr="..." -->
*/
{
request_rec *r = f->r;
? "too many arguments for if element in %s"
: "missing expr argument for if element in %s",
r->filename);
}
if (ctx->if_nesting_level) {
return APR_SUCCESS;
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
if (!expr) {
"statement: %s", r->filename);
return APR_SUCCESS;
}
return APR_SUCCESS;
}
if (was_error) {
return APR_SUCCESS;
}
if (expr_ret) {
}
else {
}
return APR_SUCCESS;
}
/*
* <!--#else -->
*/
{
request_rec *r = f->r;
0, r, "else directive does not take tags in %s",
r->filename);
}
if (ctx->if_nesting_level) {
return APR_SUCCESS;
}
}
return APR_SUCCESS;
}
}
else {
}
return APR_SUCCESS;
}
/*
* <!--#endif -->
*/
{
request_rec *r = f->r;
0, r, "endif directive does not take tags in %s",
r->filename);
}
if (ctx->if_nesting_level) {
--(ctx->if_nesting_level);
return APR_SUCCESS;
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
/*
* <!--#set var="..." value="..." ... -->
*/
{
request_rec *r = f->r;
apr_pool_t *p = r->pool;
? APLOG_ERR : APLOG_WARNING,
0, r, "missing argument for set element in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
/* we need to use the 'main' request pool to set notes as that is
* a notes lifetime
*/
while (sub) {
}
while (1) {
break;
}
}
char *parsed_string;
if (!var) {
"precede value in set directive in %s",
r->filename);
break;
}
apr_pstrdup(p, parsed_string));
}
else {
"directive in %s", r->filename);
break;
}
}
return APR_SUCCESS;
}
/*
* <!--#printenv -->
*/
{
request_rec *r = f->r;
const apr_array_header_t *arr;
const apr_table_entry_t *elts;
int i;
? APLOG_ERR : APLOG_WARNING,
0, r, "printenv directive does not take tags in %s",
r->filename);
}
return APR_SUCCESS;
}
return APR_SUCCESS;
}
/* get key */
/* get value */
if (val_text == LAZY_VALUE) {
}
/* assemble result */
*next++ = '=';
*next++ = '\n';
*next = 0;
}
return APR_SUCCESS;
}
/*
* +-------------------------------------------------------+
* | |
* | Main Includes-Filter Engine
* | |
* +-------------------------------------------------------+
*/
/* This is an implementation of the BNDM search algorithm.
*
* Fast and Flexible String Matching by Combining Bit-parallelism and
* Suffix Automata (2001)
* Gonzalo Navarro, Mathieu Raffinot
*
*
* Initial code submitted by Sascha Schumann.
*/
/* Precompile the bndm_t data structure. */
{
unsigned int x;
memset(t->T, 0, sizeof(unsigned int) * 256);
t->pattern_len = nl;
t->T[(unsigned char) *n++] |= x;
}
t->x = x - 1;
return t;
}
/* Implements the BNDM search algorithm (as described above).
*
* h - the string to look in
* hl - length of the string to look for
* t - precompiled bndm structure against the pattern
*
* Returns the count of character that is the first match or hl if no
* match is found.
*/
{
const char *skip;
unsigned int *T, x, d;
T = t->T;
x = t->x;
nl = t->pattern_len;
while (p < he) {
skip = p;
d = x;
do {
d &= T[(unsigned char) *p--];
if (!d) {
break;
}
if ((d & 1)) {
if (p != pi) {
skip = p;
}
else {
return p - h + 1;
}
}
d >>= 1;
} while (d);
}
return hl;
}
/*
* returns the index position of the first byte of start_seq (or the len of
* the buffer as non-match)
*/
{
const char *p, *ep;
p = data; /* try partial match at the end of the buffer (below) */
}
else {
/* try fast bndm search over the buffer
* (hopefully the whole start sequence can be found in this buffer)
*/
/* wow, found it. ready. */
return index;
}
else {
/* ok, the pattern can't be found as whole in the buffer,
* check the end for a partial match
*/
}
}
do {
++p;
}
/* found a possible start_seq start */
if (p < ep) {
++p;
++p;
++pos;
}
/* partial match found. Store the info for the next round */
if (p == ep) {
return index;
}
}
/* we must try all combinations; consider (e.g.) SSIStartTag "--->"
* and a string data of "--.-" and the end of the buffer
*/
} while (p < ep);
/* no match */
return len;
}
/*
* returns the first byte *after* the partial (or final) match.
*
* If we had to trick with the start_seq start, 'release' returns the
* number of chars of the start_seq which appeared not to be part of a
* full tag and may have to be passed down the filter chain.
*/
const char *data,
{
const char *p, *ep;
*release = 0;
do {
p = data;
++p;
++pos;
}
/* full match */
return (p - data);
}
/* the whole buffer is a partial match */
if (p == ep) {
return (p - data);
}
/* No match so far, but again:
* We must try all combinations, since the start_seq is a random
* user supplied string
*
* So: look if the first char of start_seq appears somewhere within
* the current partial match. If it does, try to start a match that
* begins with this offset. (This can happen, if a strange
* start_seq like "---->" spans buffers)
*/
do {
++spos;
++*release;
++p;
++spos;
++*release;
--pos;
}
/* if a matching beginning char was found, try to match the
* remainder of the old buffer.
*/
if (pos > 1) {
apr_size_t t = 1;
++p;
++p;
++t;
}
if (t == pos) {
/* yeah, another partial match found in the *old*
* buffer, now test the *current* buffer for
* continuing match
*/
break;
}
}
} while (pos > 1);
if (pos) {
continue;
}
}
break;
} while (1); /* work hard to find a match ;-) */
/* no match at all, release all (wrongly) matched chars so far */
return 0;
}
/*
* returns the position after the directive
*/
{
const char *p = data;
case PARSE_DIRECTIVE:
while (p < ep && !apr_isspace(*p)) {
/* we have to consider the case of missing space between directive
* and end_seq (be somewhat lenient), e.g. <!--#printenv-->
*/
++p;
return (p - data);
}
++p;
}
if (p < ep) { /* found delimiter whitespace */
}
break;
case PARSE_DIRECTIVE_TAIL:
++p;
++pos;
}
/* full match, we're done */
break;
}
/* partial match, the buffer is too small to match fully */
if (p == ep) {
break;
}
/* no match. continue normal parsing */
return 0;
case PARSE_DIRECTIVE_POSTTAIL:
/* continue immediately with the next state */
case PARSE_DIRECTIVE_POSTNAME:
}
if (!intern->directive_len) {
"directive name in parsed document %s",
}
else {
/* normalize directive name */
}
}
return 0;
default:
/* get a rid of a gcc warning about unhandled enumerations */
break;
}
return (p - data);
}
/*
* find out whether the next token is (a possible) end_seq or an argument
*/
{
const char *p = data;
/* skip leading WS */
while (p < ep && apr_isspace(*p)) {
++p;
}
/* buffer doesn't consist of whitespaces only */
if (p < ep) {
}
return (p - data);
}
/*
* test the stream for end_seq. If it doesn't match at all, it must be an
* argument
*/
{
const char *p = data;
}
++p;
++pos;
}
/* bingo, full match */
return (p - data);
}
/* partial match, the buffer is too small to match fully */
if (p == ep) {
return (p - data);
}
/* no match. It must be an argument string then
* The caller should cleanup and rewind to the reparse point
*/
return 0;
}
/*
* extract name=value from the buffer
* A pcre-pattern could look (similar to):
* name\s*(?:=\s*(["'`]?)value\1(?>\s*))?
*/
{
const char *p = data;
case PARSE_ARG:
/*
* create argument structure and append it to the current list
*/
sizeof(*intern->current_arg));
}
else {
}
}
/* check whether it's a valid one. If it begins with a quote, we
* can safely assume, someone forgot the name of the argument
*/
switch (*p) {
case '"': case '\'': case '`':
"argument name for value to tag %s in %s",
return (p - data);
default:
}
/* continue immediately with next state */
case PARSE_ARG_NAME:
++p;
}
if (p < ep) {
return (p - data);
}
break;
case PARSE_ARG_POSTNAME:
"argument name for value to tag %s in %s",
}
else {
/* normalize the name */
while (*sp) {
++sp;
}
}
/* continue with next state immediately */
case PARSE_ARG_EQ:
while (p < ep && apr_isspace(*p)) {
++p;
}
if (p < ep) {
if (*p == '=') {
++p;
}
else { /* no value */
}
return (p - data);
}
break;
case PARSE_ARG_PREVAL:
while (p < ep && apr_isspace(*p)) {
++p;
}
/* buffer doesn't consist of whitespaces only */
if (p < ep) {
switch (*p) {
case '"': case '\'': case '`':
break;
default:
break;
}
return (p - data);
}
break;
case PARSE_ARG_VAL_ESC:
++p;
}
/* continue with next state immediately */
case PARSE_ARG_VAL:
for (; p < ep; ++p) {
++p;
if (p == ep) {
break;
}
--p;
}
}
++p;
break;
}
++p;
break;
}
}
return (p - data);
case PARSE_ARG_POSTVAL:
/*
* The value is still the raw input string. Finally clean it up.
*/
/* strip quote escaping \ from the string */
apr_size_t shift = 0;
char *sp;
++sp;
}
++sp;
++shift;
}
if (shift) {
}
}
}
return 0;
default:
/* get a rid of a gcc warning about unhandled enumerations */
break;
}
return len; /* partial match of something */
}
/*
* This is the main loop over the current bucket brigade.
*/
{
request_rec *r = f->r;
char *magic; /* magic pointer for sentinel use */
/* fast exit */
if (APR_BRIGADE_EMPTY(bb)) {
return APR_SUCCESS;
}
/* we may crash, since already cleaned up; hand over the responsibility
* to the next filter;-)
*/
}
/* All stuff passed along has to be put into that brigade */
/* initialization for this loop */
intern->bytes_read = 0;
intern->r = r;
/* loop over the current bucket brigade */
while (b != APR_BRIGADE_SENTINEL(bb)) {
/* handle meta buckets before reading any data */
if (APR_BUCKET_IS_METADATA(b)) {
newb = APR_BUCKET_NEXT(b);
if (APR_BUCKET_IS_EOS(b)) {
/* Hit end of stream, time for cleanup ... But wait!
* Perhaps we're not ready yet. We may have to loop one or
* two times again to finish our work. In that case, we
* just re-insert the EOS bucket to allow for an extra loop.
*
* PARSE_EXECUTE means, we've hit a directive just before the
* EOS, which is now waiting for execution.
*
* PARSE_DIRECTIVE_POSTTAIL means, we've hit a directive with
* no argument and no space between directive and end_seq
* just before the EOS. (consider <!--#printenv--> as last
* or only string within the stream). This state, however,
* just cleans up and turns itself to PARSE_EXECUTE, which
* will be passed through within the next (and actually
* last) round.
*/
}
else {
break; /* END OF STREAM */
}
}
else {
if (APR_BUCKET_IS_FLUSH(b)) {
}
b = newb;
continue;
}
}
/* enough is enough ... */
if (!APR_BRIGADE_EMPTY(pass_bb)) {
if (rv != APR_SUCCESS) {
return rv;
}
}
intern->bytes_read = 0;
}
/* read the current bucket data */
len = 0;
if (intern->bytes_read > 0) {
if (APR_STATUS_IS_EAGAIN(rv)) {
continue;
}
}
}
if (rv != APR_SUCCESS) {
return rv;
}
}
/* zero length bucket, fetch next one */
b = APR_BUCKET_NEXT(b);
continue;
}
/*
*/
/* no current tag; search for start sequence */
case PARSE_PRE_HEAD:
apr_bucket_split(b, index);
}
newb = APR_BUCKET_NEXT(b);
}
else {
}
/* now delete the start_seq stuff from the remaining bucket */
}
b = APR_BUCKET_NEXT(newb);
}
else {
b = newb;
}
break;
/* we're currently looking for the end of the start sequence */
case PARSE_HEAD:
/* check if we mismatched earlier and have to release some chars */
f->c->bucket_alloc);
}
if (index) { /* any match */
/* now delete the start_seq stuff from the remaining bucket */
apr_bucket_split(b, index);
}
newb = APR_BUCKET_NEXT(b);
b = newb;
}
break;
/* we're currently grabbing the directive name */
case PARSE_DIRECTIVE:
case PARSE_DIRECTIVE_POSTNAME:
case PARSE_DIRECTIVE_TAIL:
case PARSE_DIRECTIVE_POSTTAIL:
if (index) {
apr_bucket_split(b, index);
newb = APR_BUCKET_NEXT(b);
}
if (store) {
if (index) {
b = newb;
}
/* time for cleanup? */
}
}
else if (index) {
b = newb;
}
break;
/* skip WS and find out what comes next (arg or end_seq) */
case PARSE_PRE_ARG:
if (index) { /* skipped whitespaces */
apr_bucket_split(b, index);
}
newb = APR_BUCKET_NEXT(b);
b = newb;
}
break;
/* currently parsing name[=val] */
case PARSE_ARG:
case PARSE_ARG_NAME:
case PARSE_ARG_POSTNAME:
case PARSE_ARG_EQ:
case PARSE_ARG_PREVAL:
case PARSE_ARG_VAL:
case PARSE_ARG_VAL_ESC:
case PARSE_ARG_POSTVAL:
if (index) {
apr_bucket_split(b, index);
newb = APR_BUCKET_NEXT(b);
}
if (store) {
if (index) {
b = newb;
}
/* time for cleanup? */
}
}
else if (index) {
b = newb;
}
break;
/* try to match end_seq at current pos. */
case PARSE_TAIL:
case PARSE_TAIL_SEQ:
case PARSE_EXECUTE: /* full match */
apr_bucket_split(b, index);
newb = APR_BUCKET_NEXT(b);
b = newb;
break;
case PARSE_ARG: /* no match */
/* PARSE_ARG must reparse at the beginning */
b = APR_BRIGADE_FIRST(bb);
break;
default: /* partial match */
newb = APR_BUCKET_NEXT(b);
b = newb;
break;
}
break;
/* now execute the parsed directive, cleanup the space and
* start again with PARSE_PRE_HEAD
*/
case PARSE_EXECUTE:
/* if there was an error, it was already logged; just stop here */
}
}
else {
if (handle_func) {
if (rv != APR_SUCCESS) {
return rv;
}
}
else {
"unknown directive \"%s\" in parsed doc %s",
r->filename);
}
}
}
/* cleanup */
/* Oooof. Done here, start next round */
break;
} /* switch(ctx->state) */
} /* while(brigade) */
/* End of stream. Final cleanup */
f->c->bucket_alloc));
}
}
"SSI directive was not properly finished at the end "
"of parsed document %s", r->filename);
}
}
"missing closing endif directive in parsed document"
" %s", r->filename);
}
/* cleanup our temporary memory */
/* don't forget to finally insert the EOS bucket */
}
/* if something's left over, pass it along */
if (!APR_BRIGADE_EMPTY(pass_bb)) {
}
else {
rv = APR_SUCCESS;
}
return rv;
}
/*
* +-------------------------------------------------------+
* | |
* | Runtime Hooks
* | |
* +-------------------------------------------------------+
*/
static int includes_setup(ap_filter_t *f)
{
/* When our xbithack value isn't set to full or our platform isn't
* providing group-level protection bits or our group-level bits do not
* have group-execite on, we will set the no_local_copy value to 1 so
* that we will not send 304s.
*/
f->r->no_local_copy = 1;
}
/* Don't allow ETag headers to be generated - see RFC2616 - 13.3.4.
* We don't know if we are going to be including a file or executing
* a program - in either case a strong ETag header will likely be invalid.
*/
return OK;
}
{
request_rec *r = f->r;
if (!(ap_allow_options(r) & OPT_INCLUDES)) {
"mod_include: Options +Includes (or IncludesNoExec) "
"wasn't set, INCLUDES filter removed");
return ap_pass_brigade(f->next, b);
}
if (!f->ctx) {
struct ssi_internal_ctx *intern;
/* create context for this filter */
/* runtime data */
if (ap_allow_options(r) & OPT_INCNOEXEC) {
}
ctx->if_nesting_level = 0;
}
/* Kludge --- for nested includes, we want to keep the subprocess
* environment of the base document (for compatibility); that means
* torquing our own last_modified date as well so that the
* LAST_MODIFIED variable gets reset to the proper value if the
* nested document resets <!--#config timefmt -->.
*/
}
else {
/* we're not a nested include, so we create an initial
* environment */
ap_add_cgi_vars(r);
}
/* Always unset the content-length. There is no way to know if
* the content will be modified at some point by send_parsed_content.
* It is very possible for us to not find any content in the first
* 9k of the file, but still have to modify the content of the file.
* If we are going to pass the file through send_parsed_content, then
* the content-length should just be unset.
*/
/* Always unset the Last-Modified field - see RFC2616 - 13.3.4.
* We don't know if we are going to be including a file or executing
* a program which may change the Last-Modified header or make the
* content completely dynamic. Therefore, we can't support these
* headers.
* Exception: XBitHack full means we *should* set the Last-Modified field.
*/
/* Assure the platform supports Group protections */
}
else {
}
/* add QUERY stuff to env cause it ain't yet */
if (r->args) {
}
return send_parsed_content(f, b);
}
static int include_fixup(request_rec *r)
{
{
if (!r->content_type || !*r->content_type) {
ap_set_content_type(r, "text/html");
}
r->handler = "default-handler";
}
else
/* These OS's don't support xbithack. This is being worked on. */
{
return DECLINED;
}
#else
{
return DECLINED;
}
return DECLINED;
}
return DECLINED;
}
}
#endif
/* We always return declined, because the default handler actually
* serves the file. All we have to do is add the filter.
*/
return DECLINED;
}
/*
* +-------------------------------------------------------+
* | |
* | Configuration Handling
* | |
* +-------------------------------------------------------+
*/
{
return result;
}
{
return result;
}
{
}
}
}
else {
return "XBitHack must be set to Off, On, or Full";
}
return NULL;
}
const char *tag)
{
const char *p = tag;
/* be consistent. (See below in set_default_end_tag) */
while (*p) {
if (apr_isspace(*p)) {
return "SSIStartTag may not contain any whitespaces";
}
++p;
}
return NULL;
}
const char *tag)
{
const char *p = tag;
/* sanity check. The parser may fail otherwise */
while (*p) {
if (apr_isspace(*p)) {
return "SSIEndTag may not contain any whitespaces";
}
++p;
}
return NULL;
}
const char *msg)
{
return NULL;
}
const char *msg)
{
return NULL;
}
const char *fmt)
{
return NULL;
}
/*
* +-------------------------------------------------------+
* | |
* | Module Initialization and Configuration
* | |
* +-------------------------------------------------------+
*/
{
if(ssi_pfn_register) {
}
return OK;
}
static const command_rec includes_cmds[] =
{
"Off, On, or Full"),
"a string"),
"a strftime(3) formatted string"),
"SSI Start String Tag"),
"SSI End String Tag"),
"String to be displayed if an echoed variable is undefined"),
{NULL}
};
{
}
static void register_hooks(apr_pool_t *p)
{
}
{
create_includes_dir_config, /* dir config creater */
NULL, /* dir merger --- default is to override */
create_includes_server_config,/* server config */
NULL, /* merge server config */
includes_cmds, /* command apr_table_t */
register_hooks /* register hooks */
};