mod_include.c revision 74f1cb282d1418f9eaaf86524a6d447c3a5209d1
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* ====================================================================
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * The Apache Software License, Version 1.1
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * reserved.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Redistribution and use in source and binary forms, with or without
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * modification, are permitted provided that the following conditions
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * 1. Redistributions of source code must retain the above copyright
ab2c1c1c83ec91415565da5a71fbc15d9685caa6fielding * notice, this list of conditions and the following disclaimer.
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.
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.
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.
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.
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 * 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 * 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 * http_include.c: Handles the server-parsed HTML documents
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Original by Rob McCool; substantial fixups by David Robinson;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * incorporated into the Apache module framework by rst.
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic APR_OPTIONAL_FN_TYPE(ap_register_include_handler) *ssi_pfn_register;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*****************************************************************
48d7c43629323c8d5ee9f7bd0d194de0a376b391rbb * XBITHACK. Sigh... NB it's configurable per-directory; the compile-time
8f3ec4772d2aeb347cf40e87c77627bb784dd018rbb * option only changes the default.
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard unsigned int T[256];
178381ebc820fb4c429aa000240cc8ec42c99c58trawick unsigned int x;
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingtypedef struct {
178381ebc820fb4c429aa000240cc8ec42c99c58trawicktypedef struct {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* ------------------------ Environment function -------------------------- */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Sentinel value to store in subprocess_env for items that
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * shouldn't be evaluated until/unless they're actually used
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char lazy_eval_sentinel;
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void add_include_vars(request_rec *r, char *timefmt)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(e, "DOCUMENT_PATH_INFO", r->path_info);
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char *add_include_vars_lazy(request_rec *r, const char *var)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (include_dir_config *)ap_get_module_config(r->per_dir_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = ap_ht_time(r->pool, r->request_time, conf->default_time_fmt, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (include_dir_config *)ap_get_module_config(r->per_dir_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = ap_ht_time(r->pool, r->request_time, conf->default_time_fmt, 1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (include_dir_config *)ap_get_module_config(r->per_dir_config,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding val = ap_ht_time(r->pool, r->finfo.mtime, conf->default_time_fmt, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (apr_get_username(&val, r->finfo.user, r->pool) != APR_SUCCESS) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char *get_include_var(request_rec *r, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *var)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *val;
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/* --------------------------- Parser functions --------------------------- */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* This is an implementation of the BNDM search algorithm.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Fast and Flexible String Matching by Combining Bit-parallelism and
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Suffix Automata (2001)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Gonzalo Navarro, Mathieu Raffinot
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * http://www-igm.univ-mlv.fr/~raffinot/ftp/jea2001.ps.gz
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Initial code submitted by Sascha Schumann.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* Precompile the bndm_t data structure. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void bndm_compile(bndm_t *t, const char *n, apr_size_t nl)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding unsigned int x;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh t->T[(unsigned char) *n++] |= x;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh t->x = x - 1;
407cde44becba3694e7c3d81ac99b5d86f4b03a9rbb/* Implements the BNDM search algorithm (as described above).
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 * Returns the count of character that is the first match or hl if no
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * match is found.
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_size_t bndm(const char *n, apr_size_t nl, const char *h,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *skip;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding unsigned int *T, x, d;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding p = pi + nl; /* compare window right to left. point to the first char */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (p < he) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding d &= T[(unsigned char) *p--];
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((d & 1)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return p - h + 1;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } while (d);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* We've now found a start sequence tag... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_bucket* found_start_sequence(apr_bucket *dptr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* We want to split the bucket at the '<'. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Don't set tag_start_bucket if tagStart indexes the end of the bucket. */
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 /* If it was a one bucket match */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((tagStart < len) && (dptr == ctx->head_start_bucket)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->tag_start_index = tagStart - ctx->head_start_index;
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.
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_bucket *find_start_sequence(apr_bucket *dptr, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX the bucket flush support is commented out for now
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * because it was causing a segfault */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif /* 0 */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_NONBLOCK_READ);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_split(start_bucket, ctx->head_start_index);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_BLOCK_READ);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Set our buffer to use. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* The last bucket had a left over partial match that we need to
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * complete.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (c < buf + tmpLen && *c == str[ctx->parse_pos])
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return found_start_sequence(dptr, ctx, c - buf, len);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* False alarm...
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 return found_start_sequence(dptr, ctx, pos + slen, len);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Consider the case where we have <!-- at the end of the bucket. */
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.
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_bucket *find_end_sequence(apr_bucket *dptr, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *buf;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *start;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX the bucket flush support is commented out for now
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * because it was causing a segfault */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#endif /* 0 */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_NONBLOCK_READ);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* gonna start over parsing the directive next time through */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rv = apr_bucket_read(dptr, &buf, &len, APR_BLOCK_READ);
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 const char *tmp = c;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *tmp = c;
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 if (*c == str[0]) {
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).
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic apr_status_t get_combined_directive (include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *tmp_from;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* If the tag length is longer than the tmp buffer, allocate space. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding } /* Else, just use the temp buffer. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Prime the pump. Start at the beginning of the tag... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Read the bucket... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_read (dptr, &tmp_from, &tmp_from_len, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Adjust the pointer to start at the tag within the bucket... */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_from_len -= (tmp_from_len - ctx->tail_start_index);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Loop through the buckets from the tag_start_bucket until before
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * the tail_start_bucket copying the contents into the buffer.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy (ctx->curr_tag_pos, tmp_from, tmp_from_len);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_bucket_read (dptr, &tmp_from, &tmp_from_len, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Adjust the count to stop at the beginning of the tail. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_from_len -= (tmp_from_len - ctx->tail_start_index);
b79b743d4cff02d6a830bb7118826a2fd608742amartin } while ((!done) &&
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (ctx->curr_tag_pos < ctx->combined_tag + ctx->tag_length));
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, � will not be decoded, but will be deleted.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* maximum length of any ISO-LATIN-1 HTML entity name. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* The following is a shrinking transformation, therefore safe. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic void decodehtml(char *s)
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *ents;
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh "quot\042Auml\304Euml\313Iuml\317Ouml\326Uuml\334auml\344euml\353\
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh "Acirc\302Aring\305AElig\306Ecirc\312Icirc\316Ocirc\324Ucirc\333\
66d349e02d1a5a599a01c977d2c5b0009181f7debenTHORN\336szlig\337acirc\342aring\345aelig\346ecirc\352icirc\356ocirc\364\
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 /* Do a fast scan through the string until we find anything
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh * that needs more complicated handling
23cfa61aaed581f103070c8733a493b31f990f9brbb for (; *s != '&'; s++) {
23cfa61aaed581f103070c8733a493b31f990f9brbb if (*s == '\0') {
23cfa61aaed581f103070c8733a493b31f990f9brbb for (p = s; *s != '\0'; s++, p++) {
23cfa61aaed581f103070c8733a493b31f990f9brbb if (*s != '&') {
23cfa61aaed581f103070c8733a493b31f990f9brbb /* find end of entity */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh /* is it numeric ? */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh p--; /* no data to output */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh /* wrong length */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh continue; /* skip it */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *p = RAW_ASCII_CHAR(((const unsigned char *) ents)[j]);
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..
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh * [WS]<Tag>[WS]=[WS]['|"|`]<Value>[['|"|`|]|WS]
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh#define SKIP_TAG_WHITESPACE(ptr) while ((*ptr != '\0') && (apr_isspace (*ptr))) ptr++
b1476ba063e6d9577cd86db3db5dd98ff6bc78b9rbbstatic void ap_ssi_get_tag_and_value(include_ctx_t *ctx, char **tag,
14552184cfa95bd49b274b434390cc5195e8375crbb if (ctx->curr_tag_pos > ctx->combined_tag + ctx->tag_length) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *tag = c; /* First non-whitespace character (could be NULL). */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh while (apr_islower(*c)) {
23cfa61aaed581f103070c8733a493b31f990f9brbb c++; /* Optimization for the common case where the tag */
829bc6b670c7be394ccd33886add7ac39e276976trawick } /* is already lowercase */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while ((*c != '=') && (!apr_isspace(*c)) && (*c != '\0')) {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *c = apr_tolower(*c); /* find end of tag, lowercasing as we go... */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh return; /* We have found the end of the buffer. */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh } /* We might have a tag, but definitely no value. */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh if (*c == '=') {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh *c++ = '\0'; /* Overwrite the '=' with a terminating byte after tag. */
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh else { /* Try skipping WS to find the '='. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* There needs to be an equal sign if there's a value. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c != '=') {
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh return; /* There apparently was no value. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding c++; /* Skip the equals sign. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Allow quoted values for space inclusion.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * NOTE: This does not pass the quotes on return.
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 if (*c == '\\') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Accept \" (or ' or `) as valid quotation of string.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == '\\') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Overwrite the "\" during the embedded
b79b743d4cff02d6a830bb7118826a2fd608742amartin * escape sequence of '"'. "\'" or '`'.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Shift bytes from here to next delimiter.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == term) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (*c == '\0') {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding *(c-shift_val) = '\0'; /* Overwrites delimiter (term or WS) with NULL. */
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim/* initial buffer size for power-of-two allocator in ap_ssi_parse_string */
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)
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic char *ap_ssi_parse_string(request_rec *r, include_ctx_t *ctx,
3a9bc6532fbe8439fc748d8ffedb87415904d16ajim /* allocate an output buffer if needed */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* leave room for nul terminator */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* double the buffer size */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* truncated */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* guess that the expansion won't happen */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding 0, r, "Missing '}' on variable \"%s\"",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* what a pain, too bad there's no table_getn where you can
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * pass a non-nul terminated string */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (l != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* no expansion to be done */
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard /* zero-length variable name causes just the $ to be
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * copied */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* increase the buffer size to accommodate l more chars */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding l = ((int)l > end_out - next) ? (end_out - next) : l;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* double the buffer size */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* truncated */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* --------------------------- Action handlers ---------------------------- */
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 /* If the name is canonical this is redundant
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * but in security, redundancy is worthwhile.
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * Does OS2 belong here (accepts ... for ..)?
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (dots > 1 && (!path[dots] || path[dots] == '/'))
9274c5e05fbb6b9890099c0c20aa35d747d42be1stoddard if (dots == 2 && (!path[dots] || 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
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 while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (1);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!strcmp(tag, "virtual") || !strcmp(tag, "file")) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding SPLIT_AND_PASS_PRETAG_BUCKETS(*bb, ctx, f->next, rc);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX: Port to apr_filepath_merge
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * be safe; only files in this directory or below allowed
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rr = ap_sub_req_lookup_file(parsed_string, r, f->next);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding rr = ap_sub_req_lookup_uri(parsed_string, r, f->next);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to include \"%s\" in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to include potential exec \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
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 * 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 * 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 for (p = r; p != NULL && !founddupe; p = p->main) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (p != NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
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 error_fmt = "unable to include \"%s\" in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* destroy the sub request */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" to tag include in %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
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 while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *val =
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_pool_create(echo_text, e_len,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_pool_create(sconf->undefinedEcho,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcasecmp(tag_val, "url")) encode = E_URL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding else if (!strcasecmp(tag_val, "entity")) encode = E_ENTITY;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown value \"%s\" to parameter \"encoding\" of "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" in tag echo of %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
404e2e1f8ad30c2d996f5fb6b3a9a4a4a14a004brbb/* error and tf must point to a string with room for at
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * least MAX_STRING_LEN characters
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 while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return 0; /* Reached the end of the string. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->error_str_override = (char *)apr_palloc(ctx->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_parse_string(r, ctx, tag_val, ctx->error_str_override,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->time_str_override = (char *)apr_palloc(ctx->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_ssi_parse_string(r, ctx, tag_val, ctx->time_str_override,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(env, "DATE_LOCAL", ap_ht_time(r->pool, date,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding apr_table_setn(env, "DATE_GMT", ap_ht_time(r->pool, date,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" to tag config in %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding CREATE_ERROR_BUCKET(ctx, tmp_buck, head_ptr, *inserted_head);
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int find_file(request_rec *r, const char *directive, const char *tag,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* XXX: Port to apr_filepath_merge
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * be safe; only files in this directory or below allowed
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_getparents(tag_val); /* get rid of any nasties */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* note: it is okay to pass NULL for the "next filter" since
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding we never attempt to "run" this sub request. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr->status == HTTP_OK && rr->finfo.filetype != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding APR_FINFO_GPROT | APR_FINFO_MIN, rr->pool)) != APR_SUCCESS
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to get information about \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding error_fmt = "unable to lookup information about \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s";
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_ERR | (rv ? 0 : APLOG_NOERRNO),
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* note: it is okay to pass NULL for the "next filter" since
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding we never attempt to "run" this sub request. */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (rr->status == HTTP_OK && rr->finfo.filetype != 0) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unable to get information about \"%s\" "
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "in parsed file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "unknown parameter \"%s\" to tag %s in %s",
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 while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
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 int l, x, pos = 0;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding for (x = 0; x < l; x++) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (x && (!((l - x) % 3))) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_heap_create(buff, s_len, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int handle_flastmod(include_ctx_t *ctx, apr_bucket_brigade **bb,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding parsed_string = ap_ssi_parse_string(r, ctx, tag_val, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (!find_file(r, "flastmod", tag, parsed_string, &finfo)) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding t_val = ap_ht_time(r->pool, finfo.mtime, ctx->time_str, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding tmp_buck = apr_bucket_pool_create(t_val, t_len, r->pool,
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int re_check(request_rec *r, include_ctx_t *ctx,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const apr_size_t nres = sizeof(*ctx->re_result) / sizeof(regmatch_t);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding compiled = ap_pregcomp(r->pool, rexp, REG_EXTENDED | REG_NOSUB);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ctx->re_result = apr_pcalloc(r->pool, sizeof(*ctx->re_result));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding regex_error = ap_regexec(compiled, string, nres, *ctx->re_result, 0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding token_and, token_or, token_not, token_eq, token_ne,
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic const char *get_ptoken(request_rec *r, const char *string,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Skip leading white space */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (char *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (char *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* already token->type == token_string */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* already token->type == token_string */
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 * 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 for (ch = *string; ((ch != '\0') && (!tkn_fnd)); ch = *++string) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* If qs is still set, we have an unmatched quote */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/* there is an implicit assumption here that expr is at most MAX_STRING_LEN-1
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding * characters long...
0f081398cf0eef8cc7c66a535d450110a92dc8aefieldingstatic int parse_expr(request_rec *r, include_ctx_t *ctx, const char *expr,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding const char *parse;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding return (0);
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Create Parse Tree */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding while (1) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(struct parse_node));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding new->parent = new->left = new->right = (struct parse_node *) NULL;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((parse = get_ptoken(r, parse, &new->token, was_unmatched)) ==
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding (char *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Token: string (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Token: regex (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Token: and/or\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Percolate upwards */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(" Token: not\n"));
b79b743d4cff02d6a830bb7118826a2fd608742amartin /* Percolate upwards */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding memcpy(&debug[debug_pos], " Token: eq/ne/ge/gt/le/lt\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sizeof(" Token: eq/ne/ge/gt/le/lt\n");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Percolate upwards */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh sizeof (" Token: rbrace\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Unmatched ')' in \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Token: lbrace\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Percolate upwards */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding /* Evaluate Parse Tree */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Evaluate string\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->token.value, NULL,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = (current->token.value[0] != '\0');
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "No operator before regex of expr \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof(" Evaluate and/or\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->right->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Left: %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Right: %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = current->left->value && current->right->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = current->left->value || current->right->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Returning %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding sizeof (" Evaluate eq/ne\n"));
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if ((current->left == (struct parse_node *) NULL) ||
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->left->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->right->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Re Compare (%s) with /%s/\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Compare (%s) with (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Returning %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Invalid expression \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding buffer = ap_ssi_parse_string(r, ctx, current->left->token.value,
e8d9dd6a2f39d9c1a647b0b513de84e39e2235ebbjh buffer = ap_ssi_parse_string(r, ctx, current->right->token.value,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding " Compare (%s) with (%s)\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding current->value = 0; /* Don't return -1 if unknown token */
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Returning %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Evaluate !: %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding if (current->right != (struct parse_node *) NULL) {
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding debug_pos += sprintf (&debug[debug_pos], " Evaluate (): %c\n",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Unmatched '(' in \"%s\" in file %s",
6a07be8f4d69cf6936e340975cf8ec25c01774b9rbb ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "Unmatched ')' in \"%s\" in file %s",
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding "bad token type");
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding retval = (root == (struct parse_node *) NULL) ? 0 : root->value;
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding/*-------------------------------------------------------------------------*/
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding#define LOG_COND_STATUS(cntx, t_buck, h_ptr, ins_head, tag_text) \
0f081398cf0eef8cc7c66a535d450110a92dc8aefielding char cond_txt[] = "**** X conditional_status=\"0\"\n"; \
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#define DUMP_PARSE_EXPR_DEBUG(t_buck, h_ptr, d_buf, ins_head) \
r->filename);
if (was_error) {
if (was_unmatched) {
if (expr_ret) {
#ifdef DEBUG_INCLUDE
r->filename);
r->filename);
if (was_error) {
if (was_unmatched) {
if (expr_ret) {
#ifdef DEBUG_INCLUDE
r->filename);
char *parsed_string;
while (sub) {
MAX_STRING_LEN, 0);
r->filename);
MAX_STRING_LEN, 0);
*next = 0;
r->pool,
r->filename);
int do_cleanup = 0;
return rv;
return rv;
apr_bucket **);
r->filename);
return APR_SUCCESS;
return (rv);
return rv;
return rv;
return APR_SUCCESS;
return result;
return result;
return NULL;
request_rec *r = f->r;
if (!f->ctx) {
f->c->bucket_alloc);
ap_add_cgi_vars(r);
/* Always unset the ETag/Last-Modified fields - see RFC2616 - 13.3.4.
return send_parsed_content(&b, r, f);
if(ssi_pfn_register) {
return OK;
return NULL;
return NULL;
return NULL;
return NULL;
return NULL;
{NULL}
return DECLINED;
return DECLINED;
return DECLINED;
return DECLINED;
return DECLINED;