]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
C++11: Remove GnuRegex and all -lregex related code
authorAmos Jeffries <squid3@treenet.co.nz>
Sun, 20 Nov 2016 09:12:00 +0000 (22:12 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Sun, 20 Nov 2016 09:12:00 +0000 (22:12 +1300)
Squid is now exclusively using the STL std::regex API provided on all
operating systems in a portable manner.

We no longer have any need of detecting if the system is providing a
libregex, or user has configured one, or if it actually works, or how
to call it, or use the GnuRegex code as a backup when one of those
complex details goes wrong.

22 files changed:
1  2 
CREDITS
acinclude/lib-checks.m4
compat/Makefile.am
compat/compat.h
configure.ac
doc/release-notes/release-5.sgml
squid3.dox
src/Makefile.am
src/acl/RegexData.cc
src/base/RegexPattern.cc
src/base/RegexPattern.h
src/cache_cf.cc
src/clients/FtpGateway.cc
src/mgr/QueryParams.cc
src/mime.cc
src/refresh.cc
test-suite/buildtests/layer-01-minimal.opts
test-suite/buildtests/layer-02-maximus.opts
test-suite/buildtests/layer-04-noauth-everything.opts
test-suite/squidconf/regex
tools/purge/conffile.cc
tools/purge/purge.cc

diff --cc CREDITS
Simple merge
Simple merge
Simple merge
diff --cc compat/compat.h
Simple merge
diff --cc configure.ac
Simple merge
index ac4dafd670afdf61ea4614ac087d5ce820664696,0000000000000000000000000000000000000000..e0ed556382563b512dcf825cf8dc20fff15f2217
mode 100644,000000..100644
--- /dev/null
@@@ -1,193 -1,0 +1,214 @@@
-       <p>No changes to existing directives in this version.
 +<!doctype linuxdoc system>
 +<article>
 +<title>Squid 5.0.0 release notes</title>
 +<author>Squid Developers</author>
 +
 +<abstract>
 +This document contains the release notes for version 4 of Squid.
 +Squid is a WWW Cache application developed by the National Laboratory
 +for Applied Network Research and members of the Web Caching community.
 +</abstract>
 +
 +<toc>
 +
 +<sect>Notice
 +<p>The Squid Team are pleased to announce the release of Squid-5.0.0 for testing.
 +
 +This new release is available for download from <url url="http://www.squid-cache.org/Versions/v5/"> or the
 + <url url="http://www.squid-cache.org/Download/http-mirrors.html" name="mirrors">.
 +
 +<p>While this release is not deemed ready for production use, we believe it is ready for wider testing by the community.
 +
 +<p>We welcome feedback and bug reports. If you find a bug, please see <url url="http://wiki.squid-cache.org/SquidFaq/BugReporting">
 +   for how to submit a report with a stack trace.
 +
 +<sect1>Known issues
 +<p>Although this release is deemed good enough for use in many setups, please note the existence of 
 +<url url="http://bugs.squid-cache.org/buglist.cgi?query_format=advanced&amp;product=Squid&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;version=5" name="open bugs against Squid-5">.
 +
 +<sect1>Changes since earlier releases of Squid-5
 +<p>
 +The Squid-4 change history can be <url url="http://www.squid-cache.org/Versions/v5/changesets/" name="viewed here">.
 +
 +
 +<sect>Major new features since Squid-4
 +<p>Squid-5 represents a new feature release above Squid-4.
 +
 +<p>The most important of these new features are:
 +<itemize>
 +      <item>ICAP Trailers
 +</itemize>
 +
 +Most user-facing changes are reflected in squid.conf (see below).
 +
 +
 +<sect1>ICAP Trailers
 +<p>Details in <url url="https://datatracker.ietf.org/doc/draft-rousskov-icap-trailers/" name="Draft: ICAP Trailers">
 +
 +<p>The <em>Trailers</em> feature from HTTP is being proposed for addition to ICAP,
 +   with some modifications.
 +
 +<p>This implementation complies with version -01 of that draft:
 +<itemize>
 +      <item>Announces ICAP Trailer support via the ICAP Allow request header field.
 +      <item>Parses the ICAP response trailer if and only if the ICAP server signals
 +              its presence by sending both Trailer header and Allow/trailers in the
 +              ICAP response.
 +</itemize>
 +
 +<p>For now Squid logs and ignores all parsed ICAP header fields.
 +
 +
 +<sect>Changes to squid.conf since Squid-4
 +<p>
 +There have been changes to Squid's configuration file since Squid-4.
 +
 +This section gives a thorough account of those changes in three categories:
 +
 +<itemize>
 +      <item><ref id="newdirectives" name="New directives">
 +      <item><ref id="modifieddirectives" name="Changes to existing directives">
 +      <item><ref id="removeddirectives" name="Removed directives">
 +</itemize>
 +<p>
 +
 +<sect1>New directives<label id="newdirectives">
 +<p>
 +<descrip>
 +      <p>No new directives in this version.
 +
 +</descrip>
 +
 +<sect1>Changes to existing directives<label id="modifieddirectives">
 +<p>
 +<descrip>
-       <p>No removed options in this version.
++      <tag>acl</tag>
++      <p>Due to differences between GNU Regex and libc regular expressions
++         patterns escaping the double quote (") character escaped by a slash (\)
++         will now be rejected. Use without the escaping is still accepted.
++         This affects all *_regex and regular expression based ACL types.
++
++      <tag>refresh_pattern</tag>
++      <p>Due to differences between GNU Regex and libc regular expressions
++         patterns escaping the double quote (") character with a slash (\)
++         will now be rejected. Use without the escaping is still accepted.
 +
 +</descrip>
 +
 +<sect1>Removed directives<label id="removeddirectives">
 +<p>
 +<descrip>
 +      <p>No removed directives in this version.
 +
 +</descrip>
 +
 +
 +<sect>Changes to ./configure options since Squid-4
 +<p>
 +There have been some changes to Squid's build configuration since Squid-4.
 +
 +This section gives an account of those changes in three categories:
 +
 +<itemize>
 +      <item><ref id="newoptions" name="New options">
 +      <item><ref id="modifiedoptions" name="Changes to existing options">
 +      <item><ref id="removedoptions" name="Removed options">
 +</itemize>
 +
 +
 +<sect1>New options<label id="newoptions">
 +<p>
 +<descrip>
 +      <p>No new options in this version.
 +
 +</descrip>
 +
 +<sect1>Changes to existing options<label id="modifiedoptions">
 +<p>
 +<descrip>
 +      <p>No changes to existing options in this version.
 +
 +</descrip>
 +</p>
 +
 +<sect1>Removed options<label id="removedoptions">
 +<p>
 +<descrip>
++      <tag>--enable-gnuregex</tag>
++      <p>Squid now uses C++11 std::regex instead of GNU Regex. Removed.
++
++      <tag>LDFLAGS</tag>
++      <p>Squid now uses C++11 std::regex API instead of the C regex.h API.
++         This means that linker overrides for -lregex and regex.h no longer exist.
++      <p>Custom regex libraries need to provide bindings for the std::regex
++         API to link with Squid. This may require additional -I path to be
++         provided in CXXFLAGS to the library headers. Refer to the chosen
++         library documentation for more details.
++      <p>Note that popular modern high performance regex libraries should
++         already be used by the STL internal implementation and no longer
++         need manually linking.
 +
 +</descrip>
 +
 +
 +<sect>Regressions since Squid-2.7
 +
 +<p>Some squid.conf options which were available in Squid-2.7 are not yet available in Squid-5
 +
 +<p>If you need something to do then porting one of these from Squid-2 is most welcome.
 +
 +<sect1>Missing squid.conf options available in Squid-2.7
 +<p>
 +<descrip>
 +      <tag>broken_vary_encoding</tag>
 +      <p>Not yet ported from 2.6
 +
 +      <tag>cache_peer</tag>
 +      <p><em>monitorinterval=</em> not yet ported from 2.6
 +      <p><em>monitorsize=</em> not yet ported from 2.6
 +      <p><em>monitortimeout=</em> not yet ported from 2.6
 +      <p><em>monitorurl=</em> not yet ported from 2.6
 +
 +      <tag>cache_vary</tag>
 +      <p>Not yet ported from 2.6
 +
 +      <tag>error_map</tag>
 +      <p>Not yet ported from 2.6
 +
 +      <tag>external_refresh_check</tag>
 +      <p>Not yet ported from 2.7
 +
 +      <tag>location_rewrite_access</tag>
 +      <p>Not yet ported from 2.6
 +
 +      <tag>location_rewrite_children</tag>
 +      <p>Not yet ported from 2.6
 +
 +      <tag>location_rewrite_concurrency</tag>
 +      <p>Not yet ported from 2.6
 +
 +      <tag>location_rewrite_program</tag>
 +      <p>Not yet ported from 2.6
 +
 +      <tag>refresh_pattern</tag>
 +      <p><em>stale-while-revalidate=</em> not yet ported from 2.7
 +      <p><em>ignore-stale-while-revalidate=</em> not yet ported from 2.7
 +      <p><em>negative-ttl=</em> not yet ported from 2.7
 +
 +      <tag>refresh_stale_hit</tag>
 +      <p>Not yet ported from 2.7
 +
 +      <tag>update_headers</tag>
 +      <p>Not yet ported from 2.7
 +
 +</descrip>
 +
 +<sect>Copyright
 +<p>
 +Copyright (C) 1996-2016 The Squid Software Foundation and contributors
 +<p>
 +Squid software is distributed under GPLv2+ license and includes
 +contributions from numerous individuals and organizations.
 +Please see the COPYING and CONTRIBUTORS files for details.
 +
 +</article>
diff --cc squid3.dox
Simple merge
diff --cc src/Makefile.am
index f8a8a6d6b56c9f9fd9501cdc794ed0e5fb2e6ba4,633f266b60d9e7fa1282b319158e9dd4112abb1a..2e1c7923e79be96e0189737c6560451af02f555c
@@@ -1146,9 -1187,8 +1144,8 @@@ tests_testACLMaxUserIP_LDADD= 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
        $(SSLLIB) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testACLMaxUserIP_LDFLAGS = $(LIBADD_DL)
@@@ -1419,10 -1447,10 +1416,9 @@@ tests_testCacheManager_LDADD = 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
 -      $(SQUID_CPPUNIT_LA) \
        $(SSLLIB) \
        $(KRB5LIBS) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testCacheManager_LDFLAGS = $(LIBADD_DL)
@@@ -1593,11 -1624,11 +1589,10 @@@ tests_testDiskIO_LDADD = 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
        $(SSLLIB) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
 -
  tests_testDiskIO_LDFLAGS = $(LIBADD_DL)
  tests_testDiskIO_DEPENDENCIES = \
        DiskIO/libdiskio.la \
@@@ -1844,14 -1880,12 +1839,13 @@@ tests_testEvent_LDADD = 
        $(top_builddir)/lib/libmiscutil.la \
        ipc/libipc.la \
        mgr/libmgr.la \
 +      store/libstore.la \
 +      sbuf/libsbuf.la \
        $(SNMP_LIBS) \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
 -      $(SQUID_CPPUNIT_LA) \
        $(SSLLIB) \
        $(KRB5LIBS) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testEvent_LDFLAGS = $(LIBADD_DL)
@@@ -2080,14 -2121,12 +2074,13 @@@ tests_testEventLoop_LDADD = 
        $(top_builddir)/lib/libmiscutil.la \
        ipc/libipc.la \
        mgr/libmgr.la \
 +      sbuf/libsbuf.la \
 +      store/libstore.la \
        $(SNMP_LIBS) \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
 -      $(SQUID_CPPUNIT_LA) \
        $(SSLLIB) \
        $(KRB5LIBS) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testEventLoop_LDFLAGS = $(LIBADD_DL)
@@@ -2316,10 -2360,10 +2309,9 @@@ tests_test_http_range_LDADD = 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
 -      $(SQUID_CPPUNIT_LA) \
        $(SSLLIB) \
        $(KRB5LIBS) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_test_http_range_LDFLAGS = $(LIBADD_DL)
@@@ -2620,10 -2647,10 +2612,9 @@@ tests_testHttpRequest_LDADD = 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
 -      $(SQUID_CPPUNIT_LA) \
        $(SSLLIB) \
        $(KRB5LIBS) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testHttpRequest_LDFLAGS = $(LIBADD_DL)
@@@ -2841,10 -2819,9 +2832,9 @@@ tests_testStore_LDADD= 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
        $(SSLLIB) \
        CommCalls.o \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testStore_LDFLAGS = $(LIBADD_DL)
@@@ -2877,11 -2859,9 +2867,10 @@@ tests_testString_LDADD = 
        base/libbase.la \
        libsquid.la \
        ip/libip.la \
 +      sbuf/libsbuf.la \
        $(top_builddir)/lib/libmiscutil.la \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
        $(SSLLIB) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testString_LDFLAGS = $(LIBADD_DL)
@@@ -3066,9 -3050,8 +3055,8 @@@ tests_testUfs_LDADD = 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
        $(SSLLIB) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testUfs_LDFLAGS = $(LIBADD_DL)
@@@ -3241,9 -3224,8 +3229,8 @@@ tests_testRock_LDADD = 
        $(top_builddir)/lib/libmiscencoding.la \
        $(top_builddir)/lib/libmiscutil.la \
        $(NETTLELIB) \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
        $(SSLLIB) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testRock_LDFLAGS = $(AM_CPPFLAGS) $(LIBADD_DL)
@@@ -3471,9 -3456,6 +3458,8 @@@ tests_testURL_LDADD = 
        comm/libcomm.la \
        log/liblog.la \
        format/libformat.la \
-       $(REGEXLIB) \
 +      store/libstore.la \
 +      sbuf/libsbuf.la \
        $(REPL_OBJS) \
        $(ADAPTATION_LIBS) \
        $(ESI_LIBS) \
@@@ -3548,14 -3584,12 +3534,13 @@@ tests_testConfigParser_SOURCES = 
  nodist_tests_testConfigParser_SOURCES = \
        $(TESTSOURCES)
  tests_testConfigParser_LDADD = \
 -      base/libbase.la \
        libsquid.la \
        ip/libip.la \
 +      sbuf/libsbuf.la \
 +      base/libbase.la \
        $(top_builddir)/lib/libmiscutil.la \
-       $(REGEXLIB) \
 -      $(SQUID_CPPUNIT_LIBS) \
        $(SSLLIB) \
 +      $(LIBCPPUNIT_LIBS) \
        $(COMPAT_LIB) \
        $(XTRA_LIBS)
  tests_testConfigParser_LDFLAGS = $(LIBADD_DL)
index 6312898840cdf4a99936ec80c07ccb04f61469a9,209826219257830cb236fbb5a98f4615f3c1eac9..725a5f535c1f8d4ccfb80d45901150b9abb9e1b3
@@@ -58,10 -58,10 +58,10 @@@ ACLRegexData::dump() cons
      // keeping the flags values consistent
      for (auto &i : data) {
          if (i.flags != flags) {
-             if ((i.flags&REG_ICASE) != 0) {
+             if ((i.flags & std::regex::icase)) {
 -                sl.push_back(SBuf("-i"));
 +                sl.emplace_back("-i");
              } else {
 -                sl.push_back(SBuf("+i"));
 +                sl.emplace_back("+i");
              }
              flags = i.flags;
          }
@@@ -106,19 -106,22 +106,22 @@@ compileRE(std::list<RegexPattern> &curl
      if (RE == NULL || *RE == '\0')
          return curlist.empty(); // XXX: old code did this. It looks wrong.
  
-     regex_t comp;
-     if (int errcode = regcomp(&comp, RE, flags)) {
-         char errbuf[256];
-         regerror(errcode, &comp, errbuf, sizeof errbuf);
+     // std::regex constructor does the actual compile and throws on invalid patterns
+     try {
+         curlist.emplace_back(flags, RE);
+     } catch(std::regex_error &e) {
 -        debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
 +        debugs(28, DBG_CRITICAL, cfg_filename << " line " << config_lineno << ": " << config_input_line);
-         debugs(28, DBG_CRITICAL, "ERROR: invalid regular expression: '" << RE << "': " << errbuf);
+         debugs(28, DBG_CRITICAL, "ERROR: invalid regular expression: '" << RE << "': " << e.code());
          return false;
-     }
-     debugs(28, 2, "compiled '" << RE << "' with flags " << flags);
  
-     curlist.emplace_back(flags, RE);
-     curlist.back().regex = comp;
+     } catch(...) {
 -        debugs(28, DBG_CRITICAL, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
++        debugs(28, DBG_CRITICAL, cfg_filename << " line " << config_lineno << ": " << config_input_line);
+         debugs(28, DBG_CRITICAL, "ERROR: invalid regular expression: '" << RE << "': (unknown error)");
+         return false;
+     }
  
+     debugs(28, 2, "compiled '" << RE << "' with flags " << flags);
      return true;
  }
  
@@@ -136,25 -139,23 +139,25 @@@ compileOptimisedREs(std::list<RegexPatt
      char largeRE[BUFSIZ];
      *largeRE = 0;
  
 -    while (wl != NULL) {
 +    for (const SBuf & configurationLineWord : sl) {
          int RElen;
 -        RElen = strlen( wl->key );
 +        RElen = configurationLineWord.length();
  
 -        if (strcmp(wl->key, "-i") == 0) {
 +        static const SBuf minus_i("-i");
 +        static const SBuf plus_i("+i");
 +        if (configurationLineWord == minus_i) {
-             if (flags & REG_ICASE) {
+             if ((flags & std::regex::icase)) {
                  /* optimisation of  -i ... -i */
                  debugs(28, 2, "optimisation of -i ... -i" );
              } else {
                  debugs(28, 2, "-i" );
                  if (!compileRE(newlist, largeRE, flags))
                      return 0;
-                 flags |= REG_ICASE;
+                 flags |= std::regex::icase;
                  largeRE[largeREindex=0] = '\0';
              }
 -        } else if (strcmp(wl->key, "+i") == 0) {
 +        } else if (configurationLineWord == plus_i) {
-             if ((flags & REG_ICASE) == 0) {
+             if (!(flags & std::regex::icase)) {
                  /* optimisation of  +i ... +i */
                  debugs(28, 2, "optimisation of +i ... +i");
              } else {
  }
  
  static void
 -compileUnoptimisedREs(std::list<RegexPattern> &curlist, wordlist * wl)
 +compileUnoptimisedREs(std::list<RegexPattern> &curlist, const SBufList &sl)
  {
-     int flags = REG_EXTENDED | REG_NOSUB;
+     auto flags = std::regex::extended | std::regex::nosubs;
  
 -    while (wl != NULL) {
 -        if (strcmp(wl->key, "-i") == 0) {
 +    static const SBuf minus_i("-i"), plus_i("+i");
 +    for (auto configurationLineWord : sl) {
 +        if (configurationLineWord == minus_i) {
-             flags |= REG_ICASE;
+             flags |= std::regex::icase;
 -        } else if (strcmp(wl->key, "+i") == 0) {
 +        } else if (configurationLineWord == plus_i) {
-             flags &= ~REG_ICASE;
+             flags &= ~std::regex::icase;
          } else {
 -            if (!compileRE(curlist, wl->key , flags))
 -                debugs(28, DBG_CRITICAL, "ERROR: Skipping regular expression. Compile failed: '" << wl->key << "'");
 +            if (!compileRE(curlist, configurationLineWord.c_str() , flags))
 +                debugs(28, DBG_CRITICAL, "ERROR: Skipping regular expression. "
 +                       "Compile failed: '" << configurationLineWord << "'");
          }
 -        wl = wl->next;
      }
  }
  
index b6923326d4cb4b7328114b54dbd3f5ec76e5a5e1,ec89a859c92845c08aaeb47fb1699178f9f757ac..94021828751f5d0e26a942041c109ce321affe5f
@@@ -8,38 -8,14 +8,21 @@@
  
  #include "squid.h"
  #include "base/RegexPattern.h"
 +#include <utility>
  
- RegexPattern::RegexPattern(int aFlags, const char *aPattern) :
-     flags(aFlags),
-     pattern(xstrdup(aPattern))
- {
-     memset(&regex, 0, sizeof(regex));
- }
- RegexPattern::RegexPattern(RegexPattern &&o) :
-     flags(std::move(o.flags)),
-     regex(std::move(o.regex)),
-     pattern(std::move(o.pattern))
- {
-     memset(&o.regex, 0, sizeof(o.regex));
-     o.pattern = nullptr;
- }
- RegexPattern::~RegexPattern()
- {
-     xfree(pattern);
-     regfree(&regex);
- }
+ RegexPattern::RegexPattern(const std::regex_constants::syntax_option_type &aFlags, const char *aPattern) :
+         flags(aFlags),
+         pattern(xstrdup(aPattern)),
+         regex(pattern, flags)
+ {}
  
 -RegexPattern::~RegexPattern()
 +RegexPattern &
 +RegexPattern::operator =(RegexPattern &&o)
  {
 -    xfree(pattern);
 +    flags = std::move(o.flags);
 +    regex = std::move(o.regex);
-     memset(&o.regex, 0, sizeof(o.regex));
-     pattern = std::move(o.pattern);
++    pattern = o.pattern;
 +    o.pattern = nullptr;
 +    return *this;
  }
 +
index e799aa7595a87936680585362637e5a9bec26660,7bd9f758b237c67a3f08061c8226d4dd41eec2f8..c3b479e5800ed52093cc2f5d35151f51eef68302
@@@ -22,22 -23,16 +23,18 @@@ class RegexPatter
  
  public:
      RegexPattern() = delete;
-     RegexPattern(int aFlags, const char *aPattern);
-     ~RegexPattern();
-     // regex type varies by library, usually not safe to copy
+     RegexPattern(const std::regex_constants::syntax_option_type &aFlags, const char *aPattern); // throws std::regex_error
      RegexPattern(const RegexPattern &) = delete;
-     RegexPattern(RegexPattern &&);
 +    RegexPattern &operator =(const RegexPattern &) = delete;
 -    ~RegexPattern();
+     RegexPattern(RegexPattern &&) = default; // throws std::regex_error
 +    RegexPattern &operator =(RegexPattern &&);
++    ~RegexPattern() { xfree(pattern); }
  
--    const char * c_str() const {return pattern;}
-     bool match(const char *str) const {return regexec(&regex,str,0,NULL,0)==0;}
 -    bool match(const char *str) const {return std::regex_search(str, regex);}
++    const char * c_str() const { return pattern; }
++    bool match(const char *str) const { return std::regex_search(str, regex); }
  
  public:
-     int flags;
-     regex_t regex;
+     std::regex_constants::syntax_option_type flags;
  
  private:
      char *pattern;
diff --cc src/cache_cf.cc
index 2e277e5ac424812e8b21a1bd5e351b57c91c651c,9b79520cf897be6fe10d7c088a2fd9fb3846b916..fbb2fbb930a48dc4cfb755d4cf030cd298d4aef3
@@@ -2641,25 -2620,19 +2640,17 @@@ parse_refreshpattern(RefreshPattern ** 
      int ignore_private = 0;
  #endif
  
-     int i;
-     RefreshPattern *t;
-     regex_t comp;
-     int errcode;
-     int flags = REG_EXTENDED | REG_NOSUB;
-     if ((token = ConfigParser::RegexPattern()) != NULL) {
+     auto flags = std::regex::extended | std::regex::nosubs;
  
 -    if ((token = ConfigParser::RegexPattern()) != NULL) {
++    if ((token = ConfigParser::RegexPattern())) {
          if (strcmp(token, "-i") == 0) {
-             flags |= REG_ICASE;
+             flags |= std::regex::icase;
              token = ConfigParser::RegexPattern();
          } else if (strcmp(token, "+i") == 0) {
-             flags &= ~REG_ICASE;
+             flags &= ~std::regex::icase;
              token = ConfigParser::RegexPattern();
          }
--    }
--
--    if (token == NULL) {
++    } else {
          debugs(3, DBG_CRITICAL, "FATAL: refresh_pattern missing the regex pattern parameter");
          self_destruct();
          return;
      max = (time_t) (i * 60);    /* convert minutes to seconds */
  
      /* Options */
--    while ((token = ConfigParser::NextToken()) != NULL) {
++    while ((token = ConfigParser::NextToken())) {
          if (!strcmp(token, "refresh-ims")) {
              refresh_ims = 1;
          } else if (!strcmp(token, "store-stale")) {
Simple merge
Simple merge
diff --cc src/mime.cc
index c96c7151283b3e2325eedae2c2f31cc79aa9cc53,eac260b5c0b3c130bfe2dfcc525d39b46088531b..a3ccb4e36d86825666ad5d5fe20cfbbc137e804d
@@@ -9,8 -9,9 +9,9 @@@
  /* DEBUG: section 25    MIME Parsing and Internal Icons */
  
  #include "squid.h"
 -#include "disk.h"
+ #include "base/RegexPattern.h"
  #include "fde.h"
 +#include "fs_io.h"
  #include "globals.h"
  #include "HttpHdrCc.h"
  #include "HttpReply.h"
diff --cc src/refresh.cc
Simple merge
Simple merge
Simple merge
Simple merge