int *was_error, backref_t **reptr,
string_func_t string_func, opt_func_t eval_func);
/**
- * Evaluate an expression
+ * Evaluate an expression. This is functionally equivalent to
+ * ap_expr_parse followed by ap_expr_eval, but faster and more efficient
+ * when an expression only needs to be parsed once and discarded.
* @param r The current request
* @param expr The expression to parse
* @param was_error On return, set to zero if parse successful, nonzero on error
*/
AP_DECLARE(const char*) ap_expr_string(request_rec *r, const char *str);
-/**
- * Clone a parse tree. This is required if you create a parse tree
- * using ap_expr_parse, and wish to re-use it many times in ap_expr_eval.
- * It is not required if you need to use it just once.
- * @param pool Pool
- * @param node The parse tree to clone
- * @param parent Parent node (for internal use when recursing - pass in NULL)
- * @return The cloned tree
- */
-AP_DECLARE(ap_parse_node_t*) ap_expr_clone_tree(apr_pool_t *pool,
- ap_parse_node_t *node,
- ap_parse_node_t *parent);
-
#ifdef __cplusplus
}
#endif
request_rec *r = f->r;
harness_ctx *ctx = f->ctx;
provider_ctx *pctx;
- ap_parse_node_t *tree;
mod_filter_ctx *rctx = ap_get_module_config(r->request_config,
&filter_module);
/* Check registered providers in order */
for (provider = filter->providers; provider; provider = provider->next) {
- tree = ap_expr_clone_tree(r->pool, provider->expr, NULL);
- match = ap_expr_eval(r, tree, &err, NULL, ap_expr_string, NULL);
+ match = ap_expr_eval(r, provider->expr, &err, NULL, ap_expr_string, NULL);
if (err) {
/* log error but accept match value ? */
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
#include "http_log.h"
#include "ap_expr.h"
-#include <assert.h>
#if 1
/*
* +-------------------------------------------------------+
return root;
}
-AP_DECLARE(ap_parse_node_t*) ap_expr_clone_tree(apr_pool_t *pool,
- ap_parse_node_t *pnode,
- ap_parse_node_t *parent)
+static ap_parse_node_t *ap_expr_clone_tree(apr_pool_t *pool,
+ ap_parse_node_t *pnode,
+ ap_parse_node_t *parent)
{
ap_parse_node_t *ret;
ret = apr_pmemdup(pool, pnode, sizeof(ap_parse_node_t));
}
#define PARSE_STRING(r,s) (string_func ? string_func((r),(s)) : (s))
-AP_DECLARE(int) ap_expr_eval(request_rec *r, ap_parse_node_t *root,
- int *was_error, backref_t **reptr,
- string_func_t string_func, opt_func_t eval_func)
+static int expr_eval(request_rec *r, ap_parse_node_t *root,
+ int *was_error, backref_t **reptr,
+ string_func_t string_func, opt_func_t eval_func)
{
ap_parse_node_t *current = root;
const char *error = NULL;
return (root ? root->value : 0);
}
+AP_DECLARE(int) ap_expr_eval(request_rec *r, ap_parse_node_t *root,
+ int *was_error, backref_t **reptr,
+ string_func_t string_func, opt_func_t eval_func)
+{
+ ap_parse_node_t *clone = ap_expr_clone_tree(r->pool, root, NULL);
+ return expr_eval(r, clone, was_error, reptr, string_func, eval_func);
+}
AP_DECLARE(int) ap_expr_evalstring(request_rec *r, const char *expr,
int *was_error, backref_t **reptr,
string_func_t string_func,
"Error parsing expression in %s", r->filename);
return 0;
}
- return ap_expr_eval(r, root, was_error, reptr, string_func, eval_func);
+ return expr_eval(r, root, was_error, reptr, string_func, eval_func);
}
{
/* a default string evaluator: support headers and env */
ap_regmatch_t match[3];
- assert(isvar != NULL);
+ ap_assert(isvar != NULL);
if (ap_regexec(isvar, str, 3, match, 0) == 0) {
apr_table_t *table = NULL;
int len = match[1].rm_eo-match[1].rm_so;