From: Amos Jeffries Date: Sun, 20 Nov 2016 09:12:00 +0000 (+1300) Subject: C++11: Remove GnuRegex and all -lregex related code X-Git-Tag: M-staged-PR71~362 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c438bcf10742e773a8e602a398c884ea54080336;p=thirdparty%2Fsquid.git C++11: Remove GnuRegex and all -lregex related code 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. --- c438bcf10742e773a8e602a398c884ea54080336 diff --cc doc/release-notes/release-5.sgml index ac4dafd670,0000000000..e0ed556382 mode 100644,000000..100644 --- a/doc/release-notes/release-5.sgml +++ b/doc/release-notes/release-5.sgml @@@ -1,193 -1,0 +1,214 @@@ + +
+Squid 5.0.0 release notes +Squid Developers + + +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. + + + + +Notice +

The Squid Team are pleased to announce the release of Squid-5.0.0 for testing. + +This new release is available for download from or the + . + +

While this release is not deemed ready for production use, we believe it is ready for wider testing by the community. + +

We welcome feedback and bug reports. If you find a bug, please see + for how to submit a report with a stack trace. + +Known issues +

Although this release is deemed good enough for use in many setups, please note the existence of +. + +Changes since earlier releases of Squid-5 +

+The Squid-4 change history can be . + + +Major new features since Squid-4 +

Squid-5 represents a new feature release above Squid-4. + +

The most important of these new features are: + + ICAP Trailers + + +Most user-facing changes are reflected in squid.conf (see below). + + +ICAP Trailers +

Details in + +

The Trailers feature from HTTP is being proposed for addition to ICAP, + with some modifications. + +

This implementation complies with version -01 of that draft: + + Announces ICAP Trailer support via the ICAP Allow request header field. + 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. + + +

For now Squid logs and ignores all parsed ICAP header fields. + + +Changes to squid.conf since Squid-4 +

+There have been changes to Squid's configuration file since Squid-4. + +This section gives a thorough account of those changes in three categories: + + + + + + +

+ +New directives

+ +

No new directives in this version. + + + +Changes to existing directives

+ -

No changes to existing directives in this version. ++ acl ++

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. ++ ++ refresh_pattern ++

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. + + + +Removed directives

+ +

No removed directives in this version. + + + + +Changes to ./configure options since Squid-4 +

+There have been some changes to Squid's build configuration since Squid-4. + +This section gives an account of those changes in three categories: + + + + + + + + +New options

+ +

No new options in this version. + + + +Changes to existing options

+ +

No changes to existing options in this version. + + +

+ +Removed options
diff --cc src/Makefile.am index f8a8a6d6b5,633f266b60..2e1c7923e7 --- a/src/Makefile.am +++ b/src/Makefile.am @@@ -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 \ + store/libstore.la \ + sbuf/libsbuf.la \ - $(REGEXLIB) \ $(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) diff --cc src/acl/RegexData.cc index 6312898840,2098262192..725a5f535c --- a/src/acl/RegexData.cc +++ b/src/acl/RegexData.cc @@@ -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®_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 &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::listkey ); + 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 { @@@ -204,21 -208,20 +207,21 @@@ } static void -compileUnoptimisedREs(std::list &curlist, wordlist * wl) +compileUnoptimisedREs(std::list &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; } } diff --cc src/base/RegexPattern.cc index b6923326d4,ec89a859c9..9402182875 --- a/src/base/RegexPattern.cc +++ b/src/base/RegexPattern.cc @@@ -8,38 -8,14 +8,21 @@@ #include "squid.h" #include "base/RegexPattern.h" +#include - RegexPattern::RegexPattern(int aFlags, const char *aPattern) : - flags(aFlags), - pattern(xstrdup(aPattern)) - { - memset(®ex, 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(®ex); - } + 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; } + diff --cc src/base/RegexPattern.h index e799aa7595,7bd9f758b2..c3b479e580 --- a/src/base/RegexPattern.h +++ b/src/base/RegexPattern.h @@@ -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 &operator =(const RegexPattern &) = delete; - - RegexPattern(RegexPattern &&); + RegexPattern(RegexPattern &&) = default; // throws std::regex_error - ~RegexPattern(); + RegexPattern &operator =(RegexPattern &&); ++ ~RegexPattern() { xfree(pattern); } -- const char * c_str() const {return pattern;} - bool match(const char *str) const {return regexec(®ex,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 2e277e5ac4,9b79520cf8..fbb2fbb930 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@@ -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; @@@ -2698,7 -2673,7 +2689,7 @@@ 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")) { diff --cc src/mime.cc index c96c715128,eac260b5c0..a3ccb4e36d --- a/src/mime.cc +++ b/src/mime.cc @@@ -9,8 -9,9 +9,9 @@@ /* DEBUG: section 25 MIME Parsing and Internal Icons */ #include "squid.h" + #include "base/RegexPattern.h" -#include "disk.h" #include "fde.h" +#include "fs_io.h" #include "globals.h" #include "HttpHdrCc.h" #include "HttpReply.h"