This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 9f3f9c5bc9 Change map_with_referer to use Regex class instead of pcre
directly (#11294)
9f3f9c5bc9 is described below
commit 9f3f9c5bc9b3d0134e08007dca12785c34952ef3
Author: Bryan Call <[email protected]>
AuthorDate: Sun May 5 21:29:16 2024 -0700
Change map_with_referer to use Regex class instead of pcre directly (#11294)
---
include/proxy/http/remap/UrlMapping.h | 28 +++++++++++-----------------
src/proxy/http/remap/RemapProcessor.cc | 2 +-
src/proxy/http/remap/UrlMapping.cc | 20 +++++---------------
3 files changed, 17 insertions(+), 33 deletions(-)
diff --git a/include/proxy/http/remap/UrlMapping.h
b/include/proxy/http/remap/UrlMapping.h
index 3f17f87e69..a35b66f8c1 100644
--- a/include/proxy/http/remap/UrlMapping.h
+++ b/include/proxy/http/remap/UrlMapping.h
@@ -26,15 +26,8 @@
#include <vector>
-#if __has_include("pcre/pcre.h")
-#include <pcre/pcre.h>
-#elif __has_include("pcre.h")
-#include <pcre.h>
-#else
-#error "Unable to locate PCRE heeader"
-#endif
-
#include "tscore/ink_config.h"
+#include "tsutil/Regex.h"
#include "proxy/http/remap/AclFiltering.h"
#include "proxy/hdrs/URL.h"
#include "proxy/http/remap/RemapPluginInfo.h"
@@ -45,20 +38,21 @@
class NextHopSelectionStrategy;
/**
- * Used to store http referer strings (and/or regexp)
+ * Used to store http referrer strings (and/or regexp)
**/
class referer_info
{
public:
- referer_info(char *_ref, bool *error_flag = nullptr, char *errmsgbuf =
nullptr, int errmsgbuf_size = 0);
+ referer_info(const char *_ref, bool *error_flag, char *errmsgbuf = nullptr,
int errmsgbuf_size = 0);
~referer_info();
- referer_info *next;
- char *referer;
- int referer_size;
- bool any; /* any flag '*' */
- bool negative; /* negative referer '~' */
- bool regx_valid;
- pcre *regx;
+
+ referer_info *next = nullptr;
+ char *referer = nullptr;
+ int referer_size = 0;
+ bool any = false; /* any flag '*' */
+ bool negative = false; /* negative referer '~' */
+ bool regex_valid = false;
+ Regex regex;
};
/**
diff --git a/src/proxy/http/remap/RemapProcessor.cc
b/src/proxy/http/remap/RemapProcessor.cc
index dd15b6e729..1e54c5eb67 100644
--- a/src/proxy/http/remap/RemapProcessor.cc
+++ b/src/proxy/http/remap/RemapProcessor.cc
@@ -176,7 +176,7 @@ RemapProcessor::finish_remap(HttpTransact::State *s,
UrlRewrite *table)
if (!map->negative_referer) {
break;
}
- } else if (ri->regx_valid && (pcre_exec(ri->regx, nullptr,
tmp_referer_buf, referer_len, 0, 0, nullptr, 0) != -1)) {
+ } else if (ri->regex_valid &&
ri->regex.exec(std::string_view(tmp_referer_buf, referer_len))) {
enabled_flag = ri->negative ? false : true;
break;
}
diff --git a/src/proxy/http/remap/UrlMapping.cc
b/src/proxy/http/remap/UrlMapping.cc
index 0d68041fc0..0a3a85236e 100644
--- a/src/proxy/http/remap/UrlMapping.cc
+++ b/src/proxy/http/remap/UrlMapping.cc
@@ -156,16 +156,14 @@ redirect_tag_str::parse_format_redirect_url(char *url)
/**
*
**/
-referer_info::referer_info(char *_ref, bool *error_flag, char *errmsgbuf, int
errmsgbuf_size)
- : next(nullptr), referer(nullptr), referer_size(0), any(false),
negative(false), regx_valid(false)
+referer_info::referer_info(const char *_ref, bool *error_flag, char
*errmsgbuf, int errmsgbuf_size)
{
- const char *error;
+ std::string error;
int erroffset;
if (error_flag) {
*error_flag = false;
}
- regx = nullptr;
if (_ref) {
if (*_ref == '~') {
@@ -177,16 +175,14 @@ referer_info::referer_info(char *_ref, bool *error_flag,
char *errmsgbuf, int er
if (!strcmp(referer, "*")) {
any = true;
} else {
- regx = pcre_compile(referer, PCRE_CASELESS, &error, &erroffset,
nullptr);
- if (!regx) {
+ regex_valid = regex.compile(referer, error, erroffset,
RE_CASE_INSENSITIVE);
+ if (regex_valid == false) {
if (errmsgbuf && (errmsgbuf_size - 1) > 0) {
- ink_strlcpy(errmsgbuf, error, errmsgbuf_size);
+ ink_strlcpy(errmsgbuf, error.c_str(), errmsgbuf_size);
}
if (error_flag) {
*error_flag = true;
}
- } else {
- regx_valid = true;
}
}
}
@@ -201,10 +197,4 @@ referer_info::~referer_info()
ats_free(referer);
referer = nullptr;
referer_size = 0;
-
- if (regx_valid) {
- pcre_free(regx);
- regx = nullptr;
- regx_valid = false;
- }
}