home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 November / CMCD1104.ISO / Software / Complet / Apache / apache_2.0.52-win32-x86-no_ssl.msi / Data.Cab / F277272_mod_include.h < prev    next >
C/C++ Source or Header  |  2004-09-23  |  10KB  |  206 lines

  1. /* Copyright 2000-2004 The Apache Software Foundation
  2.  *
  3.  * Licensed under the Apache License, Version 2.0 (the "License");
  4.  * you may not use this file except in compliance with the License.
  5.  * You may obtain a copy of the License at
  6.  *
  7.  *     http://www.apache.org/licenses/LICENSE-2.0
  8.  *
  9.  * Unless required by applicable law or agreed to in writing, software
  10.  * distributed under the License is distributed on an "AS IS" BASIS,
  11.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12.  * See the License for the specific language governing permissions and
  13.  * limitations under the License.
  14.  */
  15.  
  16. #ifndef _MOD_INCLUDE_H
  17. #define _MOD_INCLUDE_H 1
  18.  
  19. #include "apr_pools.h"
  20. #include "apr_optional.h"
  21.  
  22. #define STARTING_SEQUENCE "<!--#"
  23. #define ENDING_SEQUENCE "-->"
  24.  
  25. #define DEFAULT_ERROR_MSG "[an error occurred while processing this directive]"
  26. #define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
  27. #define SIZEFMT_BYTES 0
  28. #define SIZEFMT_KMG 1
  29. #define TMP_BUF_SIZE 1024
  30. #if APR_CHARSET_EBCDIC
  31. #define RAW_ASCII_CHAR(ch)  apr_xlate_conv_byte(ap_hdrs_from_ascii, (unsigned char)ch)
  32. #else /*APR_CHARSET_EBCDIC*/
  33. #define RAW_ASCII_CHAR(ch)  (ch)
  34. #endif /*APR_CHARSET_EBCDIC*/
  35.  
  36. /****************************************************************************
  37.  * Used to keep context information during parsing of a request for SSI tags.
  38.  * This is especially useful if the tag stretches across multiple buckets or
  39.  * brigades. This keeps track of which buckets need to be replaced with the
  40.  * content generated by the SSI tag.
  41.  *
  42.  * state: PRE_HEAD - State prior to finding the first character of the 
  43.  *                   STARTING_SEQUENCE. Next state is PARSE_HEAD.
  44.  *        PARSE_HEAD - State entered once the first character of the
  45.  *                     STARTING_SEQUENCE is found and exited when the
  46.  *                     the full STARTING_SEQUENCE has been matched or
  47.  *                     a match failure occurs. Next state is PRE_HEAD
  48.  *                     or PARSE_TAG.
  49.  *        PARSE_TAG - State entered once the STARTING sequence has been
  50.  *                    matched. It is exited when the first character in
  51.  *                    ENDING_SEQUENCE is found. Next state is PARSE_TAIL.
  52.  *        PARSE_TAIL - State entered from PARSE_TAG state when the first
  53.  *                     character in ENDING_SEQUENCE is encountered. This
  54.  *                     state is exited when the ENDING_SEQUENCE has been
  55.  *                     completely matched, or when a match failure occurs.
  56.  *                     Next state is PARSE_TAG or PARSED.
  57.  *        PARSED - State entered from PARSE_TAIL once the complete 
  58.  *                 ENDING_SEQUENCE has been matched. The SSI tag is
  59.  *                 processed and the SSI buckets are replaced with the
  60.  *                 SSI content during this state.
  61.  * parse_pos: Current matched position within the STARTING_SEQUENCE or
  62.  *            ENDING_SEQUENCE during the PARSE_HEAD and PARSE_TAIL states.
  63.  *            This is especially useful when the sequence spans brigades.
  64.  * X_start_bucket: These point to the buckets containing the first character
  65.  *                 of the STARTING_SEQUENCE, the first non-whitespace
  66.  *                 character of the tag, and the first character in the
  67.  *                 ENDING_SEQUENCE (head_, tag_, and tail_ respectively).
  68.  *                 The buckets are kept intact until the PARSED state is
  69.  *                 reached, at which time the tag is consolidated and the
  70.  *                 buckets are released. The buckets that these point to
  71.  *                 have all been set aside in the ssi_tag_brigade (along
  72.  *                 with all of the intervening buckets).
  73.  * X_start_index: The index points within the specified bucket contents
  74.  *                where the first character of the STARTING_SEQUENCE,
  75.  *                the first non-whitespace character of the tag, and the
  76.  *                first character in the ENDING_SEQUENCE can be found
  77.  *                (head_, tag_, and tail_ respectively).
  78.  * combined_tag: Once the PARSED state is reached the tag is collected from
  79.  *               the bucket(s) in the ssi_tag_brigade into this contiguous
  80.  *               buffer. The buckets in the ssi_tag_brigade are released
  81.  *               and the tag is processed.
  82.  * curr_tag_pos: Ptr to the combined_tag buffer indicating the current
  83.  *               parse position.
  84.  * tag_length: The number of bytes in the actual tag (excluding the
  85.  *             STARTING_SEQUENCE, leading and trailing whitespace,
  86.  *             and ENDING_SEQUENCE). This length is computed as the
  87.  *             buckets are parsed and set aside during the PARSE_TAG state.
  88.  * ssi_tag_brigade: The temporary brigade used by this filter to set aside
  89.  *                  the buckets containing parts of the ssi tag and headers.
  90.  */
  91.  
  92. /* I keep this stuff here, because of binary compat. It probably doesn't care,
  93.  * but who knows ...?
  94.  */
  95. #ifdef MOD_INCLUDE_REDESIGN
  96. typedef enum {PRE_HEAD, BLOW_PARSE_HEAD, BLOW_PARSE_DIRECTIVE, PARSE_TAG,
  97.               BLOW_PARSE_TAIL, PARSED} states;
  98. #else
  99. typedef enum {PRE_HEAD, PARSE_HEAD, PARSE_DIRECTIVE, PARSE_TAG, PARSE_TAIL,
  100.               PARSED} states;
  101. #endif
  102.  
  103. /** forward referenced as it needs to be held on the context */
  104. typedef struct bndm_t bndm_t;
  105.  
  106. typedef struct include_filter_ctx {
  107.     states       state;
  108.     long         flags;    /* See the FLAG_XXXXX definitions. */
  109.     int          if_nesting_level;
  110.     apr_size_t   parse_pos;
  111.     int          bytes_parsed;
  112.     apr_status_t status;
  113.     int          output_now;
  114.     int          output_flush;
  115.     
  116.     apr_bucket   *head_start_bucket;
  117.     apr_size_t   head_start_index;
  118.  
  119.     apr_bucket   *tag_start_bucket;
  120.     apr_size_t   tag_start_index;
  121.  
  122.     apr_bucket   *tail_start_bucket;
  123.     apr_size_t   tail_start_index;
  124.  
  125.     char        *combined_tag;
  126.     char        *curr_tag_pos;
  127.     apr_size_t   directive_length;
  128.     apr_size_t   tag_length;
  129.  
  130.     char         *error_str;
  131.     char         *error_str_override;
  132.     char         *time_str;
  133.     char         *time_str_override;
  134.     apr_pool_t   *pool;
  135.  
  136.     apr_bucket_brigade *ssi_tag_brigade;
  137.     bndm_t       *start_seq_pat;
  138.     char         *start_seq;
  139.     int          start_seq_len;
  140.     char         *end_seq;
  141.     char         *re_string;
  142.     regmatch_t   (*re_result)[10];
  143. } include_ctx_t;
  144.  
  145. /* These flags are used to set flag bits. */
  146. #define FLAG_PRINTING         0x00000001  /* Printing conditional lines. */
  147. #define FLAG_COND_TRUE        0x00000002  /* Conditional eval'd to true. */
  148. #define FLAG_SIZE_IN_BYTES    0x00000004  /* Sizes displayed in bytes.   */
  149. #define FLAG_NO_EXEC          0x00000008  /* No Exec in current context. */
  150.  
  151. /* These flags are used to clear flag bits. */
  152. #define FLAG_SIZE_ABBREV      0xFFFFFFFB  /* Reset SIZE_IN_BYTES bit.    */
  153. #define FLAG_CLEAR_PRINT_COND 0xFFFFFFFC  /* Reset PRINTING and COND_TRUE*/
  154. #define FLAG_CLEAR_PRINTING   0xFFFFFFFE  /* Reset just PRINTING bit.    */
  155.  
  156. #define CREATE_ERROR_BUCKET(cntx, t_buck, h_ptr, ins_head)        \
  157. {                                                                 \
  158.     /* XXX: it'd probably be nice to use a pool bucket here */    \
  159.     t_buck = apr_bucket_heap_create(cntx->error_str,              \
  160.                                     strlen(cntx->error_str),      \
  161.                                     NULL, h_ptr->list);           \
  162.     APR_BUCKET_INSERT_BEFORE(h_ptr, t_buck);                      \
  163.                                                                   \
  164.     if (ins_head == NULL) {                                       \
  165.         ins_head = t_buck;                                        \
  166.     }                                                             \
  167. }
  168.  
  169. /* Make sure to check the return code rc. If it is anything other
  170.  *   than APR_SUCCESS, then you should return this value up the
  171.  *   call chain.
  172.  */
  173. #define SPLIT_AND_PASS_PRETAG_BUCKETS(brgd, cntxt, next, rc)          \
  174. if ((APR_BRIGADE_EMPTY((cntxt)->ssi_tag_brigade)) &&                  \
  175.     ((cntxt)->head_start_bucket != NULL)) {                           \
  176.     apr_bucket_brigade *tag_plus;                                     \
  177.                                                                       \
  178.     tag_plus = apr_brigade_split((brgd), (cntxt)->head_start_bucket); \
  179.     if ((cntxt)->output_flush) {                                      \
  180.         APR_BRIGADE_INSERT_TAIL((brgd), apr_bucket_flush_create((brgd)->bucket_alloc));   \
  181.     }                                                                 \
  182.     (rc) = ap_pass_brigade((next), (brgd));                           \
  183.     (cntxt)->bytes_parsed = 0;                                        \
  184.     (brgd) = tag_plus;                                                \
  185. }
  186.  
  187.  
  188. typedef int (include_handler_fn_t)(include_ctx_t *ctx, apr_bucket_brigade **bb,
  189.                        request_rec *r, ap_filter_t *f, apr_bucket *head_ptr, 
  190.                        apr_bucket **inserted_head);
  191.  
  192. APR_DECLARE_OPTIONAL_FN(void, ap_ssi_get_tag_and_value, (include_ctx_t *ctx,
  193.                                                          char **tag,
  194.                                                          char **tag_val,
  195.                                                          int dodecode));
  196. APR_DECLARE_OPTIONAL_FN(char*, ap_ssi_parse_string, (request_rec *r,
  197.                                                     include_ctx_t *ctx,
  198.                                                     const char *in,
  199.                                                     char *out,
  200.                                                     apr_size_t length,
  201.                                                     int leave_name));
  202. APR_DECLARE_OPTIONAL_FN(void, ap_register_include_handler, 
  203.                         (char *tag, include_handler_fn_t *func));
  204.  
  205. #endif /* MOD_INCLUDE */
  206.