From 799c042daa5b70d064818247fd839c813a48dbbf Mon Sep 17 00:00:00 2001 From: Thierry FOURNIER Date: Fri, 6 Dec 2013 20:36:20 +0100 Subject: [PATCH] MINOR: regex: Change the struct containing regex This change permits to remove the typedef. The original regex structs are set in haproxy's struct. --- include/common/regex.h | 29 +++++++++++++++-------------- include/types/pattern.h | 2 +- src/pattern.c | 2 +- src/regex.c | 4 ++-- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/include/common/regex.h b/include/common/regex.h index 59730cac9..9789ec3c9 100644 --- a/include/common/regex.h +++ b/include/common/regex.h @@ -29,24 +29,25 @@ #ifdef USE_PCRE #include #include +#else /* no PCRE */ +#include +#endif +struct my_regex { +#ifdef USE_PCRE #ifdef USE_PCRE_JIT #ifndef PCRE_CONFIG_JIT #error "The PCRE lib doesn't support JIT. Change your lib, or remove the option USE_PCRE_JIT." #endif -struct jit_regex { - pcre *reg; - pcre_extra *extra; -}; -typedef struct jit_regex regex; + pcre *reg; + pcre_extra *extra; #else /* no PCRE_JIT */ -typedef regex_t regex; + regex_t regex; #endif - #else /* no PCRE */ -#include -typedef regex_t regex; + regex_t regex; #endif +}; /* what to do when a header matches a regex */ #define ACT_ALLOW 0 /* allow the request */ @@ -77,7 +78,7 @@ extern regmatch_t pmatch[MAX_MATCH]; * * The function return 1 is succes case, else return 0 and err is filled. */ -int regex_comp(const char *str, regex *regex, int cs, int cap, char **err); +int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **err); int exp_replace(char *dst, char *src, const char *str, const regmatch_t *matches); const char *check_replace_string(const char *str); const char *chain_regex(struct hdr_exp **head, const regex_t *preg, @@ -87,25 +88,25 @@ const char *chain_regex(struct hdr_exp **head, const regex_t *preg, * be writable because the function will temporarily force a zero past the * last character. */ -static inline int regex_exec(const regex *preg, char *subject, int length) { +static inline int regex_exec(const struct my_regex *preg, char *subject, int length) { #ifdef USE_PCRE_JIT return pcre_exec(preg->reg, preg->extra, subject, length, 0, 0, NULL, 0); #else int match; char old_char = subject[length]; subject[length] = 0; - match = regexec(preg, subject, 0, NULL, 0); + match = regexec(&preg->regex, subject, 0, NULL, 0); subject[length] = old_char; return match; #endif } -static inline void regex_free(regex *preg) { +static inline void regex_free(struct my_regex *preg) { #ifdef USE_PCRE_JIT pcre_free_study(preg->extra); pcre_free(preg->reg); #else - regfree(preg); + regfree(&preg->regex); #endif } diff --git a/include/types/pattern.h b/include/types/pattern.h index ca3cf1f2b..7065b6b9c 100644 --- a/include/types/pattern.h +++ b/include/types/pattern.h @@ -135,7 +135,7 @@ struct pattern { union { void *ptr; /* any data */ char *str; /* any string */ - regex *reg; /* a compiled regex */ + struct my_regex *reg; /* a compiled regex */ } ptr; /* indirect values, allocated */ void(*freeptrbuf)(void *ptr); /* a destructor able to free objects from the ptr */ int len; /* data length when required */ diff --git a/src/pattern.c b/src/pattern.c index 6d7de5293..3ac8f0361 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -476,7 +476,7 @@ static void pat_free_reg(void *ptr) /* Parse a regex. It is allocated. */ int pat_parse_reg(const char **text, struct pattern *pattern, int *opaque, char **err) { - regex *preg; + struct my_regex *preg; preg = calloc(1, sizeof(*preg)); diff --git a/src/regex.c b/src/regex.c index a268996b0..7a7694050 100644 --- a/src/regex.c +++ b/src/regex.c @@ -122,7 +122,7 @@ const char *chain_regex(struct hdr_exp **head, const regex_t *preg, return NULL; } -int regex_comp(const char *str, regex *regex, int cs, int cap, char **err) +int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **err) { #ifdef USE_PCRE_JIT int flags = 0; @@ -154,7 +154,7 @@ int regex_comp(const char *str, regex *regex, int cs, int cap, char **err) if (!cap) flags |= REG_NOSUB; - if (regcomp(regex, str, flags) != 0) { + if (regcomp(®ex->regex, str, flags) != 0) { memprintf(err, "regex '%s' is invalid", str); return 0; }