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.
19 * @brief Expression parser
32 /* conditional expression parser stuff */
59 typedef struct parse_node {
60 struct parse_node *parent;
61 struct parse_node *left;
62 struct parse_node *right;
75 ap_regmatch_t match[AP_MAX_REG_MATCH];
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);
82 * Parse an expression into a parse tree
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,
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)
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,
151 #endif /* AP_EXPR_H */