mod_include.c revision 74f1cb282d1418f9eaaf86524a6d447c3a5209d1
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* ====================================================================
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * The Apache Software License, Version 1.1
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * reserved.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Redistribution and use in source and binary forms, with or without
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * modification, are permitted provided that the following conditions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * are met:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 1. Redistributions of source code must retain the above copyright
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * notice, this list of conditions and the following disclaimer.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 2. Redistributions in binary form must reproduce the above copyright
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * notice, this list of conditions and the following disclaimer in
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the documentation and/or other materials provided with the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * distribution.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 3. The end-user documentation included with the redistribution,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * if any, must include the following acknowledgment:
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * "This product includes software developed by the
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Apache Software Foundation (http://www.apache.org/)."
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Alternately, this acknowledgment may appear in the software itself,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * if and wherever such third-party acknowledgments normally appear.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 4. The names "Apache" and "Apache Software Foundation" must
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * not be used to endorse or promote products derived from this
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * software without prior written permission. For written
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * permission, please contact apache@apache.org.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * 5. Products derived from this software may not be called "Apache",
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * nor may "Apache" appear in their name, without prior written
64185f9824e42f21ca7b9ae6c004484215c031a7rbb * permission of the Apache Software Foundation.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * SUCH DAMAGE.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ====================================================================
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This software consists of voluntary contributions made by many
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * individuals on behalf of the Apache Software Foundation. For more
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * information on the Apache Software Foundation, please see
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * <http://www.apache.org/>.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Portions of this software are based upon public domain software
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * originally written at the National Center for Supercomputing Applications,
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * University of Illinois, Urbana-Champaign.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * http_include.c: Handles the server-parsed HTML documents
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Original by Rob McCool; substantial fixups by David Robinson;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * incorporated into the Apache module framework by rst.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_strings.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_thread_proc.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_hash.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_user.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_lib.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_optional.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define APR_WANT_STRFUNC
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "apr_want.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define CORE_PRIVATE
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb#include "ap_config.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "util_filter.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "httpd.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_config.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_core.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_request.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_core.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_protocol.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_log.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "http_main.h"
b6055b7832a0e4d0818416252fff5925aaebae4brbb#include "util_script.h"
9625528fcf4fa27288f3be080a1979c8ef60d7dfrbb#include "http_core.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "mod_include.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#include "util_ebcdic.h"
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingmodule AP_MODULE_DECLARE_DATA include_module;
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_hash_t *include_hash;
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic APR_OPTIONAL_FN_TYPE(ap_register_include_handler) *ssi_pfn_register;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*****************************************************************
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb *
48d7c43629323c8d5ee9f7bd0d194de0a376b391rbb * XBITHACK. Sigh... NB it's configurable per-directory; the compile-time
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb * option only changes the default.
48d7c43629323c8d5ee9f7bd0d194de0a376b391rbb */
d41217398f0e1031adbb6f5bd37f45737c805deftrawick
d41217398f0e1031adbb6f5bd37f45737c805deftrawickenum xbithack {
d41217398f0e1031adbb6f5bd37f45737c805deftrawick xbithack_off, xbithack_on, xbithack_full
9625528fcf4fa27288f3be080a1979c8ef60d7dfrbb};
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstruct bndm_t {
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard unsigned int T[256];
178381ebc820fb4c429aa000240cc8ec42c99c58trawick unsigned int x;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding} ;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingtypedef struct {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *default_error_msg;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *default_time_fmt;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding enum xbithack *xbithack;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding} include_dir_config;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
178381ebc820fb4c429aa000240cc8ec42c99c58trawicktypedef struct {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *default_start_tag;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *default_end_tag;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int start_tag_len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding bndm_t start_seq_pat;
e68becff3c3ddc18723c9799b8cc2e6e9c3dbd66wrowe char *undefinedEcho;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int undefinedEchoLen;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding} include_server_config;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef XBITHACK
33098ea43d4392be70012a7c45a16639abb12439fielding#define DEFAULT_XBITHACK xbithack_full
33098ea43d4392be70012a7c45a16639abb12439fielding#else
33098ea43d4392be70012a7c45a16639abb12439fielding#define DEFAULT_XBITHACK xbithack_off
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define BYTE_COUNT_THRESHOLD AP_MIN_BYTES_TO_WRITE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* ------------------------ Environment function -------------------------- */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Sentinel value to store in subprocess_env for items that
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * shouldn't be evaluated until/unless they're actually used
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char lazy_eval_sentinel;
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet#define LAZY_VALUE (&lazy_eval_sentinel)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void add_include_vars(request_rec *r, char *timefmt)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_t *e = r->subprocess_env;
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb char *t;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "DATE_LOCAL", LAZY_VALUE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "DATE_GMT", LAZY_VALUE);
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb apr_table_setn(e, "LAST_MODIFIED", LAZY_VALUE);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "DOCUMENT_URI", r->uri);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (r->path_info && *r->path_info) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "DOCUMENT_PATH_INFO", r->path_info);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "USER_NAME", LAZY_VALUE);
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb if ((t = strrchr(r->filename, '/'))) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "DOCUMENT_NAME", ++t);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "DOCUMENT_NAME", r->uri);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (r->args) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *arg_copy = apr_pstrdup(r->pool, r->args);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_unescape_url(arg_copy);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "QUERY_STRING_UNESCAPED",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_escape_shell_cmd(r->pool, arg_copy));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char *add_include_vars_lazy(request_rec *r, const char *var)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcasecmp(var, "DATE_LOCAL")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding include_dir_config *conf =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (include_dir_config *)ap_get_module_config(r->per_dir_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding &include_module);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = ap_ht_time(r->pool, r->request_time, conf->default_time_fmt, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcasecmp(var, "DATE_GMT")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding include_dir_config *conf =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (include_dir_config *)ap_get_module_config(r->per_dir_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding &include_module);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = ap_ht_time(r->pool, r->request_time, conf->default_time_fmt, 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcasecmp(var, "LAST_MODIFIED")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding include_dir_config *conf =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (include_dir_config *)ap_get_module_config(r->per_dir_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding &include_module);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = ap_ht_time(r->pool, r->finfo.mtime, conf->default_time_fmt, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcasecmp(var, "USER_NAME")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (apr_get_username(&val, r->finfo.user, r->pool) != APR_SUCCESS) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = "<unknown>";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (val) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(r->subprocess_env, var, val);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char *get_include_var(request_rec *r, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *var)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (apr_isdigit(*var) && !var[1]) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Handle $0 .. $9 from the last regex evaluated.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The choice of returning NULL strings on not-found,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * v.s. empty strings on an empty match is deliberate.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (!ctx->re_result || !ctx->re_string) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh return NULL;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb else {
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb int idx = atoi(var);
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb apr_size_t len = (*ctx->re_result)[idx].rm_eo
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding - (*ctx->re_result)[idx].rm_so;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ( (*ctx->re_result)[idx].rm_so < 0
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh || (*ctx->re_result)[idx].rm_eo < 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = apr_pstrmemdup(r->pool, ctx->re_string
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding + (*ctx->re_result)[idx].rm_so, len);
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = apr_table_get(r->subprocess_env, var);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (val == LAZY_VALUE)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = add_include_vars_lazy(r, var);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* --------------------------- Parser functions --------------------------- */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* This is an implementation of the BNDM search algorithm.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Fast and Flexible String Matching by Combining Bit-parallelism and
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Suffix Automata (2001)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Gonzalo Navarro, Mathieu Raffinot
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * http://www-igm.univ-mlv.fr/~raffinot/ftp/jea2001.ps.gz
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Initial code submitted by Sascha Schumann.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Precompile the bndm_t data structure. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void bndm_compile(bndm_t *t, const char *n, apr_size_t nl)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding unsigned int x;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *ne = n + nl;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memset(t->T, 0, sizeof(unsigned int) * 256);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (x = 1; n < ne; x <<= 1)
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh t->T[(unsigned char) *n++] |= x;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh t->x = x - 1;
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb}
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb/* Implements the BNDM search algorithm (as described above).
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh * n - the pattern to search for
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * nl - length of the pattern to search for
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * h - the string to look in
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * hl - length of the string to look for
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * t - precompiled bndm structure against the pattern
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Returns the count of character that is the first match or hl if no
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * match is found.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_size_t bndm(const char *n, apr_size_t nl, const char *h,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t hl, bndm_t *t)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *skip;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *he, *p, *pi;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding unsigned int *T, x, d;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding he = h + hl;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding T = t->T;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding x = t->x;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pi = h - 1; /* pi: p initial */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding p = pi + nl; /* compare window right to left. point to the first char */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (p < he) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding skip = p;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding d = x;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding d &= T[(unsigned char) *p--];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!d) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((d & 1)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (p != pi)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding skip = p;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return p - h + 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding d >>= 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while (d);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pi = skip;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding p = pi + nl;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return hl;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* We've now found a start sequence tag... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_bucket* found_start_sequence(apr_bucket *dptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t tagStart,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t len)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We want to split the bucket at the '<'. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSE_DIRECTIVE;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Don't set tag_start_bucket if tagStart indexes the end of the bucket. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tagStart < len) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_start_bucket = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_start_index = tagStart;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->head_start_index > 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *tmp_bkt;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Split the bucket with the start of the tag in it */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_split(ctx->head_start_bucket, ctx->head_start_index);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_bkt = APR_BUCKET_NEXT(ctx->head_start_bucket);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* If it was a one bucket match */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((tagStart < len) && (dptr == ctx->head_start_bucket)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_start_bucket = tmp_bkt;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_start_index = tagStart - ctx->head_start_index;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_bucket = tmp_bkt;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_index = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return ctx->head_start_bucket;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* This function returns either a pointer to the split bucket containing the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * first byte of the BEGINNING_SEQUENCE (after finding a complete match) or it
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * returns NULL if no match found.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_bucket *find_start_sequence(apr_bucket *dptr, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_brigade *bb, int *do_cleanup)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *str = ctx->start_seq ;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t slen = ctx->start_seq_len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t pos;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *do_cleanup = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_status_t rv = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int read_done = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (APR_BUCKET_IS_EOS(dptr)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#if 0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX the bucket flush support is commented out for now
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * because it was causing a segfault */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (APR_BUCKET_IS_FLUSH(dptr)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *old = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dptr = APR_BUCKET_NEXT(old);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_BUCKET_REMOVE(old);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_now = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_flush = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif /* 0 */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->bytes_parsed >= BYTE_COUNT_THRESHOLD) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_now = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (ctx->bytes_parsed > 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_NONBLOCK_READ);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding read_done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (APR_STATUS_IS_EAGAIN(rv)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_now = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->output_now) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *start_bucket;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->head_start_index > 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding start_bucket = ctx->head_start_bucket;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_split(start_bucket, ctx->head_start_index);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding start_bucket = APR_BUCKET_NEXT(start_bucket);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_index = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_bucket = start_bucket;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PRE_HEAD;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding start_bucket = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return start_bucket;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!read_done) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_BLOCK_READ);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!APR_STATUS_IS_SUCCESS(rv)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->status = rv;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (len == 0) { /* end of pipe? */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Set our buffer to use. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c = buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* The last bucket had a left over partial match that we need to
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * complete.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->state == PARSE_HEAD)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t tmpLen;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmpLen = (len < (slen - 1)) ? len : (slen - 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (c < buf + tmpLen && *c == str[ctx->parse_pos])
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (str[ctx->parse_pos] == '\0')
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->bytes_parsed += c - buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return found_start_sequence(dptr, ctx, c - buf, len);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (c == buf + tmpLen) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dptr = APR_BUCKET_NEXT(dptr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* False alarm...
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_BRIGADE_PREPEND(bb, ctx->ssi_tag_brigade);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We know we are at the beginning of this bucket so
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * we can just prepend the saved bytes from the
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb * ssi_tag_brigade (which empties the ssi_tag_brigade)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * and continue processing.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * We do not need to set do_cleanup beacuse the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * prepend takes care of that.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PRE_HEAD;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_bucket = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_index = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (len)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding pos = bndm(str, slen, c, len, ctx->start_seq_pat);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (pos != len)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_bucket = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_index = pos;
44d275fe4ce94e3b2d73614b1930a2e43e6fba8fstoddard ctx->bytes_parsed += pos + slen;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return found_start_sequence(dptr, ctx, pos + slen, len);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Consider the case where we have <!-- at the end of the bucket. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (len > slen) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->bytes_parsed += (len - slen);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c = buf + len - slen;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c = buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (c < buf + len)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == str[ctx->parse_pos]) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->state == PRE_HEAD) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSE_HEAD;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_bucket = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_index = c - buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->bytes_parsed++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (ctx->parse_pos != 0)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* DO NOT INCREMENT c IN THIS BLOCK!
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Don't increment bytes_parsed either.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This block is just to reset the indexes and
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * pointers related to parsing the tag start_sequence.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The value c needs to be checked again to handle
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the case where we find "<<!--#". We are now
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * looking at the second "<" and need to restart
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the start_sequence checking from parse_pos = 0.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * do_cleanup causes the stored bytes in ssi_tag_brigade
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * to be forwarded on and cleaned up. We may not be
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * able to just prepend the ssi_tag_brigade because
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * we may have advanced too far before we noticed this
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * case, so just flag it and clean it up later.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *do_cleanup = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PRE_HEAD;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_bucket = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->head_start_index = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->bytes_parsed++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dptr = APR_BUCKET_NEXT(dptr);
66d349e02d1a5a599a01c977d2c5b0009181f7deben } while (dptr != APR_BRIGADE_SENTINEL(bb));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
b79b743d4cff02d6a830bb7118826a2fd608742amartin return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_bucket *find_end_sequence(apr_bucket *dptr, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_brigade *bb)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *str = ctx->end_seq;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *start;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_status_t rv = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int read_done = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (APR_BUCKET_IS_EOS(dptr)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#if 0
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX the bucket flush support is commented out for now
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * because it was causing a segfault */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (APR_BUCKET_IS_FLUSH(dptr)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *old = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dptr = APR_BUCKET_NEXT(old);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_BUCKET_REMOVE(old);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_now = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_flush = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif /* 0 */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->bytes_parsed >= BYTE_COUNT_THRESHOLD) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_now = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (ctx->bytes_parsed > 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_NONBLOCK_READ);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding read_done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (APR_STATUS_IS_EAGAIN(rv)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->output_now = 1;
44d275fe4ce94e3b2d73614b1930a2e43e6fba8fstoddard }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->output_now) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->state == PARSE_DIRECTIVE) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* gonna start over parsing the directive next time through */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->directive_length = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!read_done) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_BLOCK_READ);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!APR_STATUS_IS_SUCCESS(rv)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->status = rv;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (len == 0) { /* end of pipe? */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (dptr == ctx->tag_start_bucket) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c = buf + ctx->tag_start_index;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c = buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding start = c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (c < buf + len) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == str[ctx->parse_pos]) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->state != PARSE_TAIL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSE_TAIL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tail_start_bucket = dptr;
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb ctx->tail_start_index = c - buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (str[ctx->parse_pos] == '\0') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *tmp_buck = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We want to split the bucket at the '>'. The
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * end of the END_SEQUENCE is in the current bucket.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The beginning might be in a previous bucket.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->bytes_parsed += (c - start);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSED;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_split(dptr, c - buf);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = APR_BUCKET_NEXT(dptr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (tmp_buck);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->state == PARSE_DIRECTIVE) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->tag_length == 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!apr_isspace(*c)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *tmp = c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_start_bucket = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_start_index = c - buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while ((c < buf + len) && !apr_isspace(*c) &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *c != *str);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length = ctx->directive_length = c - tmp;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!apr_isspace(*c)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->directive_length++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSE_TAG;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (ctx->state == PARSE_TAG) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *tmp = c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while ((c < buf + len) && (*c != *str));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length += (c - tmp);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->parse_pos != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* The reason for this, is that we need to make sure
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * that we catch cases like --->. This makes the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * second check after the original check fails.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * If parse_pos was already 0 then we already checked
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * this.
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length += ctx->parse_pos;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == str[0]) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSE_TAIL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tail_start_bucket = dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tail_start_index = c - buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->tag_length > ctx->directive_length) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSE_TAG;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->state = PARSE_DIRECTIVE;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->directive_length += ctx->parse_pos;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tail_start_bucket = NULL;
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard ctx->tail_start_index = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->parse_pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->bytes_parsed += (c - start);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dptr = APR_BUCKET_NEXT(dptr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while (dptr != APR_BRIGADE_SENTINEL(bb));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* This function culls through the buckets that have been set aside in the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ssi_tag_brigade and copies just the directive part of the SSI tag (none
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * of the start and end delimiter bytes are copied).
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_status_t get_combined_directive (include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_brigade *bb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tmp_buf,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t tmp_buf_size)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int done = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *dptr;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *tmp_from;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t tmp_from_len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* If the tag length is longer than the tmp buffer, allocate space. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->tag_length > tmp_buf_size-1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((ctx->combined_tag = apr_pcalloc(r->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_length + 1)) == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (APR_ENOMEM);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } /* Else, just use the temp buffer. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->combined_tag = tmp_buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Prime the pump. Start at the beginning of the tag... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dptr = ctx->tag_start_bucket;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Read the bucket... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_read (dptr, &tmp_from, &tmp_from_len, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Adjust the pointer to start at the tag within the bucket... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (dptr == ctx->tail_start_bucket) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_from_len -= (tmp_from_len - ctx->tail_start_index);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_from = &tmp_from[ctx->tag_start_index];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_from_len -= ctx->tag_start_index;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->curr_tag_pos = ctx->combined_tag;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Loop through the buckets from the tag_start_bucket until before
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the tail_start_bucket copying the contents into the buffer.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy (ctx->curr_tag_pos, tmp_from, tmp_from_len);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->curr_tag_pos += tmp_from_len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (dptr == ctx->tail_start_bucket) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding dptr = APR_BUCKET_NEXT (dptr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_read (dptr, &tmp_from, &tmp_from_len, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Adjust the count to stop at the beginning of the tail. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (dptr == ctx->tail_start_bucket) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_from_len -= (tmp_from_len - ctx->tail_start_index);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin } while ((!done) &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (ctx->curr_tag_pos < ctx->combined_tag + ctx->tag_length));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->combined_tag[ctx->tag_length] = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->curr_tag_pos = ctx->combined_tag;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (APR_SUCCESS);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * decodes a string containing html entities or numeric character references.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 's' is overwritten with the decoded string.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * If 's' is syntatically incorrect, then the followed fixups will be made:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * unknown entities will be left undecoded;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * references to unused numeric characters will be deleted.
b79b743d4cff02d6a830bb7118826a2fd608742amartin * In particular, &#00; will not be decoded, but will be deleted.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * drtr
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* maximum length of any ISO-LATIN-1 HTML entity name. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define MAXENTLEN (6)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* The following is a shrinking transformation, therefore safe. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void decodehtml(char *s)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int val, i, j;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *p;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *ents;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding static const char * const entlist[MAXENTLEN + 1] =
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh NULL, /* 0 */
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb NULL, /* 1 */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh "lt\074gt\076", /* 2 */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh "amp\046ETH\320eth\360", /* 3 */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh "quot\042Auml\304Euml\313Iuml\317Ouml\326Uuml\334auml\344euml\353\
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjhiuml\357ouml\366uuml\374yuml\377", /* 4 */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh "Acirc\302Aring\305AElig\306Ecirc\312Icirc\316Ocirc\324Ucirc\333\
66d349e02d1a5a599a01c977d2c5b0009181f7debenTHORN\336szlig\337acirc\342aring\345aelig\346ecirc\352icirc\356ocirc\364\
23cfa61aaed581f103070c8733a493b31f990f9brbbucirc\373thorn\376", /* 5 */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh "Agrave\300Aacute\301Atilde\303Ccedil\307Egrave\310Eacute\311\
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjhIgrave\314Iacute\315Ntilde\321Ograve\322Oacute\323Otilde\325Oslash\330\
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjhUgrave\331Uacute\332Yacute\335agrave\340aacute\341atilde\343ccedil\347\
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjhegrave\350eacute\351igrave\354iacute\355ntilde\361ograve\362oacute\363\
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjhotilde\365oslash\370ugrave\371uacute\372yacute\375" /* 6 */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh };
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh /* Do a fast scan through the string until we find anything
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh * that needs more complicated handling
23cfa61aaed581f103070c8733a493b31f990f9brbb */
23cfa61aaed581f103070c8733a493b31f990f9brbb for (; *s != '&'; s++) {
23cfa61aaed581f103070c8733a493b31f990f9brbb if (*s == '\0') {
23cfa61aaed581f103070c8733a493b31f990f9brbb return;
23cfa61aaed581f103070c8733a493b31f990f9brbb }
23cfa61aaed581f103070c8733a493b31f990f9brbb }
23cfa61aaed581f103070c8733a493b31f990f9brbb
23cfa61aaed581f103070c8733a493b31f990f9brbb for (p = s; *s != '\0'; s++, p++) {
23cfa61aaed581f103070c8733a493b31f990f9brbb if (*s != '&') {
23cfa61aaed581f103070c8733a493b31f990f9brbb *p = *s;
23cfa61aaed581f103070c8733a493b31f990f9brbb continue;
23cfa61aaed581f103070c8733a493b31f990f9brbb }
23cfa61aaed581f103070c8733a493b31f990f9brbb /* find end of entity */
23cfa61aaed581f103070c8733a493b31f990f9brbb for (i = 1; s[i] != ';' && s[i] != '\0'; i++) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh continue;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (s[i] == '\0') { /* treat as normal data */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *p = *s;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh continue;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh /* is it numeric ? */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (s[1] == '#') {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh for (j = 2, val = 0; j < i && apr_isdigit(s[j]); j++) {
829bc6b670c7be394ccd33886add7ac39e276976trawick val = val * 10 + s[j] - '0';
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb s += i;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (j < i || val <= 8 || (val >= 11 && val <= 31) ||
9ede6357edc9aff1fb2f7edebefab473673298aarbb (val >= 127 && val <= 160) || val >= 256) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh p--; /* no data to output */
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb }
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb else {
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb *p = RAW_ASCII_CHAR(val);
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb }
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb }
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding j = i - 1;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (j > MAXENTLEN || entlist[j] == NULL) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh /* wrong length */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *p = '&';
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh continue; /* skip it */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh for (ents = entlist[j]; *ents != '\0'; ents += i) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (strncmp(s + 1, ents, j) == 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*ents == '\0') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *p = '&'; /* unknown */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *p = RAW_ASCII_CHAR(((const unsigned char *) ents)[j]);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding s += i;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *p = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Extract the next tag name and value.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * If there are no more tags, set the tag name to NULL.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The tag value is html decoded if dodecode is non-zero.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The tag value may be NULL if there is no tag value..
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * format:
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh * [WS]<Tag>[WS]=[WS]['|"|`]<Value>[['|"|`|]|WS]
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb */
a952e0c6ece342d88f2bc04e20dcfc563398eed3rbb
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh#define SKIP_TAG_WHITESPACE(ptr) while ((*ptr != '\0') && (apr_isspace (*ptr))) ptr++
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbbstatic void ap_ssi_get_tag_and_value(include_ctx_t *ctx, char **tag,
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb char **tag_val, int dodecode)
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb{
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb char *c = ctx->curr_tag_pos;
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb int shift_val = 0;
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb char term = '\0';
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbb *tag_val = NULL;
14552184cfa95bd49b274b434390cc5195e8375crbb if (ctx->curr_tag_pos > ctx->combined_tag + ctx->tag_length) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *tag = NULL;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh return;
14552184cfa95bd49b274b434390cc5195e8375crbb }
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh SKIP_TAG_WHITESPACE(c);
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *tag = c; /* First non-whitespace character (could be NULL). */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh while (apr_islower(*c)) {
23cfa61aaed581f103070c8733a493b31f990f9brbb c++; /* Optimization for the common case where the tag */
829bc6b670c7be394ccd33886add7ac39e276976trawick } /* is already lowercase */
829bc6b670c7be394ccd33886add7ac39e276976trawick
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while ((*c != '=') && (!apr_isspace(*c)) && (*c != '\0')) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *c = apr_tolower(*c); /* find end of tag, lowercasing as we go... */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh c++;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
14552184cfa95bd49b274b434390cc5195e8375crbb
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if ((*c == '\0') || (**tag == '=')) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if ((**tag == '\0') || (**tag == '=')) {
829bc6b670c7be394ccd33886add7ac39e276976trawick *tag = NULL;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
829bc6b670c7be394ccd33886add7ac39e276976trawick ctx->curr_tag_pos = c;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh return; /* We have found the end of the buffer. */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh } /* We might have a tag, but definitely no value. */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (*c == '=') {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *c++ = '\0'; /* Overwrite the '=' with a terminating byte after tag. */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh else { /* Try skipping WS to find the '='. */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *c++ = '\0'; /* Terminate the tag... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding SKIP_TAG_WHITESPACE(c);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* There needs to be an equal sign if there's a value. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c != '=') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->curr_tag_pos = c;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh return; /* There apparently was no value. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++; /* Skip the equals sign. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding SKIP_TAG_WHITESPACE(c);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == '"' || *c == '\'' || *c == '`') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Allow quoted values for space inclusion.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * NOTE: This does not pass the quotes on return.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding term = *c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *tag_val = c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!term) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (!apr_isspace(*c) && (*c != '\0')) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while ((*c != term) && (*c != '\0') && (*c != '\\')) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Quickly scan past the string until we reach
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * either the end of the tag or a backslash. If
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * we find a backslash, we have to switch to the
b79b743d4cff02d6a830bb7118826a2fd608742amartin * more complicated parser loop that follows.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == '\\') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Accept \" (or ' or `) as valid quotation of string.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == '\\') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Overwrite the "\" during the embedded
b79b743d4cff02d6a830bb7118826a2fd608742amartin * escape sequence of '"'. "\'" or '`'.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Shift bytes from here to next delimiter.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == term) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding shift_val++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (shift_val > 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *(c-shift_val) = *c;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == '\0') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim }
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim c++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (shift_val > 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *(c-shift_val) = *c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while ((*c != term) && (*c != '\0'));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *(c-shift_val) = '\0'; /* Overwrites delimiter (term or WS) with NULL. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->curr_tag_pos = ++c;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim if (dodecode) {
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim decodehtml(*tag_val);
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim }
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim return;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim}
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim/* initial buffer size for power-of-two allocator in ap_ssi_parse_string */
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim#define PARSE_STRING_INITIAL_SIZE 64
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Do variable substitution on strings
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * (Note: If out==NULL, this function allocs a buffer for the resulting
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * string from r->pool. The return value is the parsed string)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic char *ap_ssi_parse_string(request_rec *r, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *in, char *out,
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim apr_size_t length, int leave_name)
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim{
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim char ch;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim char *next;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim char *end_out;
0c17e19b2f9ebb28c25f9efa6cd58d257e1ad728dreid apr_size_t out_size;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim /* allocate an output buffer if needed */
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim if (!out) {
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim out_size = PARSE_STRING_INITIAL_SIZE;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim if (out_size > length) {
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim out_size = length;
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding out = apr_palloc(r->pool, out_size);
b79b743d4cff02d6a830bb7118826a2fd608742amartin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding out_size = length;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* leave room for nul terminator */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding end_out = out + out_size - 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding next = out;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh while ((ch = *in++) != '\0') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (ch) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '\\':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (next == end_out) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (out_size < length) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* double the buffer size */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t new_out_size = out_size * 2;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t current_length = next - out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *new_out;
b79b743d4cff02d6a830bb7118826a2fd608742amartin if (new_out_size > length) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new_out_size = length;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new_out = apr_palloc(r->pool, new_out_size);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(new_out, out, current_length);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding out = new_out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding out_size = new_out_size;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding end_out = out + out_size - 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding next = out + current_length;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* truncated */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *next = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*in == '$') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *next++ = *in++;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *next++ = ch;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '$':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *start_of_var_name;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *end_of_var_name; /* end of var name + 1 */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *expansion, *temp_end, *val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char tmp_store;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding size_t l;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* guess that the expansion won't happen */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expansion = in - 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*in == '{') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ++in;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding start_of_var_name = in;
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb in = ap_strchr_c(in, '}');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (in == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding 0, r, "Missing '}' on variable \"%s\"",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expansion);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *next = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding temp_end = in;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding end_of_var_name = (char *)temp_end;
6db54801798f6021bb464de7b3fdcc9dc3150f7bdgaudet ++in;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding start_of_var_name = in;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (apr_isalnum(*in) || *in == '_') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ++in;
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding temp_end = in;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding end_of_var_name = (char *)temp_end;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* what a pain, too bad there's no table_getn where you can
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * pass a non-nul terminated string */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding l = end_of_var_name - start_of_var_name;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (l != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_store = *end_of_var_name;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *end_of_var_name = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = get_include_var(r, ctx, start_of_var_name);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *end_of_var_name = tmp_store;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (val) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expansion = val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding l = strlen(expansion);
b79b743d4cff02d6a830bb7118826a2fd608742amartin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (leave_name) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding l = in - expansion;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* no expansion to be done */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard /* zero-length variable name causes just the $ to be
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * copied */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding l = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((next + l > end_out) && (out_size < length)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* increase the buffer size to accommodate l more chars */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t new_out_size = out_size;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t current_length = next - out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *new_out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding do {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new_out_size *= 2;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while (new_out_size < current_length + l);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (new_out_size > length) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new_out_size = length;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new_out = apr_palloc(r->pool, new_out_size);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(new_out, out, current_length);
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb out = new_out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding out_size = new_out_size;
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard end_out = out + out_size - 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding next = out + current_length;
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding l = ((int)l > end_out - next) ? (end_out - next) : l;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(next, expansion, l);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding next += l;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (next == end_out) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (out_size < length) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* double the buffer size */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t new_out_size = out_size * 2;
9cb787a8a3d06704ab9c51ffd51525b364151182trawick apr_size_t current_length = next - out;
9cb787a8a3d06704ab9c51ffd51525b364151182trawick char *new_out;
9cb787a8a3d06704ab9c51ffd51525b364151182trawick if (new_out_size > length) {
b79b743d4cff02d6a830bb7118826a2fd608742amartin new_out_size = length;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new_out = apr_palloc(r->pool, new_out_size);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(new_out, out, current_length);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding out = new_out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding out_size = new_out_size;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding end_out = out + out_size - 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding next = out + current_length;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* truncated */
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb *next = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return out;
85482525adee8e37838e0a5fca66e740a7fb5c2estoddard }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *next++ = ch;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *next = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return out;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* --------------------------- Action handlers ---------------------------- */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* ensure that path is relative, and does not contain ".." elements
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ensentially ensure that it does not match the regex:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * (^/|(^|/)\.\.(/|$))
b79b743d4cff02d6a830bb7118826a2fd608742amartin * XXX: Simply replace with apr_filepath_merge
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int is_only_below(const char *path)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef HAVE_DRIVE_LETTERS
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (path[1] == ':')
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef NETWARE
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (strchr(path, ':'))
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (path[0] == '/') {
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (*path) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int dots = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (path[dots] == '.')
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ++dots;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#if defined(WIN32)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* If the name is canonical this is redundant
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * but in security, redundancy is worthwhile.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Does OS2 belong here (accepts ... for ..)?
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (dots > 1 && (!path[dots] || path[dots] == '/'))
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#else
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard if (dots == 2 && (!path[dots] || path[dots] == '/'))
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding path += dots;
818ad8d5e5ba620e403412b947a26d578f653eedben /* Advance to either the null byte at the end of the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * string or the character right after the next slash,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * whichever comes first
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (*path && (*path++ != '/')) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int handle_include(include_ctx_t *ctx, apr_bucket_brigade **bb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket **inserted_head)
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag_val = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *tmp_buck;
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard char *parsed_string;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int loglevel = APLOG_ERR;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->flags & FLAG_PRINTING) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag_val == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (1);
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcmp(tag, "virtual") || !strcmp(tag, "file")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *rr = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *error_fmt = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_status_t rc = APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding SPLIT_AND_PASS_PRETAG_BUCKETS(*bb, ctx, f->next, rc);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rc != APR_SUCCESS) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return rc;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
b79b743d4cff02d6a830bb7118826a2fd608742amartin MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag[0] == 'f') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX: Port to apr_filepath_merge
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * be safe; only files in this directory or below allowed
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!is_only_below(parsed_string)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to include file \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rr = ap_sub_req_lookup_file(parsed_string, r, f->next);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rr = ap_sub_req_lookup_uri(parsed_string, r, f->next);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!error_fmt && rr->status != HTTP_OK) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to include \"%s\" in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!error_fmt && (ctx->flags & FLAG_NO_EXEC) &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rr->content_type &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (strncmp(rr->content_type, "text/", 5))) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to include potential exec \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (error_fmt == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* try to avoid recursive includes. We do this by walking
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * up the r->main list of subrequests, and at each level
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * walking back through any internal redirects. At each
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * step, we compare the filenames and the URIs.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The filename comparison catches a recursive include
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * with an ever-changing URL, eg.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * <!--#include virtual=
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * "$REQUEST_URI/$QUERY_STRING?$QUERY_STRING/x" -->
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * which, although they would eventually be caught because
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * we have a limit on the length of files, etc., can
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * recurse for a while.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * The URI comparison catches the case where the filename
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * is changed while processing the request, so the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * current name is never the same as any previous one.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This can happen with "DocumentRoot /foo" when you
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * request "/" on the server and it includes "/".
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * This only applies to modules such as mod_dir that
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * (somewhat improperly) mess with r->filename outside
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * of a filename translation phase.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int founddupe = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *p;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (p = r; p != NULL && !founddupe; p = p->main) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *q;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (q = p; q != NULL; q = q->prev) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((q->filename && rr->filename &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (strcmp(q->filename, rr->filename) == 0)) ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ((*q->uri == '/') &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (strcmp(q->uri, rr->uri) == 0)))
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding founddupe = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (p != NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "Recursive include of \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* See the Kludge in send_parsed_file for why */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Basically, it puts a bread crumb in here, then looks */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* for the crumb later to see if its been here. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_set_module_config(rr->request_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding &include_module, r);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!error_fmt && ap_run_sub_req(rr)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to include \"%s\" in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (error_fmt) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|loglevel,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding 0, r, error_fmt, tag_val, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* destroy the sub request */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr != NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_destroy_sub_req(rr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" to tag include in %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tag, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int handle_echo(include_ctx_t *ctx, apr_bucket_brigade **bb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket **inserted_head)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag_val = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *echo_text = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *tmp_buck;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t e_len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding enum {E_NONE, E_URL, E_ENTITY} encode;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding encode = E_ENTITY;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->flags & FLAG_PRINTING) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag_val == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag != NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcmp(tag, "var")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding conn_rec *c = r->connection;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *val =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding get_include_var(r, ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_parse_string(r, ctx, tag_val, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN, 0));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (val) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch(encode) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case E_NONE:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding echo_text = val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case E_URL:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding echo_text = ap_escape_uri(r->pool, val);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case E_ENTITY:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding echo_text = ap_escape_html(r->pool, val);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding e_len = strlen(echo_text);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_pool_create(echo_text, e_len,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding r->pool, c->bucket_alloc);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding include_server_config *sconf=
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_get_module_config(r->server->module_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding &include_module);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_pool_create(sconf->undefinedEcho,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sconf->undefinedEchoLen,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding r->pool, c->bucket_alloc);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*inserted_head == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = tmp_buck;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcmp(tag, "encoding")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcasecmp(tag_val, "none")) encode = E_NONE;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcasecmp(tag_val, "url")) encode = E_URL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcasecmp(tag_val, "entity")) encode = E_ENTITY;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown value \"%s\" to parameter \"encoding\" of "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "tag echo in %s", tag_val, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" in tag echo of %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tag, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb/* error and tf must point to a string with room for at
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * least MAX_STRING_LEN characters
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int handle_config(include_ctx_t *ctx, apr_bucket_brigade **bb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket **inserted_head)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb char *tag = NULL;
b79b743d4cff02d6a830bb7118826a2fd608742amartin char *tag_val = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *parsed_string;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_t *env = r->subprocess_env;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->flags & FLAG_PRINTING) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag_val == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0; /* Reached the end of the string. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 1; /* tags must have values. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcmp(tag, "errmsg")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->error_str_override == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->error_str_override = (char *)apr_palloc(ctx->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->error_str = ctx->error_str_override;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_parse_string(r, ctx, tag_val, ctx->error_str_override,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcmp(tag, "timefmt")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_time_t date = r->request_time;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->time_str_override == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->time_str_override = (char *)apr_palloc(ctx->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->time_str = ctx->time_str_override;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_parse_string(r, ctx, tag_val, ctx->time_str_override,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(env, "DATE_LOCAL", ap_ht_time(r->pool, date,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->time_str, 0));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(env, "DATE_GMT", ap_ht_time(r->pool, date,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->time_str, 1));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(env, "LAST_MODIFIED",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ht_time(r->pool, r->finfo.mtime,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->time_str, 0));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcmp(tag, "sizefmt")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding decodehtml(parsed_string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcmp(parsed_string, "bytes")) {
b79b743d4cff02d6a830bb7118826a2fd608742amartin ctx->flags |= FLAG_SIZE_IN_BYTES;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcmp(parsed_string, "abbrev")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->flags &= FLAG_SIZE_ABBREV;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *tmp_buck;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" to tag config in %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tag, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int find_file(request_rec *r, const char *directive, const char *tag,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag_val, apr_finfo_t *finfo)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *to_send = tag_val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *rr = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int ret=0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *error_fmt = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_status_t rv = APR_SUCCESS;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcmp(tag, "file")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX: Port to apr_filepath_merge
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * be safe; only files in this directory or below allowed
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!is_only_below(tag_val)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to access file \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_getparents(tag_val); /* get rid of any nasties */
b79b743d4cff02d6a830bb7118826a2fd608742amartin
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* note: it is okay to pass NULL for the "next filter" since
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding we never attempt to "run" this sub request. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rr = ap_sub_req_lookup_file(tag_val, r, NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr->status == HTTP_OK && rr->finfo.filetype != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding to_send = rr->filename;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((rv = apr_stat(finfo, to_send,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_FINFO_GPROT | APR_FINFO_MIN, rr->pool)) != APR_SUCCESS
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding && rv != APR_INCOMPLETE) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to get information about \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to lookup information about \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (error_fmt) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ret = -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_ERR | (rv ? 0 : APLOG_NOERRNO),
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv, r, error_fmt, to_send, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr) ap_destroy_sub_req(rr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return ret;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcmp(tag, "virtual")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* note: it is okay to pass NULL for the "next filter" since
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding we never attempt to "run" this sub request. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rr = ap_sub_req_lookup_uri(tag_val, r, NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr->status == HTTP_OK && rr->finfo.filetype != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy((char *) finfo, (const char *) &rr->finfo,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(rr->finfo));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_destroy_sub_req(rr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unable to get information about \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s",
b79b743d4cff02d6a830bb7118826a2fd608742amartin tag_val, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_destroy_sub_req(rr);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" to tag %s in %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tag, directive, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int handle_fsize(include_ctx_t *ctx, apr_bucket_brigade **bb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket **inserted_head)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag_val = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_finfo_t finfo;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t s_len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *tmp_buck;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *parsed_string;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->flags & FLAG_PRINTING) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag_val == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!find_file(r, "fsize", tag, parsed_string, &finfo)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX: if we *know* we're going to have to copy the
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * thing off of the stack anyway, why not palloc buff
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * instead of sticking it on the stack; then we can just
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * use a pool bucket and skip the copy
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char buff[50];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!(ctx->flags & FLAG_SIZE_IN_BYTES)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_strfsize(finfo.size, buff);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding s_len = strlen (buff);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int l, x, pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char tmp_buff[50];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_snprintf(tmp_buff, sizeof(tmp_buff),
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "%" APR_OFF_T_FMT, finfo.size);
b79b743d4cff02d6a830bb7118826a2fd608742amartin l = strlen(tmp_buff); /* grrr */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (x = 0; x < l; x++) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (x && (!((l - x) % 3))) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buff[pos++] = ',';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buff[pos++] = tmp_buff[x];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buff[pos] = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding s_len = pos;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_heap_create(buff, s_len, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding r->connection->bucket_alloc);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*inserted_head == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = tmp_buck;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int handle_flastmod(include_ctx_t *ctx, apr_bucket_brigade **bb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding request_rec *r, ap_filter_t *f,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *head_ptr, apr_bucket **inserted_head)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *tag_val = NULL;
b79b743d4cff02d6a830bb7118826a2fd608742amartin apr_finfo_t finfo;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t t_len;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket *tmp_buck;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *parsed_string;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ctx->flags & FLAG_PRINTING) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag_val == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (tag == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!find_file(r, "flastmod", tag, parsed_string, &finfo)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *t_val;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding t_val = ap_ht_time(r->pool, finfo.mtime, ctx->time_str, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding t_len = strlen(t_val);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_pool_create(t_val, t_len, r->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding r->connection->bucket_alloc);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*inserted_head == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head = tmp_buck;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int re_check(request_rec *r, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char *string, char *rexp)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding regex_t *compiled;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const apr_size_t nres = sizeof(*ctx->re_result) / sizeof(regmatch_t);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int regex_error;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding compiled = ap_pregcomp(r->pool, rexp, REG_EXTENDED | REG_NOSUB);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (compiled == NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unable to compile pattern \"%s\"", rexp);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return -1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!ctx->re_result) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->re_result = apr_pcalloc(r->pool, sizeof(*ctx->re_result));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->re_string = string;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding regex_error = ap_regexec(compiled, string, nres, *ctx->re_result, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_pregfree(r->pool, compiled);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (!regex_error);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingenum token_type {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token_string, token_re,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token_and, token_or, token_not, token_eq, token_ne,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token_rbrace, token_lbrace, token_group,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token_ge, token_le, token_gt, token_lt
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding};
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstruct token {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding enum token_type type;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char* value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding};
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char *get_ptoken(request_rec *r, const char *string,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct token *token, int *unmatched)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char ch;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int next = 0;
b79b743d4cff02d6a830bb7118826a2fd608742amartin char qs = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int tkn_fnd = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->value = NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Skip leading white space */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (string == (char *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (char *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while ((ch = *string++)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!apr_isspace(ch)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ch == '\0') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (char *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_string; /* the default type */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (ch) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '(':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_lbrace;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case ')':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_rbrace;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '=':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_eq;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '!':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*string == '=') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_ne;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string + 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_not;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '\'':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* already token->type == token_string */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding qs = '\'';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '/':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_re;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding qs = '/';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '|':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*string == '|') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_or;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string + 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '&':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*string == '&') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_and;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string + 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '>':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*string == '=') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_ge;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string + 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_gt;
b79b743d4cff02d6a830bb7118826a2fd608742amartin return (string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '<':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*string == '=') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_le;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string + 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->type = token_lt;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* already token->type == token_string */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We should only be here if we are in a string */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->value = apr_palloc(r->pool, strlen(string) + 2); /* 2 for ch plus
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding trailing null */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!qs) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->value[next++] = ch;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /*
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * I used the ++string throughout this section so that string
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * ends up pointing to the next token and I can just return it
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (ch = *string; ((ch != '\0') && (!tkn_fnd)); ch = *++string) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ch == '\\') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((ch = *++string) == '\0') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tkn_fnd = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->value[next++] = ch;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!qs) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (apr_isspace(ch)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tkn_fnd = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (ch) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '(':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case ')':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '=':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '!':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '<':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '>':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tkn_fnd = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '|':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*(string + 1) == '|') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tkn_fnd = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case '&':
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*(string + 1) == '&') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tkn_fnd = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!tkn_fnd) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->value[next++] = ch;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ch == qs) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding qs = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tkn_fnd = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->value[next++] = ch;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* If qs is still set, we have an unmatched quote */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (qs) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *unmatched = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding next = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token->value[next] = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (string);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* there is an implicit assumption here that expr is at most MAX_STRING_LEN-1
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * characters long...
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int parse_expr(request_rec *r, include_ctx_t *ctx, const char *expr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int *was_error, int *was_unmatched, char *debug)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct parse_node {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct parse_node *left, *right, *parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding struct token token;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int value, done;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } *root, *current, *new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *parse;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char* buffer;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding int retval = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_size_t debug_pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug[debug_pos] = '\0';
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_unmatched = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((parse = expr) == (char *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = current = (struct parse_node *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Create Parse Tree */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new = (struct parse_node *) apr_palloc(r->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(struct parse_node));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = new->left = new->right = (struct parse_node *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->done = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((parse = get_ptoken(r, parse, &new->token, was_unmatched)) ==
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (char *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (new->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos],
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Token: string (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->token.value);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->token.value = apr_pstrcat(r->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->token.value[0] ? " " : "",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding NULL);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
b79b743d4cff02d6a830bb7118826a2fd608742amartin case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ge:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_gt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_le:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = current;
b79b743d4cff02d6a830bb7118826a2fd608742amartin current = current->right = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
b79b743d4cff02d6a830bb7118826a2fd608742amartin return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_re:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos],
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Token: regex (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->token.value);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = current;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->right = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
b79b743d4cff02d6a830bb7118826a2fd608742amartin *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy (&debug[debug_pos], " Token: and/or\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Token: and/or\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof (" Token: and/or\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Percolate upwards */
b79b743d4cff02d6a830bb7118826a2fd608742amartin while (current != (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_re:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_group:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ge:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_gt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_le:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = root;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left->parent = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = (struct parse_node *) NULL;
b79b743d4cff02d6a830bb7118826a2fd608742amartin root = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = current->right;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = current;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(&debug[debug_pos], " Token: not\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(" Token: not\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof(" Token: not\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
b79b743d4cff02d6a830bb7118826a2fd608742amartin /* Percolate upwards */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (current != (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ge:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_gt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_le:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = root;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left->parent = new;
b79b743d4cff02d6a830bb7118826a2fd608742amartin new->parent = (struct parse_node *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = current->right;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = current;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ge:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_gt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_le:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(&debug[debug_pos], " Token: eq/ne/ge/gt/le/lt\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(" Token: eq/ne/ge/gt/le/lt\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof(" Token: eq/ne/ge/gt/le/lt\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
b79b743d4cff02d6a830bb7118826a2fd608742amartin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Percolate upwards */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (current != (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_re:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_group:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ge:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_gt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_le:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
b79b743d4cff02d6a830bb7118826a2fd608742amartin }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = root;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left->parent = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = (struct parse_node *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = current->right;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right = new;
b79b743d4cff02d6a830bb7118826a2fd608742amartin new->parent = current;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_rbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy (&debug[debug_pos], " Token: rbrace\n",
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh sizeof (" Token: rbrace\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof (" Token: rbrace\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (current != (struct parse_node *) NULL) {
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb if (current->token.type == token_lbrace) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh current->token.type = token_group;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Unmatched ')' in \"%s\" in file %s",
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim expr, r->filename);
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
b79b743d4cff02d6a830bb7118826a2fd608742amartin case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy (&debug[debug_pos], " Token: lbrace\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Token: lbrace\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof (" Token: lbrace\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Percolate upwards */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (current != (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ge:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_gt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_le:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_re:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_group:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = root;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left->parent = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = (struct parse_node *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding root = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->left = current->right;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right = new;
b79b743d4cff02d6a830bb7118826a2fd608742amartin new->parent = current;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = new;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Evaluate Parse Tree */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = root;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (current != (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy (&debug[debug_pos], " Evaluate string\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Evaluate string\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof (" Evaluate string\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->token.value, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->token.value = buffer;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = (current->token.value[0] != '\0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_re:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "No operator before regex of expr \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_and:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_or:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(&debug[debug_pos], " Evaluate and/or\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(" Evaluate and/or\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof(" Evaluate and/or\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current->left == (struct parse_node *) NULL ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right == (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
b79b743d4cff02d6a830bb7118826a2fd608742amartin *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!current->left->done) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->left->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding NULL, MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->token.value = buffer;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->value =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (current->left->token.value[0] != '\0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->left;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!current->right->done) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding switch (current->right->token.type) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_string:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->right->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding NULL, MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value = buffer;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->value =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (current->right->token.value[0] != '\0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->right;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Left: %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->value ? '1' : '0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Right: %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->value ? '1' : '0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
b79b743d4cff02d6a830bb7118826a2fd608742amartin if (current->token.type == token_and) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = current->left->value && current->right->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = current->left->value || current->right->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Returning %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value ? '1' : '0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
b79b743d4cff02d6a830bb7118826a2fd608742amartin current->done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_eq:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ne:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy (&debug[debug_pos], " Evaluate eq/ne\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Evaluate eq/ne\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof (" Evaluate eq/ne\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((current->left == (struct parse_node *) NULL) ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (current->right == (struct parse_node *) NULL) ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (current->left->token.type != token_string) ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ((current->right->token.type != token_string) &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (current->right->token.type != token_re))) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding NULL, MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->token.value = buffer;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->right->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding NULL, MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value = buffer;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current->right->token.type == token_re) {
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos],
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Re Compare (%s) with /%s/\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value =
ebe70c2684539a5fb2d899241d1601710dfa38a4trawick re_check(r, ctx, current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos],
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Compare (%s) with (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (strcmp(current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value) == 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current->token.type == token_ne) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = !current->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Returning %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value ? '1' : '0');
7463de0c603f07c9e1820e812d2f1a73661843e6rbb#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->done = 1;
9ede6357edc9aff1fb2f7edebefab473673298aarbb current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_ge:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_gt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_le:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lt:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
7463de0c603f07c9e1820e812d2f1a73661843e6rbb memcpy (&debug[debug_pos], " Evaluate ge/gt/le/lt\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Evaluate ge/gt/le/lt\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof (" Evaluate ge/gt/le/lt\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
7463de0c603f07c9e1820e812d2f1a73661843e6rbb if ((current->left == (struct parse_node *) NULL) ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (current->right == (struct parse_node *) NULL) ||
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb (current->left->token.type != token_string) ||
b79b743d4cff02d6a830bb7118826a2fd608742amartin (current->right->token.type != token_string)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
7463de0c603f07c9e1820e812d2f1a73661843e6rbb return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->left->token.value,
dd35ca20f76a5feada41afa296e1018d22de3805bjh NULL, MAX_STRING_LEN, 0);
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh current->left->token.value = buffer;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh buffer = ap_ssi_parse_string(r, ctx, current->right->token.value,
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh NULL, MAX_STRING_LEN, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value = buffer;
7463de0c603f07c9e1820e812d2f1a73661843e6rbb#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos],
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Compare (%s) with (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
6a07be8f4d69cf6936e340975cf8ec25c01774b9rbb current->value =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding strcmp(current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->right->token.value);
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb if (current->token.type == token_ge) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = current->value >= 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (current->token.type == token_gt) {
7463de0c603f07c9e1820e812d2f1a73661843e6rbb current->value = current->value > 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (current->token.type == token_le) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = current->value <= 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (current->token.type == token_lt) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh current->value = current->value < 0;
7463de0c603f07c9e1820e812d2f1a73661843e6rbb }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = 0; /* Don't return -1 if unknown token */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Returning %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value ? '1' : '0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_not:
53d96a3fd27f747396b3258047f889ab1179d1d0dgaudet if (current->right != (struct parse_node *) NULL) {
d96aa158770d3f83cb59cf0f2f7402e175f7dfccrbb if (!current->right->done) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->right;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = !current->right->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Evaluate !: %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value ? '1' : '0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
178381ebc820fb4c429aa000240cc8ec42c99c58trawick
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_group:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current->right != (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!current->right->done) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->right;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding continue;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = current->right->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = 1;
7463de0c603f07c9e1820e812d2f1a73661843e6rbb }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Evaluate (): %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value ? '1' : '0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->done = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current = current->parent;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding break;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_lbrace:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Unmatched '(' in \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding case token_rbrace:
6a07be8f4d69cf6936e340975cf8ec25c01774b9rbb ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Unmatched ')' in \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding expr, r->filename);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding default:
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "bad token type");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *was_error = 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return retval;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding }
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding retval = (root == (struct parse_node *) NULL) ? 0 : root->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (retval);
ebe70c2684539a5fb2d899241d1601710dfa38a4trawick}
ebe70c2684539a5fb2d899241d1601710dfa38a4trawick
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*-------------------------------------------------------------------------*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#ifdef DEBUG_INCLUDE
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define MAX_DEBUG_SIZE MAX_STRING_LEN
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define LOG_COND_STATUS(cntx, t_buck, h_ptr, ins_head, tag_text) \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding{ \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char cond_txt[] = "**** X conditional_status=\"0\"\n"; \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (cntx->flags & FLAG_COND_TRUE) { \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding cond_txt[31] = '1'; \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(&cond_txt[5], tag_text, sizeof(tag_text)-1); \
e68becff3c3ddc18723c9799b8cc2e6e9c3dbd66wrowe t_buck = apr_bucket_heap_create(cond_txt, sizeof(cond_txt)-1, \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding NULL, h_ptr->list); \
b859b5654eeba0b8995b7a46975121029cceda78fielding APR_BUCKET_INSERT_BEFORE(h_ptr, t_buck); \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (ins_head == NULL) { \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ins_head = t_buck; \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } \
b4c8a80f7dbfc9b56dbe03bdc28f0b5eb5f23697rbb}
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define DUMP_PARSE_EXPR_DEBUG(t_buck, h_ptr, d_buf, ins_head) \
b859b5654eeba0b8995b7a46975121029cceda78fielding{ \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (d_buf[0] != '\0') { \
t_buck = apr_bucket_heap_create(d_buf, strlen(d_buf), \
NULL, h_ptr->list); \
APR_BUCKET_INSERT_BEFORE(h_ptr, t_buck); \
\
if (ins_head == NULL) { \
ins_head = t_buck; \
} \
} \
}
#else
#define MAX_DEBUG_SIZE 10
#define LOG_COND_STATUS(cntx, t_buck, h_ptr, ins_head, tag_text)
#define DUMP_PARSE_EXPR_DEBUG(t_buck, h_ptr, d_buf, ins_head)
#endif
/*-------------------------------------------------------------------------*/
/* pjr - These seem to allow expr="fred" expr="joe" where joe overwrites fred. */
static int handle_if(include_ctx_t *ctx, apr_bucket_brigade **bb,
request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
apr_bucket **inserted_head)
{
char *tag = NULL;
char *tag_val = NULL;
char *expr = NULL;
int expr_ret, was_error, was_unmatched;
apr_bucket *tmp_buck;
char debug_buf[MAX_DEBUG_SIZE];
*inserted_head = NULL;
if (!ctx->flags & FLAG_PRINTING) {
ctx->if_nesting_level++;
}
else {
while (1) {
ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 0);
if (tag == NULL) {
if (expr == NULL) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"missing expr in if statement: %s",
r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
*inserted_head);
return 1;
}
expr_ret = parse_expr(r, ctx, expr, &was_error,
&was_unmatched, debug_buf);
if (was_error) {
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
*inserted_head);
return 1;
}
if (was_unmatched) {
DUMP_PARSE_EXPR_DEBUG(tmp_buck, head_ptr,
"\nUnmatched '\n", *inserted_head);
}
DUMP_PARSE_EXPR_DEBUG(tmp_buck, head_ptr, debug_buf,
*inserted_head);
if (expr_ret) {
ctx->flags |= (FLAG_PRINTING | FLAG_COND_TRUE);
}
else {
ctx->flags &= FLAG_CLEAR_PRINT_COND;
}
LOG_COND_STATUS(ctx, tmp_buck, head_ptr, *inserted_head,
" if");
ctx->if_nesting_level = 0;
return 0;
}
else if (!strcmp(tag, "expr")) {
expr = tag_val;
#ifdef DEBUG_INCLUDE
if (1) {
apr_size_t d_len = 0;
d_len = sprintf(debug_buf, "**** if expr=\"%s\"\n", expr);
tmp_buck = apr_bucket_heap_create(debug_buf, d_len, NULL,
r->connection->bucket_alloc);
APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);
if (*inserted_head == NULL) {
*inserted_head = tmp_buck;
}
}
#endif
}
else {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"unknown parameter \"%s\" to tag if in %s", tag,
r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
}
}
}
return 0;
}
static int handle_elif(include_ctx_t *ctx, apr_bucket_brigade **bb,
request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
apr_bucket **inserted_head)
{
char *tag = NULL;
char *tag_val = NULL;
char *expr = NULL;
int expr_ret, was_error, was_unmatched;
apr_bucket *tmp_buck;
char debug_buf[MAX_DEBUG_SIZE];
*inserted_head = NULL;
if (!ctx->if_nesting_level) {
while (1) {
ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 0);
if (tag == '\0') {
LOG_COND_STATUS(ctx, tmp_buck, head_ptr, *inserted_head,
" elif");
if (ctx->flags & FLAG_COND_TRUE) {
ctx->flags &= FLAG_CLEAR_PRINTING;
return (0);
}
if (expr == NULL) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"missing expr in elif statement: %s",
r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
*inserted_head);
return (1);
}
expr_ret = parse_expr(r, ctx, expr, &was_error,
&was_unmatched, debug_buf);
if (was_error) {
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
*inserted_head);
return 1;
}
if (was_unmatched) {
DUMP_PARSE_EXPR_DEBUG(tmp_buck, head_ptr,
"\nUnmatched '\n", *inserted_head);
}
DUMP_PARSE_EXPR_DEBUG(tmp_buck, head_ptr, debug_buf,
*inserted_head);
if (expr_ret) {
ctx->flags |= (FLAG_PRINTING | FLAG_COND_TRUE);
}
else {
ctx->flags &= FLAG_CLEAR_PRINT_COND;
}
LOG_COND_STATUS(ctx, tmp_buck, head_ptr, *inserted_head,
" elif");
return (0);
}
else if (!strcmp(tag, "expr")) {
expr = tag_val;
#ifdef DEBUG_INCLUDE
if (1) {
apr_size_t d_len = 0;
d_len = sprintf(debug_buf, "**** elif expr=\"%s\"\n", expr);
tmp_buck = apr_bucket_heap_create(debug_buf, d_len, NULL,
r->connection->bucket_alloc);
APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);
if (*inserted_head == NULL) {
*inserted_head = tmp_buck;
}
}
#endif
}
else {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"unknown parameter \"%s\" to tag if in %s", tag,
r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
}
}
}
return 0;
}
static int handle_else(include_ctx_t *ctx, apr_bucket_brigade **bb,
request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
apr_bucket **inserted_head)
{
char *tag = NULL;
char *tag_val = NULL;
apr_bucket *tmp_buck;
*inserted_head = NULL;
if (!ctx->if_nesting_level) {
ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
if ((tag != NULL) || (tag_val != NULL)) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"else directive does not take tags in %s", r->filename);
if (ctx->flags & FLAG_PRINTING) {
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
}
return -1;
}
else {
LOG_COND_STATUS(ctx, tmp_buck, head_ptr, *inserted_head, " else");
if (ctx->flags & FLAG_COND_TRUE) {
ctx->flags &= FLAG_CLEAR_PRINTING;
}
else {
ctx->flags |= (FLAG_PRINTING | FLAG_COND_TRUE);
}
return 0;
}
}
return 0;
}
static int handle_endif(include_ctx_t *ctx, apr_bucket_brigade **bb,
request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
apr_bucket **inserted_head)
{
char *tag = NULL;
char *tag_val = NULL;
apr_bucket *tmp_buck;
*inserted_head = NULL;
if (!ctx->if_nesting_level) {
ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
if ((tag != NULL) || (tag_val != NULL)) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"endif directive does not take tags in %s", r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
return -1;
}
else {
LOG_COND_STATUS(ctx, tmp_buck, head_ptr, *inserted_head, "endif");
ctx->flags |= (FLAG_PRINTING | FLAG_COND_TRUE);
return 0;
}
}
else {
ctx->if_nesting_level--;
return 0;
}
}
static int handle_set(include_ctx_t *ctx, apr_bucket_brigade **bb,
request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
apr_bucket **inserted_head)
{
char *tag = NULL;
char *tag_val = NULL;
char *var = NULL;
apr_bucket *tmp_buck;
char *parsed_string;
request_rec *sub = r->main;
apr_pool_t *p = r->pool;
/* we need to use the 'main' request pool to set notes as that is
* a notes lifetime
*/
while (sub) {
p = sub->pool;
sub = sub->main;
}
*inserted_head = NULL;
if (ctx->flags & FLAG_PRINTING) {
while (1) {
ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
if ((tag == NULL) && (tag_val == NULL)) {
return 0;
}
else if (tag_val == NULL) {
return 1;
}
else if (!strcmp(tag, "var")) {
var = ap_ssi_parse_string(r, ctx, tag_val, NULL,
MAX_STRING_LEN, 0);
}
else if (!strcmp(tag, "value")) {
if (var == (char *) NULL) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"variable must precede value in set directive in %s",
r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr,
*inserted_head);
return (-1);
}
parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
MAX_STRING_LEN, 0);
apr_table_setn(r->subprocess_env, apr_pstrdup(p, var),
apr_pstrdup(p, parsed_string));
}
else {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"Invalid tag for set directive in %s", r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
return -1;
}
}
}
return 0;
}
static int handle_printenv(include_ctx_t *ctx, apr_bucket_brigade **bb,
request_rec *r, ap_filter_t *f,
apr_bucket *head_ptr, apr_bucket **inserted_head)
{
char *tag = NULL;
char *tag_val = NULL;
apr_bucket *tmp_buck;
if (ctx->flags & FLAG_PRINTING) {
ap_ssi_get_tag_and_value(ctx, &tag, &tag_val, 1);
if ((tag == NULL) && (tag_val == NULL)) {
const apr_array_header_t *arr = apr_table_elts(r->subprocess_env);
const apr_table_entry_t *elts = (const apr_table_entry_t *)arr->elts;
int i;
const char *key_text, *val_text;
char *key_val, *next;
apr_size_t k_len, v_len, kv_length;
*inserted_head = NULL;
for (i = 0; i < arr->nelts; ++i) {
key_text = ap_escape_html(r->pool, elts[i].key);
val_text = elts[i].val;
if (val_text == LAZY_VALUE) {
val_text = add_include_vars_lazy(r, elts[i].key);
}
val_text = ap_escape_html(r->pool, elts[i].val);
k_len = strlen(key_text);
v_len = strlen(val_text);
kv_length = k_len + v_len + sizeof("=\n");
key_val = apr_palloc(r->pool, kv_length);
next = key_val;
memcpy(next, key_text, k_len);
next += k_len;
*next++ = '=';
memcpy(next, val_text, v_len);
next += v_len;
*next++ = '\n';
*next = 0;
tmp_buck = apr_bucket_pool_create(key_val, kv_length - 1,
r->pool,
r->connection->bucket_alloc);
APR_BUCKET_INSERT_BEFORE(head_ptr, tmp_buck);
if (*inserted_head == NULL) {
*inserted_head = tmp_buck;
}
}
return 0;
}
else {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"printenv directive does not take tags in %s",
r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
return -1;
}
}
return 0;
}
/* -------------------------- The main function --------------------------- */
static apr_status_t send_parsed_content(apr_bucket_brigade **bb,
request_rec *r, ap_filter_t *f)
{
include_ctx_t *ctx = f->ctx;
apr_bucket *dptr = APR_BRIGADE_FIRST(*bb);
apr_bucket *tmp_dptr;
apr_bucket_brigade *tag_and_after;
apr_status_t rv = APR_SUCCESS;
if (r->args) { /* add QUERY stuff to env cause it ain't yet */
char *arg_copy = apr_pstrdup(r->pool, r->args);
apr_table_setn(r->subprocess_env, "QUERY_STRING", r->args);
ap_unescape_url(arg_copy);
apr_table_setn(r->subprocess_env, "QUERY_STRING_UNESCAPED",
ap_escape_shell_cmd(r->pool, arg_copy));
}
while (dptr != APR_BRIGADE_SENTINEL(*bb) && !APR_BUCKET_IS_EOS(dptr)) {
/* State to check for the STARTING_SEQUENCE. */
if ((ctx->state == PRE_HEAD) || (ctx->state == PARSE_HEAD)) {
int do_cleanup = 0;
apr_size_t cleanup_bytes = ctx->parse_pos;
tmp_dptr = find_start_sequence(dptr, ctx, *bb, &do_cleanup);
if (!APR_STATUS_IS_SUCCESS(ctx->status)) {
return ctx->status;
}
/* The few bytes stored in the ssi_tag_brigade turned out not to
* be a tag after all. This can only happen if the starting
* tag actually spans brigades. This should be very rare.
*/
if ((do_cleanup) && (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade))) {
apr_bucket *tmp_bkt;
tmp_bkt = apr_bucket_immortal_create(ctx->start_seq,
cleanup_bytes,
r->connection->bucket_alloc);
APR_BRIGADE_INSERT_HEAD(*bb, tmp_bkt);
apr_brigade_cleanup(ctx->ssi_tag_brigade);
}
/* If I am inside a conditional (if, elif, else) that is false
* then I need to throw away anything contained in it.
*/
if ((!(ctx->flags & FLAG_PRINTING)) && (tmp_dptr != NULL) &&
(dptr != APR_BRIGADE_SENTINEL(*bb))) {
while ((dptr != APR_BRIGADE_SENTINEL(*bb)) &&
(dptr != tmp_dptr)) {
apr_bucket *free_bucket = dptr;
dptr = APR_BUCKET_NEXT (dptr);
apr_bucket_delete(free_bucket);
}
}
/* Adjust the current bucket position based on what was found... */
if ((tmp_dptr != NULL) && (ctx->state == PARSE_DIRECTIVE)) {
if (ctx->tag_start_bucket != NULL) {
dptr = ctx->tag_start_bucket;
}
else {
dptr = APR_BRIGADE_SENTINEL(*bb);
}
}
else if ((tmp_dptr != NULL) &&
(ctx->output_now ||
(ctx->bytes_parsed >= BYTE_COUNT_THRESHOLD))) {
/* Send the large chunk of pre-tag bytes... */
tag_and_after = apr_brigade_split(*bb, tmp_dptr);
if (ctx->output_flush) {
APR_BRIGADE_INSERT_TAIL(*bb, apr_bucket_flush_create((*bb)->bucket_alloc));
}
rv = ap_pass_brigade(f->next, *bb);
if (rv != APR_SUCCESS) {
return rv;
}
*bb = tag_and_after;
dptr = tmp_dptr;
ctx->output_flush = 0;
ctx->bytes_parsed = 0;
ctx->output_now = 0;
}
else if (tmp_dptr == NULL) {
/* There was no possible SSI tag in the
* remainder of this brigade... */
dptr = APR_BRIGADE_SENTINEL(*bb);
}
}
/* State to check for the ENDING_SEQUENCE. */
if (((ctx->state == PARSE_DIRECTIVE) ||
(ctx->state == PARSE_TAG) ||
(ctx->state == PARSE_TAIL)) &&
(dptr != APR_BRIGADE_SENTINEL(*bb))) {
tmp_dptr = find_end_sequence(dptr, ctx, *bb);
if (!APR_STATUS_IS_SUCCESS(ctx->status)) {
return ctx->status;
}
if (tmp_dptr != NULL) {
dptr = tmp_dptr; /* Adjust bucket pos... */
/* If some of the tag has already been set aside then set
* aside remainder of tag. Now the full tag is in
* ssi_tag_brigade.
* If none has yet been set aside, then leave it all where it
* is.
* In any event after this the entire set of tag buckets will
* be in one place or another.
*/
if (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
tag_and_after = apr_brigade_split(*bb, dptr);
APR_BRIGADE_CONCAT(ctx->ssi_tag_brigade, *bb);
*bb = tag_and_after;
}
else if (ctx->output_now ||
(ctx->bytes_parsed >= BYTE_COUNT_THRESHOLD)) {
SPLIT_AND_PASS_PRETAG_BUCKETS(*bb, ctx, f->next, rv);
if (rv != APR_SUCCESS) {
return rv;
}
ctx->output_flush = 0;
ctx->output_now = 0;
}
}
else {
/* remainder of this brigade... */
dptr = APR_BRIGADE_SENTINEL(*bb);
}
}
/* State to processed the directive... */
if (ctx->state == PARSED) {
apr_bucket *content_head = NULL, *tmp_bkt;
apr_size_t tmp_i;
char tmp_buf[TMP_BUF_SIZE];
int (*handle_func)(include_ctx_t *, apr_bucket_brigade **,
request_rec *, ap_filter_t *, apr_bucket *,
apr_bucket **);
/* By now the full tag (all buckets) should either be set aside into
* ssi_tag_brigade or contained within the current bb. All tag
* processing from here on can assume that.
*/
/* At this point, everything between ctx->head_start_bucket and
* ctx->tail_start_bucket is an SSI
* directive, we just have to deal with it now.
*/
if (get_combined_directive(ctx, r, *bb, tmp_buf,
TMP_BUF_SIZE) != APR_SUCCESS) {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"mod_include: error copying directive in %s",
r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_bkt, dptr, content_head);
/* DO CLEANUP HERE!!!!! */
tmp_dptr = ctx->head_start_bucket;
if (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
apr_brigade_cleanup(ctx->ssi_tag_brigade);
}
else {
do {
tmp_bkt = tmp_dptr;
tmp_dptr = APR_BUCKET_NEXT (tmp_dptr);
apr_bucket_delete(tmp_bkt);
} while ((tmp_dptr != dptr) &&
(tmp_dptr != APR_BRIGADE_SENTINEL(*bb)));
}
return APR_SUCCESS;
}
/* Can't destroy the tag buckets until I'm done processing
* because the combined_tag might just be pointing to
* the contents of a single bucket!
*/
/* Retrieve the handler function to be called for this directive
* from the functions registered in the hash table.
* Need to lower case the directive for proper matching. Also need
* to have it NULL terminated for proper hash matching.
*/
for (tmp_i = 0; tmp_i < ctx->directive_length; tmp_i++) {
ctx->combined_tag[tmp_i] =
apr_tolower(ctx->combined_tag[tmp_i]);
}
ctx->combined_tag[ctx->directive_length] = '\0';
ctx->curr_tag_pos = &ctx->combined_tag[ctx->directive_length+1];
handle_func =
(include_handler_fn_t *)apr_hash_get(include_hash,
ctx->combined_tag,
ctx->directive_length);
if (handle_func != NULL) {
rv = (*handle_func)(ctx, bb, r, f, dptr, &content_head);
if ((rv != 0) && (rv != 1)) {
return (rv);
}
}
else {
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"unknown directive \"%s\" in parsed doc %s",
ctx->combined_tag, r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_bkt, dptr, content_head);
}
/* This chunk of code starts at the first bucket in the chain
* of tag buckets (assuming that by this point the bucket for
* the STARTING_SEQUENCE has been split) and loops through to
* the end of the tag buckets freeing them all.
*
* Remember that some part of this may have been set aside
* into the ssi_tag_brigade and the remainder (possibly as
* little as one byte) will be in the current brigade.
*
* The value of dptr should have been set during the
* PARSE_TAIL state to the first bucket after the
* ENDING_SEQUENCE.
*
* The value of content_head may have been set during processing
* of the directive. If so, the content was inserted in front
* of the dptr bucket. The inserted buckets should not be thrown
* away here, but they should also not be parsed later.
*/
if (content_head == NULL) {
content_head = dptr;
}
tmp_dptr = ctx->head_start_bucket;
if (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
apr_brigade_cleanup(ctx->ssi_tag_brigade);
}
else {
do {
tmp_bkt = tmp_dptr;
tmp_dptr = APR_BUCKET_NEXT (tmp_dptr);
apr_bucket_delete(tmp_bkt);
} while ((tmp_dptr != content_head) &&
(tmp_dptr != APR_BRIGADE_SENTINEL(*bb)));
}
if (ctx->combined_tag == tmp_buf) {
ctx->combined_tag = NULL;
}
/* Don't reset the flags or the nesting level!!! */
ctx->parse_pos = 0;
ctx->head_start_bucket = NULL;
ctx->head_start_index = 0;
ctx->tag_start_bucket = NULL;
ctx->tag_start_index = 0;
ctx->tail_start_bucket = NULL;
ctx->tail_start_index = 0;
ctx->curr_tag_pos = NULL;
ctx->tag_length = 0;
ctx->directive_length = 0;
if (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
apr_brigade_cleanup(ctx->ssi_tag_brigade);
}
ctx->state = PRE_HEAD;
}
}
/* We have nothing more to send, stop now. */
if (dptr != APR_BRIGADE_SENTINEL(*bb) &&
APR_BUCKET_IS_EOS(dptr)) {
/* We might have something saved that we never completed, but send
* down unparsed. This allows for <!-- at the end of files to be
* sent correctly. */
if (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
APR_BRIGADE_CONCAT(ctx->ssi_tag_brigade, *bb);
return ap_pass_brigade(f->next, ctx->ssi_tag_brigade);
}
return ap_pass_brigade(f->next, *bb);
}
/* If I am in the middle of parsing an SSI tag then I need to set aside
* the pertinent trailing buckets and pass on the initial part of the
* brigade. The pertinent parts of the next brigades will be added to
* these set aside buckets to form the whole tag and will be processed
* once the whole tag has been found.
*/
if (ctx->state == PRE_HEAD) {
/* Inside a false conditional (if, elif, else), so toss it all... */
if ((dptr != APR_BRIGADE_SENTINEL(*bb)) &&
(!(ctx->flags & FLAG_PRINTING))) {
apr_bucket *free_bucket;
do {
free_bucket = dptr;
dptr = APR_BUCKET_NEXT (dptr);
apr_bucket_delete(free_bucket);
} while (dptr != APR_BRIGADE_SENTINEL(*bb));
}
else {
/* Otherwise pass it along...
* No SSI tags in this brigade... */
rv = ap_pass_brigade(f->next, *bb);
if (rv != APR_SUCCESS) {
return rv;
}
ctx->bytes_parsed = 0;
}
}
else if (ctx->state == PARSED) { /* Invalid internal condition... */
apr_bucket *content_head = NULL, *tmp_bkt;
ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
"Invalid mod_include state during file %s", r->filename);
CREATE_ERROR_BUCKET(ctx, tmp_bkt, APR_BRIGADE_FIRST(*bb), content_head);
}
else { /* Entire brigade is middle chunk of SSI tag... */
if (!APR_BRIGADE_EMPTY(ctx->ssi_tag_brigade)) {
APR_BRIGADE_CONCAT(ctx->ssi_tag_brigade, *bb);
}
else { /* End of brigade contains part of SSI tag... */
if (ctx->head_start_index > 0) {
apr_bucket_split(ctx->head_start_bucket, ctx->head_start_index);
ctx->head_start_bucket =
APR_BUCKET_NEXT(ctx->head_start_bucket);
ctx->head_start_index = 0;
}
/* Set aside tag, pass pre-tag... */
tag_and_after = apr_brigade_split(*bb, ctx->head_start_bucket);
ap_save_brigade(f, &ctx->ssi_tag_brigade, &tag_and_after, r->pool);
rv = ap_pass_brigade(f->next, *bb);
if (rv != APR_SUCCESS) {
return rv;
}
ctx->bytes_parsed = 0;
}
}
return APR_SUCCESS;
}
static void *create_includes_dir_config(apr_pool_t *p, char *dummy)
{
include_dir_config *result =
(include_dir_config *)apr_palloc(p, sizeof(include_dir_config));
enum xbithack *xbh = (enum xbithack *) apr_palloc(p, sizeof(enum xbithack));
*xbh = DEFAULT_XBITHACK;
result->default_error_msg = DEFAULT_ERROR_MSG;
result->default_time_fmt = DEFAULT_TIME_FORMAT;
result->xbithack = xbh;
return result;
}
static void *create_includes_server_config(apr_pool_t*p, server_rec *server)
{
include_server_config *result =
(include_server_config *)apr_palloc(p, sizeof(include_server_config));
result->default_end_tag = ENDING_SEQUENCE;
result->default_start_tag =STARTING_SEQUENCE;
result->start_tag_len = sizeof(STARTING_SEQUENCE)-1;
/* compile the pattern used by find_start_sequence */
bndm_compile(&result->start_seq_pat, result->default_start_tag,
result->start_tag_len);
result->undefinedEcho = apr_pstrdup(p,"(none)");
result->undefinedEchoLen = strlen( result->undefinedEcho);
return result;
}
static const char *set_xbithack(cmd_parms *cmd, void *xbp, const char *arg)
{
include_dir_config *conf = (include_dir_config *)xbp;
if (!strcasecmp(arg, "off")) {
*conf->xbithack = xbithack_off;
}
else if (!strcasecmp(arg, "on")) {
*conf->xbithack = xbithack_on;
}
else if (!strcasecmp(arg, "full")) {
*conf->xbithack = xbithack_full;
}
else {
return "XBitHack must be set to Off, On, or Full";
}
return NULL;
}
static apr_status_t includes_filter(ap_filter_t *f, apr_bucket_brigade *b)
{
request_rec *r = f->r;
include_ctx_t *ctx = f->ctx;
request_rec *parent;
include_dir_config *conf =
(include_dir_config *)ap_get_module_config(r->per_dir_config,
&include_module);
include_server_config *sconf= ap_get_module_config(r->server->module_config,
&include_module);
if (!(ap_allow_options(r) & OPT_INCLUDES)) {
return ap_pass_brigade(f->next, b);
}
if (!f->ctx) {
f->ctx = ctx = apr_pcalloc(f->c->pool, sizeof(*ctx));
ctx->state = PRE_HEAD;
ctx->flags = (FLAG_PRINTING | FLAG_COND_TRUE);
if (ap_allow_options(r) & OPT_INCNOEXEC) {
ctx->flags |= FLAG_NO_EXEC;
}
ctx->ssi_tag_brigade = apr_brigade_create(f->c->pool,
f->c->bucket_alloc);
ctx->status = APR_SUCCESS;
ctx->error_str = conf->default_error_msg;
ctx->time_str = conf->default_time_fmt;
ctx->pool = f->c->pool;
ctx->start_seq_pat = &sconf->start_seq_pat;
ctx->start_seq = sconf->default_start_tag;
ctx->start_seq_len = sconf->start_tag_len;
ctx->end_seq = sconf->default_end_tag;
}
else {
ctx->bytes_parsed = 0;
}
if ((parent = ap_get_module_config(r->request_config, &include_module))) {
/* 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 -->.
*/
r->subprocess_env = r->main->subprocess_env;
apr_pool_join(r->main->pool, r->pool);
r->finfo.mtime = r->main->finfo.mtime;
}
else {
/* we're not a nested include, so we create an initial
* environment */
ap_add_common_vars(r);
ap_add_cgi_vars(r);
add_include_vars(r, conf->default_time_fmt);
}
/* XXX: this is bogus, at some point we're going to do a subrequest,
* and when we do it we're going to be subjecting code that doesn't
* expect to be signal-ready to SIGALRM. There is no clean way to
* fix this, except to put alarm support into BUFF. -djg
*/
/* 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.
*/
apr_table_unset(f->r->headers_out, "Content-Length");
/* Always unset the ETag/Last-Modified fields - 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.
*/
apr_table_unset(f->r->headers_out, "ETag");
/* Assure the platform supports Group protections */
if ((*conf->xbithack == xbithack_full)
&& (r->finfo.valid & APR_FINFO_GPROT)
&& (r->finfo.protection & APR_GEXECUTE)) {
ap_update_mtime(r, r->finfo.mtime);
ap_set_last_modified(r);
}
else {
apr_table_unset(f->r->headers_out, "Last-Modified");
}
return send_parsed_content(&b, r, f);
}
static void ap_register_include_handler(char *tag, include_handler_fn_t *func)
{
apr_hash_set(include_hash, tag, strlen(tag), (const void *)func);
}
static int include_post_config(apr_pool_t *p, apr_pool_t *plog,
apr_pool_t *ptemp, server_rec *s)
{
include_hash = apr_hash_make(p);
ssi_pfn_register = APR_RETRIEVE_OPTIONAL_FN(ap_register_include_handler);
if(ssi_pfn_register) {
ssi_pfn_register("if", handle_if);
ssi_pfn_register("set", handle_set);
ssi_pfn_register("else", handle_else);
ssi_pfn_register("elif", handle_elif);
ssi_pfn_register("echo", handle_echo);
ssi_pfn_register("endif", handle_endif);
ssi_pfn_register("fsize", handle_fsize);
ssi_pfn_register("config", handle_config);
ssi_pfn_register("include", handle_include);
ssi_pfn_register("flastmod", handle_flastmod);
ssi_pfn_register("printenv", handle_printenv);
}
return OK;
}
static const char *set_default_error_msg(cmd_parms *cmd, void *mconfig, const char *msg)
{
include_dir_config *conf = (include_dir_config *)mconfig;
conf->default_error_msg = apr_pstrdup(cmd->pool, msg);
return NULL;
}
static const char *set_default_start_tag(cmd_parms *cmd, void *mconfig, const char *msg)
{
include_server_config *conf;
conf= ap_get_module_config(cmd->server->module_config , &include_module);
conf->default_start_tag = apr_pstrdup(cmd->pool, msg);
conf->start_tag_len = strlen(conf->default_start_tag );
bndm_compile(&conf->start_seq_pat, conf->default_start_tag,
conf->start_tag_len);
return NULL;
}
static const char *set_undefined_echo(cmd_parms *cmd, void *mconfig, const char *msg)
{
include_server_config *conf;
conf = ap_get_module_config(cmd->server->module_config, &include_module);
conf->undefinedEcho = apr_pstrdup(cmd->pool, msg);
conf->undefinedEchoLen = strlen(msg);
return NULL;
}
static const char *set_default_end_tag(cmd_parms *cmd, void *mconfig, const char *msg)
{
include_server_config *conf;
conf= ap_get_module_config(cmd->server->module_config , &include_module);
conf->default_end_tag = apr_pstrdup(cmd->pool, msg);
return NULL;
}
static const char *set_default_time_fmt(cmd_parms *cmd, void *mconfig, const char *fmt)
{
include_dir_config *conf = (include_dir_config *)mconfig;
conf->default_time_fmt = apr_pstrdup(cmd->pool, fmt);
return NULL;
}
/*
* Module definition and configuration data structs...
*/
static const command_rec includes_cmds[] =
{
AP_INIT_TAKE1("XBitHack", set_xbithack, NULL, OR_OPTIONS,
"Off, On, or Full"),
AP_INIT_TAKE1("SSIErrorMsg", set_default_error_msg, NULL, OR_ALL,
"a string"),
AP_INIT_TAKE1("SSITimeFormat", set_default_time_fmt, NULL, OR_ALL,
"a strftime(3) formatted string"),
AP_INIT_TAKE1("SSIStartTag", set_default_start_tag, NULL, RSRC_CONF,
"SSI Start String Tag"),
AP_INIT_TAKE1("SSIEndTag", set_default_end_tag, NULL, RSRC_CONF,
"SSI End String Tag"),
AP_INIT_TAKE1("SSIUndefinedEcho", set_undefined_echo, NULL, RSRC_CONF,
"SSI Start String Tag"),
{NULL}
};
static int include_fixup(request_rec *r)
{
include_dir_config *conf;
conf = (include_dir_config *) ap_get_module_config(r->per_dir_config,
&include_module);
if (r->handler && (strcmp(r->handler, "server-parsed") == 0))
{
if (!r->content_type || !*r->content_type) {
ap_set_content_type(r, "text/html");
}
r->handler = "default-handler";
}
else
#if defined(OS2) || defined(WIN32) || defined(NETWARE)
/* These OS's don't support xbithack. This is being worked on. */
{
return DECLINED;
}
#else
{
if (*conf->xbithack == xbithack_off) {
return DECLINED;
}
if (!(r->finfo.protection & APR_UEXECUTE)) {
return DECLINED;
}
if (!r->content_type || strcmp(r->content_type, "text/html")) {
return DECLINED;
}
}
#endif
/* We always return declined, because the default handler actually
* serves the file. All we have to do is add the filter.
*/
ap_add_output_filter("INCLUDES", NULL, r, r->connection);
return DECLINED;
}
static void register_hooks(apr_pool_t *p)
{
APR_REGISTER_OPTIONAL_FN(ap_ssi_get_tag_and_value);
APR_REGISTER_OPTIONAL_FN(ap_ssi_parse_string);
APR_REGISTER_OPTIONAL_FN(ap_register_include_handler);
ap_hook_post_config(include_post_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
ap_hook_fixups(include_fixup, NULL, NULL, APR_HOOK_LAST);
ap_register_output_filter("INCLUDES", includes_filter, AP_FTYPE_RESOURCE);
}
module AP_MODULE_DECLARE_DATA include_module =
{
STANDARD20_MODULE_STUFF,
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 */
};