MINOR: regex: Change the struct containing regex
This change permits to remove the typedef. The original regex structs
are set in haproxy's struct.
diff --git a/include/common/regex.h b/include/common/regex.h
index 59730ca..9789ec3 100644
--- a/include/common/regex.h
+++ b/include/common/regex.h
@@ -29,24 +29,25 @@
#ifdef USE_PCRE
#include <pcre.h>
#include <pcreposix.h>
+#else /* no PCRE */
+#include <regex.h>
+#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 <regex.h>
-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 @@
*
* 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 @@
* 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 ca3cf1f..7065b6b 100644
--- a/include/types/pattern.h
+++ b/include/types/pattern.h
@@ -135,7 +135,7 @@
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 6d7de52..3ac8f03 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -476,7 +476,7 @@
/* 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 a268996..7a76940 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -122,7 +122,7 @@
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 @@
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;
}