From dd6755985cbca4f5dd0f69301b06efda5744848f Mon Sep 17 00:00:00 2001 From: brectanus Date: Tue, 5 Jun 2007 18:20:44 +0000 Subject: [PATCH] Move the transformation cache recort into re.h. See #14. --- apache2/modsecurity.h | 10 ---------- apache2/re.c | 12 ++++++------ apache2/re.h | 12 ++++++++++++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/apache2/modsecurity.h b/apache2/modsecurity.h index 69e52c4c..0a523168 100644 --- a/apache2/modsecurity.h +++ b/apache2/modsecurity.h @@ -502,14 +502,4 @@ void DSOLOCAL msc_alert(modsec_rec *msr, int level, msre_actionset *actionset, c apr_status_t DSOLOCAL modsecurity_request_body_clear(modsec_rec *msr); -/* Data Cache */ - -struct msc_cache_rec { - int hits; - int changed; - const char *key; - const char *val; - apr_size_t val_len; -}; - #endif diff --git a/apache2/re.c b/apache2/re.c index debd6c7a..47286f0f 100644 --- a/apache2/re.c +++ b/apache2/re.c @@ -1364,8 +1364,8 @@ apr_status_t msre_rule_process(msre_rule *rule, modsec_rec *msr) { { const apr_array_header_t *tarr; const apr_table_entry_t *telts; - msc_cache_rec **carr = NULL; - msc_cache_rec *crec = NULL; + msre_cache_rec **carr = NULL; + msre_cache_rec *crec = NULL; char *tfnsvar = NULL; char *tfnskey = NULL; int tfnscount = 0; @@ -1417,7 +1417,7 @@ apr_status_t msre_rule_process(msre_rule *rule, modsec_rec *msr) { if (usecache && tfnscount > 1 && !multi_match) { crec = NULL; msr_log(msr, 9, "CACHE: Fetching %s (multi)", tfnskey); - carr = (msc_cache_rec **)apr_hash_get(msr->tcache, tfnskey, APR_HASH_KEY_STRING); + carr = (msre_cache_rec **)apr_hash_get(msr->tcache, tfnskey, APR_HASH_KEY_STRING); if (carr != NULL) { crec = carr[msr->phase]; } @@ -1500,7 +1500,7 @@ apr_status_t msre_rule_process(msre_rule *rule, modsec_rec *msr) { /* Try to fetch this transformation from cache */ msr_log(msr, 9, "CACHE: Fetching %s", tfnskey); crec = NULL; - carr = (msc_cache_rec **)apr_hash_get(msr->tcache, tfnskey, APR_HASH_KEY_STRING); + carr = (msre_cache_rec **)apr_hash_get(msr->tcache, tfnskey, APR_HASH_KEY_STRING); if (carr != NULL) { crec = carr[msr->phase]; } @@ -1532,12 +1532,12 @@ apr_status_t msre_rule_process(msre_rule *rule, modsec_rec *msr) { if (usecache) { /* ENH1: Add flag to vars to tell which ones can change across phases store the rest in a global cache */ if (carr == NULL) { - carr = (msc_cache_rec **)apr_pcalloc(msr->mp, (sizeof(msc_cache_rec *) * (PHASE_LAST + 1))); + carr = (msre_cache_rec **)apr_pcalloc(msr->mp, (sizeof(msc_cache_rec *) * (PHASE_LAST + 1))); if (carr == NULL) return -1; memset(carr, 0, (sizeof(msc_cache_rec *) * (PHASE_LAST + 1))); apr_hash_set(msr->tcache, tfnskey, APR_HASH_KEY_STRING, carr); } - crec = carr[msr->phase] = (msc_cache_rec *)apr_pcalloc(msr->mp, sizeof(msc_cache_rec)); + crec = carr[msr->phase] = (msre_cache_rec *)apr_pcalloc(msr->mp, sizeof(msre_cache_rec)); if (crec == NULL) return -1; crec->hits = 0; diff --git a/apache2/re.h b/apache2/re.h index b459ce01..d011ea57 100644 --- a/apache2/re.h +++ b/apache2/re.h @@ -28,6 +28,7 @@ typedef struct msre_tfn_metadata msre_tfn_metadata; typedef struct msre_actionset msre_actionset; typedef struct msre_action_metadata msre_action_metadata; typedef struct msre_action msre_action; +typedef struct msre_cache_rec msre_cache_rec; #include "apr_general.h" #include "apr_tables.h" @@ -304,4 +305,15 @@ apr_status_t DSOLOCAL msre_parse_vars(msre_ruleset *ruleset, const char *text, char DSOLOCAL *msre_format_metadata(modsec_rec *msr, msre_actionset *actionset); + +/* -- Data Cache -- */ + +struct msre_cache_rec { + int hits; + int changed; + const char *key; + const char *val; + apr_size_t val_len; +}; + #endif