From 7cd8b6e3a40fe62b4ce37ccfc7e1b3327d9b07af Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 2 Jun 2020 17:32:26 +0200 Subject: [PATCH] REORG: include: split common/regex.h into haproxy/regex{,-t}.h Regex are essentially included for myregex_t but it turns out that several of the C files didn't include it directly, relying on the one included by their own .h. This has been cleanly addressed so that only the type is included by H files which need it, and adding the missing includes for the other ones. --- include/haproxy/regex-t.h | 78 +++++++++++++++++++++++++++++ include/{common => haproxy}/regex.h | 72 +++++++------------------- include/proto/http_htx.h | 2 +- include/types/action.h | 2 +- include/types/checks.h | 2 +- include/types/fcgi-app.h | 2 +- include/types/hlua.h | 2 +- include/types/pattern.h | 2 +- include/types/peers.h | 1 - include/types/proxy.h | 1 - src/checks.c | 1 + src/fcgi-app.c | 1 + src/haproxy.c | 2 +- src/hlua.c | 1 + src/hlua_fcn.c | 1 + src/http_act.c | 1 + src/http_ana.c | 1 + src/http_htx.c | 1 + src/map.c | 1 + src/mux_fcgi.c | 1 + src/pattern.c | 1 + src/regex.c | 2 +- src/sample.c | 1 + 23 files changed, 115 insertions(+), 64 deletions(-) create mode 100644 include/haproxy/regex-t.h rename include/{common => haproxy}/regex.h (78%) diff --git a/include/haproxy/regex-t.h b/include/haproxy/regex-t.h new file mode 100644 index 0000000000..7b7fa03e8c --- /dev/null +++ b/include/haproxy/regex-t.h @@ -0,0 +1,78 @@ +/* + * include/haproxy/regex-t.h + * Types and macros definitions for regular expressions + * + * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, version 2.1 + * exclusively. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _HAPROXY_REGEX_T_H +#define _HAPROXY_REGEX_T_H + +#include +#include + +#include +#include + +#ifdef USE_PCRE +#include +#include + +/* For pre-8.20 PCRE compatibility */ +#ifndef PCRE_STUDY_JIT_COMPILE +#define PCRE_STUDY_JIT_COMPILE 0 +#endif + +#elif USE_PCRE2 +#include +#include + +#else /* no PCRE, nor PCRE2 */ +#include +#endif + +struct my_regex { +#ifdef USE_PCRE + pcre *reg; + pcre_extra *extra; +#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 +#endif +#elif USE_PCRE2 + pcre2_code *reg; +#else /* no PCRE */ + regex_t regex; +#endif +}; + +struct hdr_exp { + struct hdr_exp *next; + struct my_regex *preg; /* expression to look for */ + const char *replace; /* expression to set instead */ + void *cond; /* a possible condition or NULL */ +}; + +#endif /* _HAPROXY_REGEX_T_H */ + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/include/common/regex.h b/include/haproxy/regex.h similarity index 78% rename from include/common/regex.h rename to include/haproxy/regex.h index 79e54ff12d..6d84ea6138 100644 --- a/include/common/regex.h +++ b/include/haproxy/regex.h @@ -1,8 +1,8 @@ /* - * include/common/regex.h - * This file defines everything related to regular expressions. + * include/haproxy/regex.h + * Compatibility layer for various regular expression engines * - * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu + * Copyright (C) 2000-2020 Willy Tarreau - w@1wt.eu * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -19,55 +19,16 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _COMMON_REGEX_H -#define _COMMON_REGEX_H +#ifndef _HAPROXY_REGEX_H +#define _HAPROXY_REGEX_H #include #include #include +#include #include -#ifdef USE_PCRE -#include -#include - -/* For pre-8.20 PCRE compatibility */ -#ifndef PCRE_STUDY_JIT_COMPILE -#define PCRE_STUDY_JIT_COMPILE 0 -#endif - -#elif USE_PCRE2 -#include -#include - -#else /* no PCRE, nor PCRE2 */ -#include -#endif - -struct my_regex { -#ifdef USE_PCRE - pcre *reg; - pcre_extra *extra; -#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 -#endif -#elif USE_PCRE2 - pcre2_code *reg; -#else /* no PCRE */ - regex_t regex; -#endif -}; - -struct hdr_exp { - struct hdr_exp *next; - struct my_regex *preg; /* expression to look for */ - const char *replace; /* expression to set instead */ - void *cond; /* a possible condition or NULL */ -}; - extern THREAD_LOCAL regmatch_t pmatch[MAX_MATCH]; /* "str" is the string that contain the regex to compile. @@ -83,10 +44,16 @@ extern THREAD_LOCAL regmatch_t pmatch[MAX_MATCH]; struct my_regex *regex_comp(const char *str, int cs, int cap, char **err); int exp_replace(char *dst, unsigned int dst_size, char *src, const char *str, const regmatch_t *matches); const char *check_replace_string(const char *str); +int regex_exec_match(const struct my_regex *preg, const char *subject, + size_t nmatch, regmatch_t pmatch[], int flags); +int regex_exec_match2(const struct my_regex *preg, char *subject, int length, + size_t nmatch, regmatch_t pmatch[], int flags); + /* If the function doesn't match, it returns false, else it returns true. */ -static inline int regex_exec(const struct my_regex *preg, char *subject) { +static inline int regex_exec(const struct my_regex *preg, char *subject) +{ #if defined(USE_PCRE) || defined(USE_PCRE_JIT) if (pcre_exec(preg->reg, preg->extra, subject, strlen(subject), 0, 0, NULL, 0) < 0) return 0; @@ -117,7 +84,8 @@ static inline int regex_exec(const struct my_regex *preg, char *subject) { * * If the function doesn't match, it returns false, else it returns true. */ -static inline int regex_exec2(const struct my_regex *preg, char *subject, int length) { +static inline int regex_exec2(const struct my_regex *preg, char *subject, int length) +{ #if defined(USE_PCRE) || defined(USE_PCRE_JIT) if (pcre_exec(preg->reg, preg->extra, subject, length, 0, 0, NULL, 0) < 0) return 0; @@ -145,12 +113,8 @@ static inline int regex_exec2(const struct my_regex *preg, char *subject, int le #endif } -int regex_exec_match(const struct my_regex *preg, const char *subject, - size_t nmatch, regmatch_t pmatch[], int flags); -int regex_exec_match2(const struct my_regex *preg, char *subject, int length, - size_t nmatch, regmatch_t pmatch[], int flags); - -static inline void regex_free(struct my_regex *preg) { +static inline void regex_free(struct my_regex *preg) +{ if (!preg) return; #if defined(USE_PCRE) || defined(USE_PCRE_JIT) @@ -171,7 +135,7 @@ static inline void regex_free(struct my_regex *preg) { free(preg); } -#endif /* _COMMON_REGEX_H */ +#endif /* _HAPROXY_REGEX_H */ /* * Local variables: diff --git a/include/proto/http_htx.h b/include/proto/http_htx.h index 77e4d6753f..d480be8680 100644 --- a/include/proto/http_htx.h +++ b/include/proto/http_htx.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include diff --git a/include/types/action.h b/include/types/action.h index 00c37fa6a2..a102b2b927 100644 --- a/include/types/action.h +++ b/include/types/action.h @@ -22,7 +22,7 @@ #ifndef _TYPES_ACTION_H #define _TYPES_ACTION_H -#include +#include #include #include diff --git a/include/types/checks.h b/include/types/checks.h index 243a1ef030..075e9022f2 100644 --- a/include/types/checks.h +++ b/include/types/checks.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include diff --git a/include/types/fcgi-app.h b/include/types/fcgi-app.h index c88dda3d0b..72219e9427 100644 --- a/include/types/fcgi-app.h +++ b/include/types/fcgi-app.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include diff --git a/include/types/hlua.h b/include/types/hlua.h index 28ed9bd491..10a33036cf 100644 --- a/include/types/hlua.h +++ b/include/types/hlua.h @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include diff --git a/include/types/pattern.h b/include/types/pattern.h index aa3ab24ed1..0baf3d795a 100644 --- a/include/types/pattern.h +++ b/include/types/pattern.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include diff --git a/include/types/peers.h b/include/types/peers.h index 4bd06802ad..8961d7e97d 100644 --- a/include/types/peers.h +++ b/include/types/peers.h @@ -29,7 +29,6 @@ #include #include -#include #include #include diff --git a/include/types/proxy.h b/include/types/proxy.h index 4e095efc0f..2e6a26cd84 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -31,7 +31,6 @@ #include #include #include -#include #include #include diff --git a/src/checks.c b/src/checks.c index 45de864c3f..2374f65e7e 100644 --- a/src/checks.c +++ b/src/checks.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include diff --git a/src/fcgi-app.c b/src/fcgi-app.c index f0889001af..eb78807b96 100644 --- a/src/fcgi-app.c +++ b/src/fcgi-app.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/src/haproxy.c b/src/haproxy.c index 36f669419a..684ee2217a 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -91,7 +91,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/hlua.c b/src/hlua.c index 06c45b6c15..5513a7dcd6 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index 3f833a0c0a..53a2b4039a 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/src/http_act.c b/src/http_act.c index c2e3857371..4193b91c10 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include diff --git a/src/http_ana.c b/src/http_ana.c index 2c44a481ba..9f65082777 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include diff --git a/src/http_htx.c b/src/http_htx.c index 38a91cc419..af8758c992 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -15,6 +15,7 @@ #include #include +#include #include #include diff --git a/src/map.c b/src/map.c index 5f98dd0a00..771fcc8130 100644 --- a/src/map.c +++ b/src/map.c @@ -13,6 +13,7 @@ #include #include +#include #include #include diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index d8b38215eb..364e5cf477 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/src/pattern.c b/src/pattern.c index b948c6f393..f2692f0df0 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -16,6 +16,7 @@ #include #include +#include #include #include diff --git a/src/regex.c b/src/regex.c index fa1c91b45c..764704da11 100644 --- a/src/regex.c +++ b/src/regex.c @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include diff --git a/src/sample.c b/src/sample.c index 9470a8bc6e..14615a1ba1 100644 --- a/src/sample.c +++ b/src/sample.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include -- 2.47.2