Skip to content

Commit b38147f

Browse files
authored
Remove PCRE references, complete migration to PCRE2 (#12685)
- Remove cmake/FindPCRE.cmake (no longer needed) - Update all CMakeLists.txt files to use PkgConfig::PCRE2 instead of PCRE::PCRE - Remove find_package(PCRE) from main CMakeLists.txt - Update code comments from PCRE to PCRE2 in plugin sources - Update coverity model from PCRE to PCRE2 API - Update README example to remove obsolete PCRE_ROOT reference - Update tools/hrw4u/src/lsp/documentation.py to reference PCRE2 - Note: cripts::Matcher::PCRE class name intentionally unchanged (public API) - Remove redundant PCRE2 links, use tsutil Regex wrapper - Use RE_ERROR_NOMATCH from tsutil instead of PCRE2_ERROR_NOMATCH in ControlMatcher to properly use the Regex wrapper - Remove direct pcre2.h include from ControlMatcher.h - Remove redundant PCRE2 links from components that get it transitively through tsutil (tscore, tsapi) - Remove redundant PCRE2 links from plugins that only use tsutil/Regex.h (cachekey, prefetch, slice, tls_bridge) Only components that directly use PCRE2 APIs (tsutil, cripts, txn_box) should explicitly link PCRE2. Others get it transitively through tsutil which publicly exports PCRE2.
1 parent 355a9ee commit b38147f

File tree

30 files changed

+81
-147
lines changed

30 files changed

+81
-147
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ if(LibLZMA_FOUND)
274274
set(HAVE_LZMA_H TRUE)
275275
endif()
276276

277-
find_package(PCRE REQUIRED)
278277
pkg_check_modules(PCRE2 REQUIRED IMPORTED_TARGET libpcre2-8)
279278

280279
include(CheckOpenSSLIsBoringSSL)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $ ccmake build
4747
To specify the location of a dependency (like `--with-*` for autotools builds), you generally set a variable with the `ROOT`. The big exception to this is for openssl. This variable is called `OPENSSL_ROOT_DIR`
4848

4949
```
50-
$ cmake -B build -Djemalloc_ROOT=/opt/jemalloc -DPCRE_ROOT=/opt/edge -DOPENSSL_ROOT_DIR=/opt/boringssl
50+
$ cmake -B build -Djemalloc_ROOT=/opt/jemalloc -DOPENSSL_ROOT_DIR=/opt/boringssl
5151
```
5252

5353
#### Using presets to configure the build

ci/coverity-model.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,15 @@
1616
limitations under the License.
1717
*/
1818

19-
// This is for PCRE, where the offsets vector is considered uninitialized, but it's an
19+
// This is for PCRE2, where the offsets vector is considered uninitialized, but it's an
2020
// output vector only (input doesn't matter).
2121
extern "C" {
22-
#define PCRE_SPTR const char *
23-
24-
struct real_pcre; /* declaration; the definition is private */
25-
typedef struct real_pcre pcre;
26-
27-
typedef struct pcre_extra {
28-
} pcre_extra;
22+
#define PCRE2_CODE_UNIT_WIDTH 8
23+
#include <pcre2.h>
2924

3025
int
31-
pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
32-
PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
33-
int offsetcount)
26+
pcre2_match(const pcre2_code *code, PCRE2_SPTR subject, PCRE2_SIZE length, PCRE2_SIZE startoffset, uint32_t options,
27+
pcre2_match_data *match_data, pcre2_match_context *mcontext)
3428
{
3529
__coverity_panic__();
3630
}

cmake/FindPCRE.cmake

Lines changed: 0 additions & 48 deletions
This file was deleted.

include/proxy/ControlMatcher.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@
9797
#include "tsutil/Regex.h"
9898
#include "proxy/hdrs/URL.h"
9999

100-
#define PCRE2_CODE_UNIT_WIDTH 8
101-
#include "pcre2.h"
102-
103100
#include <swoc/swoc_ip.h>
104101

105102
#ifdef HAVE_CTYPE_H

plugins/cachekey/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#######################
1717

1818
add_atsplugin(cachekey cachekey.cc common.cc configs.cc pattern.cc plugin.cc)
19-
20-
target_link_libraries(cachekey PRIVATE PCRE::PCRE)
2119
verify_global_plugin(cachekey)
2220
verify_remap_plugin(cachekey)
2321

@@ -26,6 +24,6 @@ if(BUILD_TESTING)
2624
add_executable(pattern_test unit_tests/pattern_test.cc pattern.cc common.cc)
2725
target_include_directories(pattern_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
2826
target_compile_definitions(pattern_test PRIVATE CACHEKEY_UNIT_TEST)
29-
target_link_libraries(pattern_test PRIVATE Catch2::Catch2WithMain PCRE::PCRE libswoc::libswoc ts::tsutil)
27+
target_link_libraries(pattern_test PRIVATE Catch2::Catch2WithMain libswoc::libswoc ts::tsutil)
3028
add_catch2_test(NAME pattern_test COMMAND pattern_test)
3129
endif()

plugins/cachekey/cachekey.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,8 @@ CacheKey::appendQuery(const ConfigQuery &config)
676676
/**
677677
* @brief Append User-Agent header captures specified in the Pattern configuration object.
678678
*
679-
* Apply given PCRE pattern/replacement to the first User-Agent value, and append any captured portions to cache key.
680-
* @param config PCRE pattern which contains capture groups.
679+
* Apply given PCRE2 pattern/replacement to the first User-Agent value, and append any captured portions to cache key.
680+
* @param config PCRE2 pattern which contains capture groups.
681681
* @todo: TBD if ignoring the comma in the header as a field separator is generic enough.
682682
* @note Add the UA captures to hier-part (RFC 3986) in the original order.
683683
*/

plugins/cachekey/pattern.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Pattern::empty() const
134134
* @brief Capture or capture-and-replace depending on whether a replacement string is specified.
135135
* @see replace()
136136
* @see capture()
137-
* @param subject PCRE subject string
137+
* @param subject PCRE2 subject string
138138
* @param result vector of strings where the result of captures or the replacements will be returned.
139139
* @return true if there was a match and capture or replacement succeeded, false if failure.
140140
*/

plugins/cachekey/unit_tests/pattern_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ TEST_CASE("Pattern compile and match behavior", "[cachekey][pattern]")
8383
{
8484
Pattern p;
8585
REQUIRE(p.init("^$"));
86-
// Pattern::match uses PCRE_NOTEMPTY which prevents empty-string matches.
86+
// Pattern::match uses PCRE2_NOTEMPTY which prevents empty-string matches.
8787
// Therefore '^$' will NOT match an empty subject with the current implementation.
8888
CHECK(p.match("") == false);
8989
CHECK(p.match("not-empty") == false);
@@ -92,7 +92,7 @@ TEST_CASE("Pattern compile and match behavior", "[cachekey][pattern]")
9292
SECTION("Case-insensitive inline flag")
9393
{
9494
Pattern p;
95-
// PCRE inline flag for case-insensitive
95+
// PCRE2 inline flag for case-insensitive
9696
REQUIRE(p.init("(?i)AbC"));
9797
CHECK(p.match("aBc") == true);
9898
CHECK(p.match("ABC") == true);

plugins/experimental/access_control/pattern.cc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Pattern::Pattern() : _pattern(""), _replacement("") {}
4545
Pattern::~Pattern() = default;
4646

4747
/**
48-
* @brief Initializes PCRE pattern by providing the subject and replacement strings.
49-
* @param pattern PCRE pattern, a string containing PCRE patterns, capturing groups.
50-
* @param replacement PCRE replacement, a string where $0 ... $9 will be replaced with the corresponding capturing groups
48+
* @brief Initializes PCRE2 pattern by providing the subject and replacement strings.
49+
* @param pattern PCRE2 pattern, a string containing PCRE2 patterns, capturing groups.
50+
* @param replacement PCRE2 replacement, a string where $0 ... $9 will be replaced with the corresponding capturing groups
5151
* @return true if successful, false if failure
5252
*/
5353
bool
@@ -69,9 +69,9 @@ Pattern::init(const String &pattern, const String &replacement, bool replace)
6969
}
7070

7171
/**
72-
* @brief Initializes PCRE pattern by providing the pattern only or pattern+replacement in a single configuration string.
72+
* @brief Initializes PCRE2 pattern by providing the pattern only or pattern+replacement in a single configuration string.
7373
* @see init()
74-
* @param config PCRE pattern <pattern> or PCRE pattern + replacement in format /<pattern>/<replacement>/
74+
* @param config PCRE2 pattern <pattern> or PCRE2 pattern + replacement in format /<pattern>/<replacement>/
7575
* @return true if successful, false if failure
7676
*/
7777
bool
@@ -145,14 +145,14 @@ Pattern::empty() const
145145
}
146146

147147
/**
148-
* @brief Destructor, frees PCRE related resources.
148+
* @brief Destructor, frees PCRE2 related resources.
149149
*/
150150

151151
/**
152152
* @brief Capture or capture-and-replace depending on whether a replacement string is specified.
153153
* @see replace()
154154
* @see capture()
155-
* @param subject PCRE subject string
155+
* @param subject PCRE2 subject string
156156
* @param result vector of strings where the result of captures or the replacements will be returned.
157157
* @return true if there was a match and capture or replacement succeeded, false if failure.
158158
*/
@@ -188,8 +188,8 @@ Pattern::process(const String &subject, StringVector &result)
188188
}
189189

190190
/**
191-
* @brief PCRE matches a subject string against the regex pattern.
192-
* @param subject PCRE subject
191+
* @brief PCRE2 matches a subject string against the regex pattern.
192+
* @param subject PCRE2 subject
193193
* @return true - matched, false - did not.
194194
*/
195195
bool
@@ -214,8 +214,8 @@ Pattern::match(const String &subject)
214214
}
215215

