From 500c9cb211aa25db1624eadd3325b97c5be02355 Mon Sep 17 00:00:00 2001 From: Nick Kew Date: Mon, 31 Mar 2008 22:10:36 +0000 Subject: [PATCH] Remove ap_expr_clone from the API (same day it was added:-) git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@643175 13f79535-47bb-0310-9956-ffa450edef68 --- include/ap_expr.h | 17 +++-------------- modules/filters/mod_filter.c | 4 +--- server/util_expr.c | 24 +++++++++++++++--------- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/include/ap_expr.h b/include/ap_expr.h index 2dcaf3935e..11dac272a4 100644 --- a/include/ap_expr.h +++ b/include/ap_expr.h @@ -102,7 +102,9 @@ 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); /** - * 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 @@ -141,19 +143,6 @@ AP_DECLARE(apr_status_t) ap_expr_init(apr_pool_t *pool); */ 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 diff --git a/modules/filters/mod_filter.c b/modules/filters/mod_filter.c index b1bdd0e40e..4d6ee7f0e7 100644 --- a/modules/filters/mod_filter.c +++ b/modules/filters/mod_filter.c @@ -141,14 +141,12 @@ static int filter_lookup(ap_filter_t *f, ap_filter_rec_t *filter) 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, diff --git a/server/util_expr.c b/server/util_expr.c index dedde033eb..fd1fd99424 100644 --- a/server/util_expr.c +++ b/server/util_expr.c @@ -26,7 +26,6 @@ #include "http_log.h" #include "ap_expr.h" -#include #if 1 /* * +-------------------------------------------------------+ @@ -670,9 +669,9 @@ AP_DECLARE(ap_parse_node_t*) ap_expr_parse(apr_pool_t* pool, const char *expr, 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)); @@ -687,9 +686,9 @@ AP_DECLARE(ap_parse_node_t*) ap_expr_clone_tree(apr_pool_t *pool, } #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; @@ -868,6 +867,13 @@ AP_DECLARE(int) ap_expr_eval(request_rec *r, ap_parse_node_t *root, 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, @@ -879,7 +885,7 @@ AP_DECLARE(int) ap_expr_evalstring(request_rec *r, const char *expr, "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); } @@ -888,7 +894,7 @@ AP_DECLARE(const char*) ap_expr_string(request_rec *r, const char *str) { /* 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; -- 2.40.0