mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 15:47:01 +02:00
MINOR: regex: Copy the original regex expression into string.
This is useful for the debug or for search regex in maps.
This commit is contained in:
parent
799c042daa
commit
39e258fcee
@ -47,6 +47,7 @@ struct my_regex {
|
|||||||
#else /* no PCRE */
|
#else /* no PCRE */
|
||||||
regex_t regex;
|
regex_t regex;
|
||||||
#endif
|
#endif
|
||||||
|
char *regstr; /* this contain the original string */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* what to do when a header matches a regex */
|
/* what to do when a header matches a regex */
|
||||||
@ -108,6 +109,8 @@ static inline void regex_free(struct my_regex *preg) {
|
|||||||
#else
|
#else
|
||||||
regfree(&preg->regex);
|
regfree(&preg->regex);
|
||||||
#endif
|
#endif
|
||||||
|
free(preg->regstr);
|
||||||
|
preg->regstr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* _COMMON_REGEX_H */
|
#endif /* _COMMON_REGEX_H */
|
||||||
|
10
src/regex.c
10
src/regex.c
@ -124,6 +124,13 @@ const char *chain_regex(struct hdr_exp **head, const regex_t *preg,
|
|||||||
|
|
||||||
int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **err)
|
int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **err)
|
||||||
{
|
{
|
||||||
|
/* copy the original regex format */
|
||||||
|
regex->regstr = strdup(str);
|
||||||
|
if (!regex->regstr) {
|
||||||
|
memprintf(err, "out of memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_PCRE_JIT
|
#ifdef USE_PCRE_JIT
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
const char *error;
|
const char *error;
|
||||||
@ -136,12 +143,14 @@ int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **
|
|||||||
|
|
||||||
regex->reg = pcre_compile(str, flags, &error, &erroffset, NULL);
|
regex->reg = pcre_compile(str, flags, &error, &erroffset, NULL);
|
||||||
if (!regex->reg) {
|
if (!regex->reg) {
|
||||||
|
free(regex->regstr);
|
||||||
memprintf(err, "regex '%s' is invalid (error=%s, erroffset=%d)", str, error, erroffset);
|
memprintf(err, "regex '%s' is invalid (error=%s, erroffset=%d)", str, error, erroffset);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
regex->extra = pcre_study(regex->reg, PCRE_STUDY_JIT_COMPILE, &error);
|
regex->extra = pcre_study(regex->reg, PCRE_STUDY_JIT_COMPILE, &error);
|
||||||
if (!regex->extra) {
|
if (!regex->extra) {
|
||||||
|
free(regex->regstr);
|
||||||
pcre_free(regex->reg);
|
pcre_free(regex->reg);
|
||||||
memprintf(err, "failed to compile regex '%s' (error=%s)", str, error);
|
memprintf(err, "failed to compile regex '%s' (error=%s)", str, error);
|
||||||
return 0;
|
return 0;
|
||||||
@ -155,6 +164,7 @@ int regex_comp(const char *str, struct my_regex *regex, int cs, int cap, char **
|
|||||||
flags |= REG_NOSUB;
|
flags |= REG_NOSUB;
|
||||||
|
|
||||||
if (regcomp(®ex->regex, str, flags) != 0) {
|
if (regcomp(®ex->regex, str, flags) != 0) {
|
||||||
|
free(regex->regstr);
|
||||||
memprintf(err, "regex '%s' is invalid", str);
|
memprintf(err, "regex '%s' is invalid", str);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user