216216
/**
217-
* @brief Return all PCRE capture groups that matched in the subject string
218-
* @param subject PCRE subject string
217+
* @brief Return all PCRE2 capture groups that matched in the subject string
218+
* @param subject PCRE2 subject string
219219
* @param result reference to vector of strings containing all capture groups
220220
*/
221221
bool
@@ -249,8 +249,8 @@ Pattern::capture(const String &subject, StringVector &result)
249249
}
250250

251251
/**
252-
* @brief Replaces all replacements found in the replacement string with what matched in the PCRE capturing groups.
253-
* @param subject PCRE subject string
252+
* @brief Replaces all replacements found in the replacement string with what matched in the PCRE2 capturing groups.
253+
* @param subject PCRE2 subject string
254254
* @param result reference to A string where the result of the replacement will be stored
255255
* @return true - success, false - nothing matched or failure.
256256
*/
@@ -305,14 +305,14 @@ Pattern::replace(const String &subject, String &result)
305305
}
306306

307307
/**
308-
* @brief PCRE compiles the regex, called only during initialization.
308+
* @brief PCRE2 compiles the regex, called only during initialization.
309309
* @return true if successful, false if not.
310310
*/
311311
bool
312312
Pattern::compile()
313313
{
314-
std::string error; /* PCRE error description */
315-
int errOffset; /* PCRE error offset */
314+
std::string error; /* PCRE2 error description */
315+
int errOffset; /* PCRE2 error offset */
316316

317317
AccessControlDebug("compiling pattern:'%s', replace: %s, replacement:'%s'", _pattern.c_str(), _replace ? "true" : "false",
318318
_replacement.c_str());

0 commit comments

Comments
 (0)