]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: regex: Change the struct containing regex
authorThierry FOURNIER <tfournier@exceliance.fr>
Fri, 6 Dec 2013 19:36:20 +0000 (20:36 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Dec 2013 14:42:58 +0000 (15:42 +0100)
This change permits to remove the typedef. The original regex structs
are set in haproxy's struct.

include/common/regex.h
include/types/pattern.h
src/pattern.c
src/regex.c

index 59730cac95ef8e32879be04a8852a256fc7d324e..9789ec3c9bea2eaa70c88b67e333f06eaf0a1bc1 100644 (file)
 #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 @@ 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
 }
 
index ca3cf1f2b86f9b8559ee5f32c50a9a392d867ecf..7065b6b9c915b5a0af4bc945d9ad6ed7f9f43c13 100644 (file)
@@ -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  */
index 6d7de5293f4880d1befa7cad5a8bc2ed5823698b..3ac8f0361b9dd7910ac17f3f1e43b5a33d028170 100644 (file)
@@ -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));
 
index a268996b01bcd9a7f2926ffa5739d2b57358fefd..7a7694050b41cd666f06c76bad1f3b89dc589ee9 100644 (file)
@@ -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(&regex->regex, str, flags) != 0) {
                memprintf(err, "regex '%s' is invalid", str);
                return 0;
        }