removed some of the debug logging and added author details
[httpd-crcsyncproxy.git] / include / ap_expr.h
blob2763ee23d700fb77a5e7e71833ae3f0c94152178
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /**
18 * @file ap_expr.h
19 * @brief Expression parser
22 #ifndef AP_EXPR_H
23 #define AP_EXPR_H
25 #include "httpd.h"
26 #include "ap_regex.h"
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
32 /* conditional expression parser stuff */
33 typedef enum {
34 TOKEN_STRING,
35 TOKEN_RE,
36 TOKEN_AND,
37 TOKEN_OR,
38 TOKEN_NOT,
39 TOKEN_EQ,
40 TOKEN_NE,
41 TOKEN_RBRACE,
42 TOKEN_LBRACE,
43 TOKEN_GROUP,
44 TOKEN_GE,
45 TOKEN_LE,
46 TOKEN_GT,
47 TOKEN_LT,
48 TOKEN_ACCESS
49 } token_type_t;
51 typedef struct {
52 token_type_t type;
53 const char *value;
54 #ifdef DEBUG_INCLUDE
55 const char *s;
56 #endif
57 } token_t;
59 typedef struct parse_node {
60 struct parse_node *parent;
61 struct parse_node *left;
62 struct parse_node *right;
63 token_t token;
64 int value;
65 int done;
66 #ifdef DEBUG_INCLUDE
67 int dump_done;
68 #endif
69 } ap_parse_node_t;
71 typedef struct {
72 const char *source;
73 const char *rexp;
74 apr_size_t nsub;
75 ap_regmatch_t match[AP_MAX_REG_MATCH];
76 } backref_t;
78 typedef const char *(*string_func_t)(request_rec*, const char*);
79 typedef int (*opt_func_t)(request_rec*, ap_parse_node_t*, string_func_t);
81 /**
82 * Parse an expression into a parse tree
83 * @param pool Pool
84 * @param expr The expression to parse
85 * @param was_error On return, set to zero if parse successful, nonzero on error
86 * @return The parse tree
88 AP_DECLARE(ap_parse_node_t*) ap_expr_parse(apr_pool_t *pool, const char *expr,
89 int *was_error);
90 /**
91 * Evaluate a parse tree
92 * @param r The current request
93 * @param root The root node of the parse tree
94 * @param was_error On return, set to zero if parse successful, nonzero on error
95 * @param reptr Regular expression memory for backreferencing if a regexp was parsed
96 * @param string_func String parser function - perform variable substitutions
97 * Use ap_expr_string where applicable
98 * @param eval_func Option evaluation function (e.g. -A filename)
99 * @return the value the expression parsed to
101 AP_DECLARE(int) ap_expr_eval(request_rec *r, ap_parse_node_t *root,
102 int *was_error, backref_t **reptr,
103 string_func_t string_func, opt_func_t eval_func);
105 * Evaluate an expression. This is functionally equivalent to
106 * ap_expr_parse followed by ap_expr_eval, but faster and more efficient
107 * when an expression only needs to be parsed once and discarded.
108 * @param r The current request
109 * @param expr The expression to parse
110 * @param was_error On return, set to zero if parse successful, nonzero on error
111 * @param reptr Regular expression memory for backreferencing if a regexp was parsed
112 * @param string_func String parser function - perform variable substitutions
113 * Use ap_expr_string where applicable
114 * @param eval_func Option evaluation function (e.g. -A filename)
115 * @return the value the expression parsed to
117 AP_DECLARE(int) ap_expr_evalstring(request_rec *r, const char *expr,
118 int *was_error, backref_t **reptr,
119 string_func_t string_func,
120 opt_func_t eval_func);
123 * Internal initialisation of ap_expr (for httpd)
124 * @param pool Pool
125 * @return APR_SUCCESS or error
127 AP_DECLARE(apr_status_t) ap_expr_init(apr_pool_t *pool);
130 * Default string evaluation function for passing to ap_expr_eval and
131 * ap_expr_evalstring. Use this (and update as necessary) to offer
132 * a consistent expression syntax across different modules.
133 * Supports the following:
134 * $req{foo} - request header "foo"
135 * $resp{foo} - response header "foo"
136 * $env{foo} - environment variable "foo"
137 * $handler - r->handler
138 * $content-type - r->content_type
139 * Other strings are returned unmodified.
140 * @param r The current request
141 * @param str The string to evaluate
142 * @return The evaluated string
144 AP_DECLARE_NONSTD(const char*) ap_expr_string(request_rec *r,
145 const char *str);
147 #ifdef __cplusplus
149 #endif
151 #endif /* AP_EXPR_H */