mod_include.h revision e099672a13ea4ff4a11f130406f1baecba5949ba
18343797fadabacf01280b38ea7688690d12aec0rbb/* ====================================================================
18343797fadabacf01280b38ea7688690d12aec0rbb * The Apache Software License, Version 1.1
18343797fadabacf01280b38ea7688690d12aec0rbb *
b99dbaab171d91e1b664397cc40e039d0c087c65fielding * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
18343797fadabacf01280b38ea7688690d12aec0rbb * reserved.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * Redistribution and use in source and binary forms, with or without
18343797fadabacf01280b38ea7688690d12aec0rbb * modification, are permitted provided that the following conditions
18343797fadabacf01280b38ea7688690d12aec0rbb * are met:
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * 1. Redistributions of source code must retain the above copyright
18343797fadabacf01280b38ea7688690d12aec0rbb * notice, this list of conditions and the following disclaimer.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * 2. Redistributions in binary form must reproduce the above copyright
18343797fadabacf01280b38ea7688690d12aec0rbb * notice, this list of conditions and the following disclaimer in
18343797fadabacf01280b38ea7688690d12aec0rbb * the documentation and/or other materials provided with the
18343797fadabacf01280b38ea7688690d12aec0rbb * distribution.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * 3. The end-user documentation included with the redistribution,
18343797fadabacf01280b38ea7688690d12aec0rbb * if any, must include the following acknowledgment:
18343797fadabacf01280b38ea7688690d12aec0rbb * "This product includes software developed by the
18343797fadabacf01280b38ea7688690d12aec0rbb * Apache Software Foundation (http://www.apache.org/)."
18343797fadabacf01280b38ea7688690d12aec0rbb * Alternately, this acknowledgment may appear in the software itself,
18343797fadabacf01280b38ea7688690d12aec0rbb * if and wherever such third-party acknowledgments normally appear.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * 4. The names "Apache" and "Apache Software Foundation" must
18343797fadabacf01280b38ea7688690d12aec0rbb * not be used to endorse or promote products derived from this
18343797fadabacf01280b38ea7688690d12aec0rbb * software without prior written permission. For written
18343797fadabacf01280b38ea7688690d12aec0rbb * permission, please contact apache@apache.org.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * 5. Products derived from this software may not be called "Apache",
18343797fadabacf01280b38ea7688690d12aec0rbb * nor may "Apache" appear in their name, without prior written
18343797fadabacf01280b38ea7688690d12aec0rbb * permission of the Apache Software Foundation.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
18343797fadabacf01280b38ea7688690d12aec0rbb * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18343797fadabacf01280b38ea7688690d12aec0rbb * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18343797fadabacf01280b38ea7688690d12aec0rbb * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
18343797fadabacf01280b38ea7688690d12aec0rbb * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18343797fadabacf01280b38ea7688690d12aec0rbb * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
18343797fadabacf01280b38ea7688690d12aec0rbb * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18343797fadabacf01280b38ea7688690d12aec0rbb * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
18343797fadabacf01280b38ea7688690d12aec0rbb * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
18343797fadabacf01280b38ea7688690d12aec0rbb * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
18343797fadabacf01280b38ea7688690d12aec0rbb * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
18343797fadabacf01280b38ea7688690d12aec0rbb * SUCH DAMAGE.
18343797fadabacf01280b38ea7688690d12aec0rbb * ====================================================================
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * This software consists of voluntary contributions made by many
18343797fadabacf01280b38ea7688690d12aec0rbb * individuals on behalf of the Apache Software Foundation. For more
18343797fadabacf01280b38ea7688690d12aec0rbb * information on the Apache Software Foundation, please see
18343797fadabacf01280b38ea7688690d12aec0rbb * <http://www.apache.org/>.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * Portions of this software are based upon public domain software
18343797fadabacf01280b38ea7688690d12aec0rbb * originally written at the National Center for Supercomputing Applications,
18343797fadabacf01280b38ea7688690d12aec0rbb * University of Illinois, Urbana-Champaign.
18343797fadabacf01280b38ea7688690d12aec0rbb */
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb#ifndef _MOD_INCLUDE_H
18343797fadabacf01280b38ea7688690d12aec0rbb#define _MOD_INCLUDE_H 1
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb#define STARTING_SEQUENCE "<!--#"
18343797fadabacf01280b38ea7688690d12aec0rbb#define ENDING_SEQUENCE "-->"
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb#define DEFAULT_ERROR_MSG "[an error occurred while processing this directive]"
18343797fadabacf01280b38ea7688690d12aec0rbb#define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
18343797fadabacf01280b38ea7688690d12aec0rbb#define SIZEFMT_BYTES 0
18343797fadabacf01280b38ea7688690d12aec0rbb#define SIZEFMT_KMG 1
18343797fadabacf01280b38ea7688690d12aec0rbb#define TMP_BUF_SIZE 1024
db3fa7db7c7910f2f23c3e3ffe0cf9f41a1899b9trawick#if APR_CHARSET_EBCDIC
18343797fadabacf01280b38ea7688690d12aec0rbb#define RAW_ASCII_CHAR(ch) apr_xlate_conv_byte(ap_hdrs_from_ascii, (unsigned char)ch)
db3fa7db7c7910f2f23c3e3ffe0cf9f41a1899b9trawick#else /*APR_CHARSET_EBCDIC*/
18343797fadabacf01280b38ea7688690d12aec0rbb#define RAW_ASCII_CHAR(ch) (ch)
db3fa7db7c7910f2f23c3e3ffe0cf9f41a1899b9trawick#endif /*APR_CHARSET_EBCDIC*/
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb/* just need some arbitrary non-NULL pointer which can't also be a request_rec */
138c8f7cb8254e035c6f45288e3909cd9c21be5cmartin#define NESTED_INCLUDE_MAGIC (&include_module)
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb/****************************************************************************
18343797fadabacf01280b38ea7688690d12aec0rbb * Used to keep context information during parsing of a request for SSI tags.
18343797fadabacf01280b38ea7688690d12aec0rbb * This is especially useful if the tag stretches across multiple buckets or
18343797fadabacf01280b38ea7688690d12aec0rbb * brigades. This keeps track of which buckets need to be replaced with the
18343797fadabacf01280b38ea7688690d12aec0rbb * content generated by the SSI tag.
18343797fadabacf01280b38ea7688690d12aec0rbb *
18343797fadabacf01280b38ea7688690d12aec0rbb * state: PRE_HEAD - State prior to finding the first character of the
18343797fadabacf01280b38ea7688690d12aec0rbb * STARTING_SEQUENCE. Next state is PARSE_HEAD.
18343797fadabacf01280b38ea7688690d12aec0rbb * PARSE_HEAD - State entered once the first character of the
18343797fadabacf01280b38ea7688690d12aec0rbb * STARTING_SEQUENCE is found and exited when the
18343797fadabacf01280b38ea7688690d12aec0rbb * the full STARTING_SEQUENCE has been matched or
18343797fadabacf01280b38ea7688690d12aec0rbb * a match failure occurs. Next state is PRE_HEAD
18343797fadabacf01280b38ea7688690d12aec0rbb * or PARSE_TAG.
18343797fadabacf01280b38ea7688690d12aec0rbb * PARSE_TAG - State entered once the STARTING sequence has been
18343797fadabacf01280b38ea7688690d12aec0rbb * matched. It is exited when the first character in
18343797fadabacf01280b38ea7688690d12aec0rbb * ENDING_SEQUENCE is found. Next state is PARSE_TAIL.
18343797fadabacf01280b38ea7688690d12aec0rbb * PARSE_TAIL - State entered from PARSE_TAG state when the first
18343797fadabacf01280b38ea7688690d12aec0rbb * character in ENDING_SEQUENCE is encountered. This
18343797fadabacf01280b38ea7688690d12aec0rbb * state is exited when the ENDING_SEQUENCE has been
18343797fadabacf01280b38ea7688690d12aec0rbb * completely matched, or when a match failure occurs.
18343797fadabacf01280b38ea7688690d12aec0rbb * Next state is PARSE_TAG or PARSED.
18343797fadabacf01280b38ea7688690d12aec0rbb * PARSED - State entered from PARSE_TAIL once the complete
18343797fadabacf01280b38ea7688690d12aec0rbb * ENDING_SEQUENCE has been matched. The SSI tag is
18343797fadabacf01280b38ea7688690d12aec0rbb * processed and the SSI buckets are replaced with the
18343797fadabacf01280b38ea7688690d12aec0rbb * SSI content during this state.
18343797fadabacf01280b38ea7688690d12aec0rbb * parse_pos: Current matched position within the STARTING_SEQUENCE or
18343797fadabacf01280b38ea7688690d12aec0rbb * ENDING_SEQUENCE during the PARSE_HEAD and PARSE_TAIL states.
18343797fadabacf01280b38ea7688690d12aec0rbb * This is especially useful when the sequence spans brigades.
18343797fadabacf01280b38ea7688690d12aec0rbb * X_start_bucket: These point to the buckets containing the first character
18343797fadabacf01280b38ea7688690d12aec0rbb * of the STARTING_SEQUENCE, the first non-whitespace
18343797fadabacf01280b38ea7688690d12aec0rbb * character of the tag, and the first character in the
18343797fadabacf01280b38ea7688690d12aec0rbb * ENDING_SEQUENCE (head_, tag_, and tail_ respectively).
18343797fadabacf01280b38ea7688690d12aec0rbb * The buckets are kept intact until the PARSED state is
18343797fadabacf01280b38ea7688690d12aec0rbb * reached, at which time the tag is consolidated and the
18343797fadabacf01280b38ea7688690d12aec0rbb * buckets are released. The buckets that these point to
18343797fadabacf01280b38ea7688690d12aec0rbb * have all been set aside in the ssi_tag_brigade (along
18343797fadabacf01280b38ea7688690d12aec0rbb * with all of the intervening buckets).
18343797fadabacf01280b38ea7688690d12aec0rbb * X_start_index: The index points within the specified bucket contents
18343797fadabacf01280b38ea7688690d12aec0rbb * where the first character of the STARTING_SEQUENCE,
18343797fadabacf01280b38ea7688690d12aec0rbb * the first non-whitespace character of the tag, and the
18343797fadabacf01280b38ea7688690d12aec0rbb * first character in the ENDING_SEQUENCE can be found
18343797fadabacf01280b38ea7688690d12aec0rbb * (head_, tag_, and tail_ respectively).
18343797fadabacf01280b38ea7688690d12aec0rbb * combined_tag: Once the PARSED state is reached the tag is collected from
18343797fadabacf01280b38ea7688690d12aec0rbb * the bucket(s) in the ssi_tag_brigade into this contiguous
18343797fadabacf01280b38ea7688690d12aec0rbb * buffer. The buckets in the ssi_tag_brigade are released
18343797fadabacf01280b38ea7688690d12aec0rbb * and the tag is processed.
18343797fadabacf01280b38ea7688690d12aec0rbb * curr_tag_pos: Ptr to the combined_tag buffer indicating the current
18343797fadabacf01280b38ea7688690d12aec0rbb * parse position.
18343797fadabacf01280b38ea7688690d12aec0rbb * tag_length: The number of bytes in the actual tag (excluding the
18343797fadabacf01280b38ea7688690d12aec0rbb * STARTING_SEQUENCE, leading and trailing whitespace,
18343797fadabacf01280b38ea7688690d12aec0rbb * and ENDING_SEQUENCE). This length is computed as the
18343797fadabacf01280b38ea7688690d12aec0rbb * buckets are parsed and set aside during the PARSE_TAG state.
18343797fadabacf01280b38ea7688690d12aec0rbb * ssi_tag_brigade: The temporary brigade used by this filter to set aside
18343797fadabacf01280b38ea7688690d12aec0rbb * the buckets containing parts of the ssi tag and headers.
18343797fadabacf01280b38ea7688690d12aec0rbb */
f6e9f5600e77b78fb013bb543d364135961639d1rbbtypedef enum {PRE_HEAD, PARSE_HEAD, PARSE_DIRECTIVE, PARSE_TAG, PARSE_TAIL, PARSED} states;
18343797fadabacf01280b38ea7688690d12aec0rbbtypedef struct include_filter_ctx {
18343797fadabacf01280b38ea7688690d12aec0rbb states state;
18343797fadabacf01280b38ea7688690d12aec0rbb long flags; /* See the FLAG_XXXXX definitions. */
18343797fadabacf01280b38ea7688690d12aec0rbb int if_nesting_level;
23801cf373ddaff5a5ba7692d2637d75bdffdc4btrawick apr_size_t parse_pos;
b42a7e46e4f80282bd27e96d43c9510b14ccb9aarbb int bytes_parsed;
e099672a13ea4ff4a11f130406f1baecba5949bajerenkrantz apr_status_t status;
e099672a13ea4ff4a11f130406f1baecba5949bajerenkrantz int output_now;
18343797fadabacf01280b38ea7688690d12aec0rbb
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe apr_bucket *head_start_bucket;
23801cf373ddaff5a5ba7692d2637d75bdffdc4btrawick apr_size_t head_start_index;
18343797fadabacf01280b38ea7688690d12aec0rbb
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe apr_bucket *tag_start_bucket;
23801cf373ddaff5a5ba7692d2637d75bdffdc4btrawick apr_size_t tag_start_index;
18343797fadabacf01280b38ea7688690d12aec0rbb
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe apr_bucket *tail_start_bucket;
23801cf373ddaff5a5ba7692d2637d75bdffdc4btrawick apr_size_t tail_start_index;
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb char *combined_tag;
18343797fadabacf01280b38ea7688690d12aec0rbb char *curr_tag_pos;
f6e9f5600e77b78fb013bb543d364135961639d1rbb apr_size_t directive_length;
23801cf373ddaff5a5ba7692d2637d75bdffdc4btrawick apr_size_t tag_length;
18343797fadabacf01280b38ea7688690d12aec0rbb
23801cf373ddaff5a5ba7692d2637d75bdffdc4btrawick apr_size_t error_length;
18343797fadabacf01280b38ea7688690d12aec0rbb char error_str[MAX_STRING_LEN];
18343797fadabacf01280b38ea7688690d12aec0rbb char time_str[MAX_STRING_LEN];
18343797fadabacf01280b38ea7688690d12aec0rbb
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe apr_bucket_brigade *ssi_tag_brigade;
18343797fadabacf01280b38ea7688690d12aec0rbb} include_ctx_t;
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb/* These flags are used to set flag bits. */
18343797fadabacf01280b38ea7688690d12aec0rbb#define FLAG_PRINTING 0x00000001 /* Printing conditional lines. */
18343797fadabacf01280b38ea7688690d12aec0rbb#define FLAG_COND_TRUE 0x00000002 /* Conditional eval'd to true. */
18343797fadabacf01280b38ea7688690d12aec0rbb#define FLAG_SIZE_IN_BYTES 0x00000004 /* Sizes displayed in bytes. */
18343797fadabacf01280b38ea7688690d12aec0rbb#define FLAG_NO_EXEC 0x00000008 /* No Exec in current context. */
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb/* These flags are used to clear flag bits. */
18343797fadabacf01280b38ea7688690d12aec0rbb#define FLAG_SIZE_ABBREV 0xFFFFFFFB /* Reset SIZE_IN_BYTES bit. */
18343797fadabacf01280b38ea7688690d12aec0rbb#define FLAG_CLEAR_PRINT_COND 0xFFFFFFFC /* Reset PRINTING and COND_TRUE*/
18343797fadabacf01280b38ea7688690d12aec0rbb#define FLAG_CLEAR_PRINTING 0xFFFFFFFE /* Reset just PRINTING bit. */
18343797fadabacf01280b38ea7688690d12aec0rbb
18343797fadabacf01280b38ea7688690d12aec0rbb#define CREATE_ERROR_BUCKET(cntx, t_buck, h_ptr, ins_head) \
18343797fadabacf01280b38ea7688690d12aec0rbb{ \
cd36eaa1f276d94ef45e8665cc701ac1d5fc5ba3trawick apr_size_t e_wrt; \
066877f1a045103acfdd376d48cdd473c33f409bdougm t_buck = apr_bucket_heap_create(cntx->error_str, \
bfd43a0d7c378ab28f80f013a7c0931562774ee3jwoolley cntx->error_length, 1, &e_wrt); \
445997e06464e7625c7f0e22917f8f2d9876cfffrbb APR_BUCKET_INSERT_BEFORE(h_ptr, t_buck); \
18343797fadabacf01280b38ea7688690d12aec0rbb \
18343797fadabacf01280b38ea7688690d12aec0rbb if (ins_head == NULL) { \
18343797fadabacf01280b38ea7688690d12aec0rbb ins_head = t_buck; \
18343797fadabacf01280b38ea7688690d12aec0rbb } \
18343797fadabacf01280b38ea7688690d12aec0rbb}
18343797fadabacf01280b38ea7688690d12aec0rbb
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj/* Make sure to check the return code rc. If it is anything other
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj * than APR_SUCCESS, then you should return this value up the
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj * call chain.
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj */
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj#define SPLIT_AND_PASS_PRETAG_BUCKETS(brgd, cntxt, next, rc) \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpjif ((APR_BRIGADE_EMPTY(cntxt->ssi_tag_brigade)) && \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj (cntxt->head_start_bucket != NULL)) { \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj apr_bucket_brigade *tag_plus; \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj tag_plus = apr_brigade_split(brgd, cntxt->head_start_bucket); \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj rc = ap_pass_brigade(next, brgd); \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj cntxt->bytes_parsed = 0; \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj brgd = tag_plus; \
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj}
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj
4d003677925ceb0abefb9c95355b4c9e9e502899rederpj
e08a1745d191d666759873a50edcc520ca273e12wrowetypedef int (include_handler_fn_t)(include_ctx_t *ctx, apr_bucket_brigade **bb,
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe request_rec *r, ap_filter_t *f, apr_bucket *head_ptr,
b980ad7fdc218b4855cde9f75a747527f50c554dwrowe apr_bucket **inserted_head);
f6e9f5600e77b78fb013bb543d364135961639d1rbb
445997e06464e7625c7f0e22917f8f2d9876cfffrbbAPR_DECLARE_OPTIONAL_FN(void, ap_ssi_get_tag_and_value, (include_ctx_t *ctx,
445997e06464e7625c7f0e22917f8f2d9876cfffrbb char **tag,
445997e06464e7625c7f0e22917f8f2d9876cfffrbb char **tag_val,
cd33213135c92372051b7fa4f617c3d5848e6eb0rbb int dodecode));
445997e06464e7625c7f0e22917f8f2d9876cfffrbbAPR_DECLARE_OPTIONAL_FN(void, ap_ssi_parse_string, (request_rec *r,
445997e06464e7625c7f0e22917f8f2d9876cfffrbb const char *in,
445997e06464e7625c7f0e22917f8f2d9876cfffrbb char *out,
445997e06464e7625c7f0e22917f8f2d9876cfffrbb size_t length,
cd33213135c92372051b7fa4f617c3d5848e6eb0rbb int leave_name));
e08a1745d191d666759873a50edcc520ca273e12wroweAPR_DECLARE_OPTIONAL_FN(void, ap_register_include_handler,
e08a1745d191d666759873a50edcc520ca273e12wrowe (char *tag, include_handler_fn_t *func));
f6e9f5600e77b78fb013bb543d364135961639d1rbb
18343797fadabacf01280b38ea7688690d12aec0rbb#endif /* MOD_INCLUDE */