mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
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.
This commit is contained in:
parent
7a00efbe43
commit
7cd8b6e3a4
78
include/haproxy/regex-t.h
Normal file
78
include/haproxy/regex-t.h
Normal file
@ -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:
|
||||
*/
|
@ -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 <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:
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include <haproxy/api.h>
|
||||
#include <haproxy/regex.h>
|
||||
#include <types/global.h>
|
||||
|
||||
#include <common/cfgparse.h>
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <haproxy/api.h>
|
||||
#include <haproxy/regex.h>
|
||||
#include <common/standard.h>
|
||||
|
||||
#include <types/applet.h>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user