]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: include: split common/regex.h into haproxy/regex{,-t}.h
authorWilly Tarreau <w@1wt.eu>
Tue, 2 Jun 2020 15:32:26 +0000 (17:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 11 Jun 2020 08:18:57 +0000 (10:18 +0200)
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.

23 files changed:
include/haproxy/regex-t.h [new file with mode: 0644]
include/haproxy/regex.h [moved from include/common/regex.h with 78% similarity]
include/proto/http_htx.h
include/types/action.h
include/types/checks.h
include/types/fcgi-app.h
include/types/hlua.h
include/types/pattern.h
include/types/peers.h
include/types/proxy.h
src/checks.c
src/fcgi-app.c
src/haproxy.c
src/hlua.c
src/hlua_fcn.c
src/http_act.c
src/http_ana.c
src/http_htx.c
src/map.c
src/mux_fcgi.c
src/pattern.c
src/regex.c
src/sample.c

diff --git a/include/haproxy/regex-t.h b/include/haproxy/regex-t.h
new file mode 100644 (file)
index 0000000..7b7fa03
--- /dev/null
@@ -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 <stdlib.h>
+#include <string.h>
+
+#include <haproxy/api.h>
+#include <haproxy/thread-t.h>
+
+#ifdef USE_PCRE
+#include <pcre.h>
+#include <pcreposix.h>
+
+/* For pre-8.20 PCRE compatibility */
+#ifndef PCRE_STUDY_JIT_COMPILE
+#define PCRE_STUDY_JIT_COMPILE 0
+#endif
+
+#elif USE_PCRE2
+#include <pcre2.h>
+#include <pcre2posix.h>
+
+#else /* no PCRE, nor PCRE2 */
+#include <regex.h>
+#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:
+ */
similarity index 78%
rename from include/common/regex.h
rename to include/haproxy/regex.h
index 79e54ff12d4a3f22ad3c59875246fb10b06b3e57..6d84ea6138bebf2b82f283f178558b5ca290e2ee 100644 (file)
@@ -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
  * 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 <stdlib.h>
 #include <string.h>
 
 #include <haproxy/api.h>
+#include <haproxy/regex-t.h>
 #include <haproxy/thread-t.h>
 
-#ifdef USE_PCRE
-#include <pcre.h>
-#include <pcreposix.h>
-
-/* For pre-8.20 PCRE compatibility */
-#ifndef PCRE_STUDY_JIT_COMPILE
-#define PCRE_STUDY_JIT_COMPILE 0
-#endif
-
-#elif USE_PCRE2
-#include <pcre2.h>
-#include <pcre2posix.h>
-
-#else /* no PCRE, nor PCRE2 */
-#include <regex.h>
-#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:
index 77e4d6753fa13424a1b71d8d4992f6b5d79fbe92..d480be868067a2295071dd269c701deec38f3cac 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <haproxy/buf.h>
 #include <import/ist.h>
-#include <common/regex.h>
+#include <haproxy/regex-t.h>
 
 #include <types/http_htx.h>
 
index 00c37fa6a2d13a5b18ce24ad151a1555ff730733..a102b2b927f09eef5a63240ba00972cf469d9971 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef _TYPES_ACTION_H
 #define _TYPES_ACTION_H
 
-#include <common/regex.h>
+#include <haproxy/regex-t.h>
 
 #include <types/applet.h>
 #include <types/stick_table.h>
index 243a1ef0303e7333bbd0558d586298ecb1489710..075e9022f2206bde4af3e3a62122c98de7fb4500 100644 (file)
@@ -18,7 +18,7 @@
 
 #include <import/ist.h>
 #include <haproxy/list-t.h>
-#include <common/regex.h>
+#include <haproxy/regex-t.h>
 #include <haproxy/buf-t.h>
 
 #include <types/connection.h>
index c88dda3d0b1154ca584fd76d84782e311782ddb7..72219e9427bce2978c932223b73c11d72db4efac 100644 (file)
@@ -26,7 +26,7 @@
 #include <import/ist.h>
 #include <common/fcgi.h>
 #include <haproxy/list-t.h>
-#include <common/regex.h>
+#include <haproxy/regex-t.h>
 
 #include <import/ebistree.h>
 
index 28ed9bd4911797dd06cdac481eba8de9389ff9b8..10a33036cf5632cf10fe5a1a20ce3bb3bbf43e30 100644 (file)
@@ -6,7 +6,7 @@
 #include <lua.h>
 #include <lauxlib.h>
 
-#include <common/regex.h>
+#include <haproxy/regex-t.h>
 #include <common/xref.h>
 
 #include <types/http_ana.h>
index aa3ab24ed197c222b98f3ad3b630d554a27620e2..0baf3d795afe142850d17a84eed77f0647f9e88b 100644 (file)
@@ -24,7 +24,7 @@
 
 #include <haproxy/api-t.h>
 #include <haproxy/list-t.h>
-#include <common/regex.h>
+#include <haproxy/regex-t.h>
 
 #include <types/sample.h>
 
index 4bd06802adfe6174e7933a247afd1a3eb3274f29..8961d7e97d13ca89c42edaee4b49a8be2396e4c7 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <haproxy/api-t.h>
 #include <haproxy/list-t.h>
-#include <common/regex.h>
 #include <import/eb32tree.h>
 
 #include <types/dict.h>
index 4e095efc0f4eed2d8eeefea268f98c00958df9d5..2e6a26cd845cce1b4906e11409b5b5898f2dad2f 100644 (file)
@@ -31,7 +31,6 @@
 #include <haproxy/chunk.h>
 #include <common/http.h>
 #include <haproxy/list-t.h>
-#include <common/regex.h>
 #include <haproxy/thread.h>
 
 #include <import/eb32tree.h>
index 45de864c3f87b80f8db8efe1ad3f165a2c0b87b0..2374f65e7e62ee6523a5754a21db3c89a07ac6ad 100644 (file)
@@ -35,6 +35,7 @@
 #include <haproxy/chunk.h>
 #include <haproxy/istbuf.h>
 #include <haproxy/list.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 #include <haproxy/time.h>
 #include <haproxy/thread.h>
index f0889001af79e6782dc579cc3cd9ab970994a650..eb78807b968c40a528da7d0818f8a6eba68f0bd7 100644 (file)
@@ -14,6 +14,7 @@
 #include <haproxy/chunk.h>
 #include <common/cfgparse.h>
 #include <haproxy/errors.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 
 #include <types/global.h>
index 36f669419a04b61a23ddfb929e89545a0a7f7e6b..684ee2217aaafd6076760e27ab337a575c89bad1 100644 (file)
@@ -91,7 +91,7 @@
 #include <haproxy/namespace.h>
 #include <haproxy/net_helper.h>
 #include <haproxy/openssl-compat.h>
-#include <common/regex.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 #include <haproxy/time.h>
 #include <common/uri_auth.h>
index 06c45b6c156212a7085ec8c0aa562bc14f7e4b0e..5513a7dcd6c0230965e1a8fa22120b7ec3deed1f 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <common/cfgparse.h>
 #include <haproxy/thread.h>
+#include <haproxy/regex.h>
 #include <common/xref.h>
 #include <common/h1.h>
 #include <common/standard.h>
index 3f833a0c0a8da6f404eecb2502c95b9fc0f1c50f..53a2b4039a19bdec95ba2135caee79cee728c9cb 100644 (file)
@@ -19,6 +19,7 @@
 #include <lualib.h>
 
 #include <haproxy/net_helper.h>
+#include <haproxy/regex.h>
 #include <haproxy/time.h>
 #include <common/uri_auth.h>
 
index c2e3857371dbfc23dfbf6fc686b8af582cdfd2ea..4193b91c102a8531423fea7626dfdad84ce823df 100644 (file)
@@ -21,6 +21,7 @@
 #include <haproxy/chunk.h>
 #include <common/http.h>
 #include <haproxy/pool.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 #include <common/uri_auth.h>
 #include <haproxy/version.h>
index 2c44a481baf7dee407d4dc0b30ef84b22b5ad5ef..9f6508277778def153ec704bddbfadaa7f20aeae 100644 (file)
@@ -14,6 +14,7 @@
 #include <haproxy/base64.h>
 #include <common/htx.h>
 #include <haproxy/net_helper.h>
+#include <haproxy/regex.h>
 #include <common/uri_auth.h>
 
 #include <types/capture.h>
index 38a91cc41937cd1827d2a35549d2e0b0a9677fa2..af8758c992d6f7b80148e75d6ed7e870d3cdccfc 100644 (file)
@@ -15,6 +15,7 @@
 #include <unistd.h>
 
 #include <haproxy/api.h>
+#include <haproxy/regex.h>
 #include <types/global.h>
 
 #include <common/cfgparse.h>
index 5f98dd0a00541cfbc0981f84a513ecb7bf559a0c..771fcc81309abdaa5c346b60d5e82323b70593bf 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -13,6 +13,7 @@
 #include <stdio.h>
 
 #include <haproxy/api.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 
 #include <types/applet.h>
index d8b38215eb400dfac4f33ac8dd6333de8c9bc521..364e5cf477a6edfdc931ad135da045e8218aab65 100644 (file)
@@ -18,6 +18,7 @@
 #include <import/ist.h>
 #include <haproxy/list.h>
 #include <haproxy/net_helper.h>
+#include <haproxy/regex.h>
 
 #include <types/proxy.h>
 #include <types/session.h>
index b948c6f3938c2869d8a22b9f43ea21ad587114f6..f2692f0df066d7106c37640dec6144a443c0a415 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <haproxy/api.h>
 #include <haproxy/net_helper.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 
 #include <types/global.h>
index fa1c91b45c729d1913b21ae02c4724e72061036d..764704da110ba4892435ecc55d5aca042830ce63 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <haproxy/api.h>
 #include <types/global.h>
-#include <common/regex.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 #include <proto/log.h>
 
index 9470a8bc6e5e0ebec558f9495b3661eb7431aa8e..14615a1ba1ec33563b87bccac7356a29f9cf98a9 100644 (file)
@@ -23,6 +23,7 @@
 #include <haproxy/hash.h>
 #include <common/http.h>
 #include <haproxy/net_helper.h>
+#include <haproxy/regex.h>
 #include <common/standard.h>
 #include <common/uri_auth.h>
 #include <haproxy/base64.h>