diff --git a/modules/bindbackend/bindbackend2.cc b/modules/bindbackend/bindbackend2.cc index 3c9b5409d7d61..0d45c6b7669df 100644 --- a/modules/bindbackend/bindbackend2.cc +++ b/modules/bindbackend/bindbackend2.cc @@ -23,6 +23,8 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include +#include #include #include #include @@ -924,7 +926,7 @@ void Bind2Backend::loadConfig(string* status) // NOLINT(readability-function-cog } } - sort(domains.begin(), domains.end()); // put stuff in inode order + boost::range::sort(domains); // put stuff in inode order for (const auto& domain : domains) { if (!(domain.hadFileDirective)) { g_log << Logger::Warning << d_logprefix << " Zone '" << domain.name << "' has no 'file' directive set in " << getArg("config") << endl; @@ -1021,7 +1023,7 @@ void Bind2Backend::loadConfig(string* status) // NOLINT(readability-function-cog } vector diff; - set_difference(oldnames.begin(), oldnames.end(), newnames.begin(), newnames.end(), back_inserter(diff)); + boost::range::set_difference(oldnames, newnames, back_inserter(diff)); unsigned int remdomains = diff.size(); for (const DNSName& name : diff) { @@ -1030,7 +1032,7 @@ void Bind2Backend::loadConfig(string* status) // NOLINT(readability-function-cog // count number of entirely new domains diff.clear(); - set_difference(newnames.begin(), newnames.end(), oldnames.begin(), oldnames.end(), back_inserter(diff)); + boost::range::set_difference(newnames, oldnames, back_inserter(diff)); newdomains = diff.size(); ostringstream msg; diff --git a/modules/geoipbackend/geoipbackend.cc b/modules/geoipbackend/geoipbackend.cc index 83e3aee798358..44f304d66b49f 100644 --- a/modules/geoipbackend/geoipbackend.cc +++ b/modules/geoipbackend/geoipbackend.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -356,7 +357,7 @@ void GeoIPBackend::loadDomainsFromDirectory(const std::string& dir, vector #include #include #include @@ -33,6 +34,7 @@ #include #include #include +#include #include ArgvMap::param_t::const_iterator ArgvMap::begin() @@ -111,7 +113,7 @@ bool ArgvMap::contains(const string& var, const string& val) vector parts; stringtok(parts, param->second, ", \t"); - return std::any_of(parts.begin(), parts.end(), [&](const std::string& str) { return str == val; }); + return boost::algorithm::any_of_equal(parts, val); } string ArgvMap::helpstring(string prefix) @@ -440,7 +442,7 @@ void ArgvMap::parseOne(const string& arg, const string& parseOnly, bool lax) // unknown setting encountered. see if its on the ignore list before throwing. vector parts; stringtok(parts, d_params["ignore-unknown-settings"], " ,\t\n\r"); - if (find(parts.begin(), parts.end(), var) != parts.end()) { + if (boost::algorithm::any_of_equal(parts, var)) { d_unknownParams[var] = std::move(val); SLOG(g_log << Logger::Warning << "Ignoring unknown setting '" << var << "' as requested" << endl, d_log->info(Logr::Warning, "Ignoring unknown setting as requested", "name", Logging::Loggable(var))); @@ -605,6 +607,6 @@ void ArgvMap::gatherIncludes(const std::string& directory, const std::string& su throw ArgException(msg); } - std::sort(vec.begin(), vec.end(), CIStringComparePOSIX()); + boost::range::sort(vec, CIStringComparePOSIX()); extraConfigs.insert(extraConfigs.end(), vec.begin(), vec.end()); } diff --git a/pdns/auth-secondarycommunicator.cc b/pdns/auth-secondarycommunicator.cc index 739838afe9762..a89ced4cae92e 100644 --- a/pdns/auth-secondarycommunicator.cc +++ b/pdns/auth-secondarycommunicator.cc @@ -27,6 +27,9 @@ #include "dnssecinfra.hh" #include "dnsseckeeper.hh" #include "base32.hh" +#include +#include +#include #include #include "communicator.hh" #include @@ -98,8 +101,8 @@ static bool catalogDiff(const DomainInfo& di, vector& fromXFR, vect vector retrieve; try { - sort(fromXFR.begin(), fromXFR.end()); - sort(fromDB.begin(), fromDB.end()); + boost::range::sort(fromXFR); + boost::range::sort(fromDB); auto xfr = fromXFR.cbegin(); auto db = fromDB.cbegin(); @@ -321,7 +324,7 @@ static bool catalogProcess(const DomainInfo& di, vector& rrs, vector ret; const auto compare = [](const DNSResourceRecord& a, const DNSResourceRecord& b) { return a.qname == b.qname ? a.qtype < b.qtype : a.qname.canonCompare(b.qname); }; - sort(rrs.begin(), rrs.end(), compare); + boost::range::sort(rrs, compare); DNSName rel; DNSName unique; @@ -490,12 +493,9 @@ void CommunicatorClass::ixfrSuck(const DNSName& domain, const TSIGTriplet& tt, c } } // O(N^2)! - rrset.erase(remove_if(rrset.begin(), rrset.end(), - [&g](const DNSRecord& dr) { - return count(g.second.first.cbegin(), - g.second.first.cend(), dr); - }), - rrset.end()); + boost::range::remove_erase_if(rrset, [&g](const auto& dnsr) { + return boost::algorithm::any_of_equal(g.second.first, dnsr); + }); // the DNSRecord== operator compares on name, type, class and lowercase content representation for (const auto& x : g.second.second) { diff --git a/pdns/comfun.cc b/pdns/comfun.cc index 01a1fff2cc3fa..b4a4bf641046d 100644 --- a/pdns/comfun.cc +++ b/pdns/comfun.cc @@ -19,6 +19,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#include + #include "statbag.hh" #include "zoneparser-tng.hh" #include "namespaces.hh" @@ -501,7 +504,7 @@ try domains.push_back(nsq); } - sort(domains.begin(), domains.end(), [](const NSQuery& a, const NSQuery& b) { return b.count < a.count; }); + boost::range::sort(domains, [](const auto& first, const auto& second) { return second.count < first.count; }); for(;;) { try { inflighter.run(); diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index 8685920dc7a21..88371b19e7c36 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -26,6 +26,9 @@ #include "dnssecinfra.hh" #include "ueberbackend.hh" #include "statbag.hh" +#include +#include +#include #include #include @@ -574,7 +577,7 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const DNSName& zone, bool useCache) algoNoSEP.insert(dkrc.d_algorithm); } } - set_intersection(algoSEP.begin(), algoSEP.end(), algoNoSEP.begin(), algoNoSEP.end(), std::back_inserter(algoHasSeparateKSK)); + boost::range::set_intersection(algoSEP, algoNoSEP, std::back_inserter(algoHasSeparateKSK)); retkeyset.reserve(dbkeyset.size()); for(DNSBackend::KeyData& kd : dbkeyset) @@ -591,16 +594,19 @@ DNSSECKeeper::keyset_t DNSSECKeeper::getKeys(const DNSName& zone, bool useCache) kmd.hasSEPBit = (kd.flags == 257); kmd.id = kd.id; - if (find(algoHasSeparateKSK.begin(), algoHasSeparateKSK.end(), dpk.getAlgorithm()) == algoHasSeparateKSK.end()) + if (boost::algorithm::none_of_equal(algoHasSeparateKSK, dpk.getAlgorithm())) { kmd.keyType = CSK; - else if(kmd.hasSEPBit) + } + else if (kmd.hasSEPBit) { kmd.keyType = KSK; - else + } + else { kmd.keyType = ZSK; + } retkeyset.emplace_back(dpk, kmd); } - sort(retkeyset.begin(), retkeyset.end(), keyCompareByKindAndID); + boost::range::sort(retkeyset, keyCompareByKindAndID); if (ttl > 0) { KeyCacheEntry kce; diff --git a/pdns/dnsbackend.cc b/pdns/dnsbackend.cc index 7abb7d47f39eb..f9598cdbf2af4 100644 --- a/pdns/dnsbackend.cc +++ b/pdns/dnsbackend.cc @@ -19,6 +19,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #ifdef HAVE_CONFIG_H #include "config.h" @@ -157,7 +158,7 @@ void BackendMakerClass::launch(const string& instr) stringtok(parts, instr, ", "); for (const auto& part : parts) { - if (count(parts.begin(), parts.end(), part) > 1) { + if (boost::range::count(parts, part) > 1) { throw ArgException("Refusing to launch multiple backends with the same name '" + part + "', verify all 'launch' statements in your configuration"); } } diff --git a/pdns/dnsbackend.hh b/pdns/dnsbackend.hh index 7b7e4c211784f..d260bd6b0d8ee 100644 --- a/pdns/dnsbackend.hh +++ b/pdns/dnsbackend.hh @@ -22,6 +22,7 @@ #pragma once #include +#include #include class DNSPacket; @@ -120,7 +121,7 @@ struct DomainInfo [[nodiscard]] bool isPrimary(const ComboAddress& ipAddress) const { - return std::any_of(primaries.begin(), primaries.end(), [ipAddress](auto primary) { return ComboAddress::addressOnlyEqual()(ipAddress, primary); }); + return boost::algorithm::any_of(primaries, [ipAddress](auto primary) { return ComboAddress::addressOnlyEqual()(ipAddress, primary); }); } }; diff --git a/pdns/dnsbulktest.cc b/pdns/dnsbulktest.cc index 49ad38ab49e46..e08746bd895dd 100644 --- a/pdns/dnsbulktest.cc +++ b/pdns/dnsbulktest.cc @@ -28,6 +28,7 @@ #pragma GCC diagnostic ignored "-Wdeprecated-copy-with-user-provided-copy" #endif #include +#include #include #include #pragma GCC diagnostic pop @@ -317,8 +318,7 @@ try pos=split.second.find('/'); if(pos != string::npos) // alexa has whole urls in the list now. split.second.resize(pos); - if(find_if(split.second.begin(), split.second.end(), isalpha) == split.second.end()) - { + if (boost::algorithm::none_of(split.second, isalpha)) { continue; // this was an IP address } domains.push_back(TypedQuery(split.second, qtype)); diff --git a/pdns/dnsdistdist/dnsdist-lua-rules.cc b/pdns/dnsdistdist/dnsdist-lua-rules.cc index 10937c03fcdf2..a8fff5d59bed1 100644 --- a/pdns/dnsdistdist/dnsdist-lua-rules.cc +++ b/pdns/dnsdistdist/dnsdist-lua-rules.cc @@ -25,6 +25,8 @@ #include "dnsdist-rule-chains.hh" #include "dns_random.hh" +#include + std::shared_ptr makeRule(const luadnsrule_t& var, const std::string& calledFrom) { if (var.type() == typeid(std::shared_ptr)) { @@ -141,15 +143,12 @@ static void showRules(IdentifierT identifier, boost::optional& var template static bool removeRuleFromChain(ChainTypeT& rules, const std::function& matchFunction) { - auto removeIt = std::remove_if(rules.begin(), - rules.end(), - matchFunction); + auto removeIt = boost::range::remove_if(rules, matchFunction); if (removeIt == rules.end()) { g_outputBuffer = "Error: no rule matched\n"; return false; } - rules.erase(removeIt, - rules.end()); + rules.erase(removeIt, rules.end()); return true; } diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 09818d982107a..3805bcc2c6749 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -36,6 +36,8 @@ #include #include +#include + #include "dnsdist.hh" #include "dnsdist-backend.hh" #include "dnsdist-cache.hh" @@ -760,7 +762,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } dnsdist::configuration::updateRuntimeConfiguration([&server](dnsdist::configuration::RuntimeConfiguration& config) { - config.d_backends.erase(std::remove(config.d_backends.begin(), config.d_backends.end(), server), config.d_backends.end()); + boost::range::remove_erase(config.d_backends, server); }); server->stop(); diff --git a/pdns/dnsdistdist/dnsdist-protocols.cc b/pdns/dnsdistdist/dnsdist-protocols.cc index 35da4711f4152..33b31496339d9 100644 --- a/pdns/dnsdistdist/dnsdist-protocols.cc +++ b/pdns/dnsdistdist/dnsdist-protocols.cc @@ -23,6 +23,8 @@ #include #include +#include + #include "dnsdist-protocols.hh" namespace dnsdist @@ -49,7 +51,7 @@ const std::array Protocol::s_prettyN Protocol::Protocol(const std::string& protocol) { - const auto& namesIt = std::find(s_names.begin(), s_names.end(), protocol); + auto namesIt = boost::ranges::find(s_names, protocol); if (namesIt == s_names.end()) { throw std::runtime_error("Unknown protocol name: '" + protocol + "'"); } diff --git a/pdns/dnsdistdist/doh3.cc b/pdns/dnsdistdist/doh3.cc index 661e9c6182236..38819587cbb1c 100644 --- a/pdns/dnsdistdist/doh3.cc +++ b/pdns/dnsdistdist/doh3.cc @@ -22,6 +22,8 @@ #include "doh3.hh" +#include + #ifdef HAVE_DNS_OVER_HTTP3 #include @@ -991,11 +993,11 @@ void doh3Thread(ClientState* clientState) mplexer->getAvailableFDs(readyFDs, 500); try { - if (std::find(readyFDs.begin(), readyFDs.end(), sock.getHandle()) != readyFDs.end()) { + if (boost::algorithm::any_of_equal(readyFDs, sock.getHandle())) { handleSocketReadable(*frontend, *clientState, sock, buffer); } - if (std::find(readyFDs.begin(), readyFDs.end(), responseReceiverFD) != readyFDs.end()) { + if (boost::algorithm::any_of_equal(readyFDs, responseReceiverFD)) { flushResponses(frontend->d_server_config->d_responseReceiver); } diff --git a/pdns/dnsdistdist/doq.cc b/pdns/dnsdistdist/doq.cc index 661fe5c2b5f96..56038ce617860 100644 --- a/pdns/dnsdistdist/doq.cc +++ b/pdns/dnsdistdist/doq.cc @@ -22,6 +22,8 @@ #include "doq.hh" +#include + #ifdef HAVE_DNS_OVER_QUIC #include @@ -794,11 +796,11 @@ void doqThread(ClientState* clientState) mplexer->getAvailableFDs(readyFDs, 500); try { - if (std::find(readyFDs.begin(), readyFDs.end(), sock.getHandle()) != readyFDs.end()) { + if (boost::algorithm::any_of_equal(readyFDs, sock.getHandle())) { handleSocketReadable(*frontend, *clientState, sock, buffer); } - if (std::find(readyFDs.begin(), readyFDs.end(), responseReceiverFD) != readyFDs.end()) { + if (boost::algorithm::any_of_equal(readyFDs, responseReceiverFD)) { flushResponses(frontend->d_server_config->d_responseReceiver); } diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index bbac4ffcb6a4a..1e4c48453e45d 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -21,6 +21,8 @@ */ #include "dnsname.hh" #include +#include +#include #include #include @@ -464,7 +466,7 @@ void DNSName::prependRawLabel(const std::string& label) bool DNSName::slowCanonCompare(const DNSName& rhs) const { auto ours=getRawLabels(), rhsLabels = rhs.getRawLabels(); - return std::lexicographical_compare(ours.rbegin(), ours.rend(), rhsLabels.rbegin(), rhsLabels.rend(), CIStringCompare()); + return boost::range::lexicographical_compare(boost::adaptors::reverse(ours), boost::adaptors::reverse(rhsLabels), CIStringCompare()); } vector DNSName::getRawLabels() const diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 9ba8ba7fbb740..f5344f00610ba 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -21,6 +21,9 @@ */ #pragma once #include +#include +#include +#include #include #include #include @@ -163,11 +166,11 @@ public: bool operator<(const DNSName& rhs) const // this delivers _some_ kind of ordering, but not one useful in a DNS context. Really fast though. { - return std::lexicographical_compare(d_storage.rbegin(), d_storage.rend(), - rhs.d_storage.rbegin(), rhs.d_storage.rend(), - [](const unsigned char& a, const unsigned char& b) { - return dns_tolower(a) < dns_tolower(b); - }); // note that this is case insensitive, including on the label lengths + return boost::range::lexicographical_compare(boost::adaptors::reverse(d_storage), + boost::adaptors::reverse(rhs.d_storage), + [](const unsigned char& a, const unsigned char& b) { + return dns_tolower(a) < dns_tolower(b); + }); // note that this is case insensitive, including on the label lengths } inline bool canonCompare(const DNSName& rhs) const; @@ -656,7 +659,7 @@ bool DNSName::operator==(const DNSName& rhs) const struct DNSNameSet: public std::unordered_set { std::string toString() const { std::ostringstream oss; - std::copy(begin(), end(), std::ostream_iterator(oss, "\n")); + boost::range::copy(*this, std::ostream_iterator(oss, "\n")); return oss.str(); } }; diff --git a/pdns/dnspacket.cc b/pdns/dnspacket.cc index 8588f2c21a151..f83c530bdd22c 100644 --- a/pdns/dnspacket.cc +++ b/pdns/dnspacket.cc @@ -23,6 +23,7 @@ #include "config.h" #endif #include "utility.hh" +#include #include #include #include @@ -272,9 +273,9 @@ void DNSPacket::wrapup(bool throwsOnTruncation) // we now need to order rrs so that the different sections come at the right place // we want a stable sort, based on the d_place field - stable_sort(d_rrs.begin(),d_rrs.end(), [](const DNSZoneRecord& a, const DNSZoneRecord& b) { - return a.dr.d_place < b.dr.d_place; - }); + boost::range::stable_sort(d_rrs, [](const auto& first, const auto& second) { + return first.dr.d_place < second.dr.d_place; + }); static bool mustNotShuffle = ::arg().mustDo("no-shuffle"); if(!d_xfr && !mustNotShuffle) { diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 72311fd51ef89..4c85ae4df9037 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -24,6 +24,7 @@ #endif #include +#include #include "utility.hh" #include "dnsrecords.hh" @@ -812,11 +813,10 @@ SvcParam SVCBBaseRecordContent::getParam(const SvcParam::SvcParamKey &key) const } set::const_iterator SVCBBaseRecordContent::getParamIt(const SvcParam::SvcParamKey &key) const { - auto p = std::find_if(d_params.begin(), d_params.end(), - [&key](const SvcParam ¶m) { - return param.getKey() == key; - }); - return p; + return boost::range::find_if(d_params, + [&key](const SvcParam& param) { + return param.getKey() == key; + }); } std::shared_ptr SVCBRecordContent::clone() const diff --git a/pdns/dnssecinfra.hh b/pdns/dnssecinfra.hh index 32b565d75668f..f769178a8bf52 100644 --- a/pdns/dnssecinfra.hh +++ b/pdns/dnssecinfra.hh @@ -23,6 +23,7 @@ #include "dnsrecords.hh" #include "dnspacket.hh" +#include #include #include #include @@ -263,8 +264,8 @@ struct CanonicalCompare stringtok(avect, a, "."); stringtok(bvect, b, "."); - reverse(avect.begin(), avect.end()); - reverse(bvect.begin(), bvect.end()); + boost::range::reverse(avect); + boost::range::reverse(bvect); return avect < bvect; } diff --git a/pdns/dnssecsigner.cc b/pdns/dnssecsigner.cc index 0e122c11a3192..24cd4bdd2565e 100644 --- a/pdns/dnssecsigner.cc +++ b/pdns/dnssecsigner.cc @@ -20,6 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H +#include + #include "config.h" #endif #include "dnssecinfra.hh" @@ -205,7 +207,7 @@ static bool getBestAuthFromSet(const set& authSet, const DNSName& name, void addRRSigs(DNSSECKeeper& dk, UeberBackend& db, const set& authSet, vector& rrs, DNSPacket* packet) { - stable_sort(rrs.begin(), rrs.end(), rrsigncomp); + boost::range::stable_sort(rrs, rrsigncomp); DNSName authQName, signQName, wildcardQName; uint16_t signQType=0; diff --git a/pdns/dynlistener.cc b/pdns/dynlistener.cc index d2e7b06096299..0d606e8ec72db 100644 --- a/pdns/dynlistener.cc +++ b/pdns/dynlistener.cc @@ -22,6 +22,8 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include +#include #include #include #include @@ -409,9 +411,9 @@ string DynListener::getHelp() for(g_funkdb_t::const_iterator i=s_funcdb.begin();i!=s_funcdb.end();++i) { funcs.push_back(str(boost::format(fmter) % (toLower(i->first)+" "+i->second.args) % i->second.usage)); } - sort(funcs.begin(), funcs.end()); + boost::range::sort(funcs); // hack: this removes the duplicate quit method - funcs.resize(unique(funcs.begin(), funcs.end()) - funcs.begin()); + funcs.erase(std::unique(funcs.begin(), funcs.end()), funcs.end()); return boost::join(funcs, "\n"); } diff --git a/pdns/histogram.hh b/pdns/histogram.hh index 4b9263bc8248e..0fc5c67c7a128 100644 --- a/pdns/histogram.hh +++ b/pdns/histogram.hh @@ -21,6 +21,7 @@ */ #pragma once +#include #include #include #include @@ -73,7 +74,7 @@ public: BaseHistogram(const std::string& prefix, const std::vector& boundaries) : d_name(prefix) { - if (!std::is_sorted(boundaries.cbegin(), boundaries.cend())) { + if (!boost::algorithm::is_sorted(boundaries)) { throw std::invalid_argument("boundary array must be sorted"); } if (boundaries.size() == 0) { diff --git a/pdns/lua-base4.cc b/pdns/lua-base4.cc index a95f8e05afa78..e02ed21ee9ae0 100644 --- a/pdns/lua-base4.cc +++ b/pdns/lua-base4.cc @@ -1,4 +1,5 @@ #include "config.h" +#include #include #include #include @@ -66,7 +67,7 @@ void BaseLua4::includePath(const std::string& directory) { throw PDNSException(msg); } - std::sort(vec.begin(), vec.end(), CIStringComparePOSIX()); + boost::range::sort(vec, CIStringComparePOSIX()); for(const auto& file: vec) { loadFile(file, false); diff --git a/pdns/misc.hh b/pdns/misc.hh index 39fdb6c086807..496e765feae3c 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #pragma once +#include #include #include #include @@ -455,8 +456,8 @@ struct CIStringPairCompare inline size_t pdns_ci_find(const string& haystack, const string& needle) { - string::const_iterator it = std::search(haystack.begin(), haystack.end(), - needle.begin(), needle.end(), pdns_iequals_ch); + string::const_iterator it = boost::range::search(haystack, + needle, pdns_iequals_ch); if (it == haystack.end()) { // not found return string::npos; diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index ca6d263438c4e..97ad914abba7b 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -224,7 +224,7 @@ bool PacketHandler::addCDS(DNSPacket& p, std::unique_ptr& r) rr.dr.d_name=p.qdomain; rr.auth=true; - if(std::find(digestAlgos.begin(), digestAlgos.end(), "0") != digestAlgos.end()) { // delete DS via CDS + if (boost::algorithm::any_of_equal(digestAlgos, "0")) { // delete DS via CDS rr.dr.setContent(s_deleteCDSContent); r->addRecord(std::move(rr)); return true; diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index ed19662297cdf..50d4f6b416c01 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -2,6 +2,10 @@ #include "dnsparser.hh" #include "dnsrecords.hh" #include "qtype.hh" +#include +#include +#include +#include #include #ifdef HAVE_CONFIG_H #include "config.h" @@ -1216,7 +1220,7 @@ static int editZone(const DNSName &zone, const PDNSColors& col) { DNSRecord dr(rr); pre.push_back(dr); } - sort(pre.begin(), pre.end(), DNSRecord::prettyCompare); + boost::range::sort(pre, DNSRecord::prettyCompare); for(const auto& dr : pre) { ostringstream os; os<getZoneRepresentation(true)< diff; map, string> changed; - set_difference(pre.cbegin(), pre.cend(), post.cbegin(), post.cend(), back_inserter(diff), DNSRecord::prettyCompare); + boost::range::set_difference(pre, post, back_inserter(diff), DNSRecord::prettyCompare); for(const auto& d : diff) { ostringstream str; str << col.red() << "-" << d.d_name << " " << d.d_ttl << " IN " << DNSRecordContent::NumberToType(d.d_type) << " " <getZoneRepresentation(true) << col.rst() < + #include "arguments.hh" #include "dns_random.hh" #include "ednsextendederror.hh" @@ -736,24 +738,21 @@ int getFakeAAAARecords(const DNSName& qname, ComboAddress prefix, vector seenCNAMEs; - ret.erase(std::remove_if( - ret.begin(), - ret.end(), - [&seenCNAMEs](DNSRecord& record) { - if (record.d_type == QType::CNAME) { - auto target = getRR(record); - if (target == nullptr) { - return false; - } - if (seenCNAMEs.count(target->getTarget()) > 0) { - // We've had this CNAME before, remove it - return true; - } - seenCNAMEs.insert(target->getTarget()); - } - return false; - }), - ret.end()); + boost::range::remove_erase_if(ret, + [&seenCNAMEs](DNSRecord& record) { + if (record.d_type == QType::CNAME) { + auto target = getRR(record); + if (target == nullptr) { + return false; + } + if (seenCNAMEs.count(target->getTarget()) > 0) { + // We've had this CNAME before, remove it + return true; + } + seenCNAMEs.insert(target->getTarget()); + } + return false; + }); bool seenA = false; for (DNSRecord& record : ret) { @@ -771,31 +770,25 @@ int getFakeAAAARecords(const DNSName& qname, ComboAddress prefix, vector seenSOAs; - ret.erase(std::remove_if( - ret.begin(), - ret.end(), - [&seenSOAs](DNSRecord& record) { - if (record.d_type == QType::SOA) { - if (seenSOAs.count(record.d_name) > 0) { - // We've had this SOA before, remove it - return true; - } - seenSOAs.insert(record.d_name); - } - return false; - }), - ret.end()); + boost::range::remove_erase_if(ret, + [&seenSOAs](DNSRecord& record) { + if (record.d_type == QType::SOA) { + if (seenSOAs.count(record.d_name) > 0) { + // We've had this SOA before, remove it + return true; + } + seenSOAs.insert(record.d_name); + } + return false; + }); } t_Counters.at(rec::Counter::dns64prefixanswers)++; return rcode; diff --git a/pdns/recursordist/settings/cxxsupport.cc b/pdns/recursordist/settings/cxxsupport.cc index 4c4fd13c1a339..be5c52ba0b134 100644 --- a/pdns/recursordist/settings/cxxsupport.cc +++ b/pdns/recursordist/settings/cxxsupport.cc @@ -26,6 +26,8 @@ #include #include +#include + #include "namespaces.hh" #include "arguments.hh" #include "misc.hh" @@ -750,7 +752,7 @@ void fromLuaToRust(const LuaConfigItems& luaConfig, pdns::rust::settings::rec::D ::rust::Vec<::rust::String> dsRecords; for (const auto& dsRecord : anchors.second) { const auto dsString = dsRecord.getZoneRepresentation(); - if (anchors.first != g_rootdnsname || std::find(rootDSs.begin(), rootDSs.end(), dsString) == rootDSs.end()) { + if (anchors.first != g_rootdnsname || boost::algorithm::none_of_equal(rootDSs, dsString)) { dsRecords.emplace_back(dsRecord.getZoneRepresentation()); } } @@ -1367,7 +1369,7 @@ bool pdns::settings::rec::luaItemSet(const pdns::rust::settings::rec::Recursorse break; } for (const auto& dsRecord : trustanchor.dsrecords) { - if (std::find(rootDSs.begin(), rootDSs.end(), std::string(dsRecord)) == rootDSs.end()) { + if (boost::algorithm::none_of_equal(rootDSs, dsRecord)) { alldefault = false; break; } diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 9a318dfc46ba8..4efe2868576f8 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -20,11 +20,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifdef HAVE_CONFIG_H -#include - #include "config.h" #endif +#include +#include +#include + #include "arguments.hh" #include "aggressive_nsec.hh" #include "cachecleaner.hh" @@ -3558,7 +3560,7 @@ bool SyncRes::throttledOrBlocked(const std::string& prefix, const ComboAddress& } // The name (from the cache) is forwarded, but is it forwarded to an IP in known forwarders? const auto& ips = iter->second.d_servers; - if (std::find(ips.cbegin(), ips.cend(), remoteIP) == ips.cend()) { + if (boost::algorithm::none_of_equal(ips, remoteIP)) { LOG(prefix << qname << ": Not sending query to " << remoteIP.toString() << ", blocked by 'dont-query' setting" << endl); t_Counters.at(rec::Counter::dontqueries)++; return true; @@ -5109,13 +5111,10 @@ bool SyncRes::processRecords(const std::string& prefix, const DNSName& qname, co dnameTarget = content->getTarget(); dnameTTL = rec.d_ttl; if (!newtarget.empty()) { // We had a CNAME before, remove it from ret so we don't cache it - ret.erase(std::remove_if( - ret.begin(), - ret.end(), - [&qname](DNSRecord& dnsrecord) { - return (dnsrecord.d_place == DNSResourceRecord::ANSWER && dnsrecord.d_type == QType::CNAME && dnsrecord.d_name == qname); - }), - ret.end()); + boost::range::remove_erase_if(ret, + [&qname](DNSRecord& dnsrecord) { + return (dnsrecord.d_place == DNSResourceRecord::ANSWER && dnsrecord.d_type == QType::CNAME && dnsrecord.d_name == qname); + }); } try { newtarget = qname.makeRelative(dnameOwner) + dnameTarget; @@ -6266,19 +6265,7 @@ bool SyncRes::answerIsNOData(uint16_t requestedType, int rcode, const std::vecto return false; } - // NOLINTNEXTLINE(readability-use-anyofallof) - for (const auto& rec : records) { - if (rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == requestedType) { - /* we have a record, of the right type, in the right section */ - return false; - } - } - return true; -#if 0 - // This code should be equivalent to the code above, clang-tidy prefers any_of() - // I have doubts if that is easier to read - return !std::any_of(records.begin(), records.end(), [=](const DNSRecord& rec) { + return boost::algorithm::none_of(records, [=](const auto& rec) { return rec.d_place == DNSResourceRecord::ANSWER && rec.d_type == requestedType; }); -#endif } diff --git a/pdns/rfc2136handler.cc b/pdns/rfc2136handler.cc index be4d78f5c1273..f8d6341259c6f 100644 --- a/pdns/rfc2136handler.cc +++ b/pdns/rfc2136handler.cc @@ -2,6 +2,9 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + +#include + #include "packethandler.hh" #include "qtype.hh" #include "dnspacket.hh" @@ -476,10 +479,12 @@ uint PacketHandler::performUpdate(const string &msgPrefix, const DNSRecord *rr, bool foundDeeper = false, foundOtherWithSameName = false; di->backend->listSubZone(rr->d_name, di->id); while (di->backend->get(rec)) { - if (rec.qname == rr->d_name && !count(recordsToDelete.begin(), recordsToDelete.end(), rec)) + if (rec.qname == rr->d_name && boost::range::count(recordsToDelete, rec) == 0) { foundOtherWithSameName = true; - if (rec.qname != rr->d_name && rec.qtype.getCode() != QType::NS) //Skip NS records, as this would be a delegate that we can ignore as this does not require us to create a ENT + } + if (rec.qname != rr->d_name && rec.qtype.getCode() != QType::NS) { // Skip NS records, as this would be a delegate that we can ignore as this does not require us to create a ENT foundDeeper = true; + } } if (foundDeeper && !foundOtherWithSameName) { diff --git a/pdns/secpoll.cc b/pdns/secpoll.cc index 8ee4a59bbfbce..398f8c6ae63cc 100644 --- a/pdns/secpoll.cc +++ b/pdns/secpoll.cc @@ -20,6 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include #include "dnsrecords.hh" @@ -28,7 +29,7 @@ #include "secpoll.hh" bool isReleaseVersion(const std::string &version) { - return std::count(version.begin(), version.end(), '.') == 2; + return boost::range::count(version, '.') == 2; } static void setSecPollToUnknownOnOK(int &secPollStatus) { diff --git a/pdns/shuffle.cc b/pdns/shuffle.cc index 0e507a76d54d3..f2ddc52002939 100644 --- a/pdns/shuffle.cc +++ b/pdns/shuffle.cc @@ -23,6 +23,7 @@ #include "config.h" #endif +#include #include #include "shuffle.hh" @@ -135,7 +136,7 @@ static uint16_t mapTypesToOrder(uint16_t type) // then shuffle the parts that desire shuffling void pdns::orderAndShuffle(vector& rrs, bool includingAdditionals) { - std::stable_sort(rrs.begin(), rrs.end(), [](const DNSRecord& lhs, const DNSRecord& rhs) { + boost::range::stable_sort(rrs, [](const DNSRecord& lhs, const DNSRecord& rhs) { return std::tuple(lhs.d_place, mapTypesToOrder(lhs.d_type)) < std::tuple(rhs.d_place, mapTypesToOrder(rhs.d_type)); }); shuffle(rrs, includingAdditionals); diff --git a/pdns/signingpipe.cc b/pdns/signingpipe.cc index 25f3d59b9f978..880add9d190c0 100644 --- a/pdns/signingpipe.cc +++ b/pdns/signingpipe.cc @@ -2,6 +2,9 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif + +#include + #include "signingpipe.hh" #include "misc.hh" #include "dns_random.hh" @@ -113,9 +116,9 @@ bool dedupEqual(const DNSZoneRecord& a, const DNSZoneRecord &b) void ChunkedSigningPipe::dedupRRSet() { - // our set contains contains records for one type and one name, but might not be sorted otherwise - sort(d_rrsetToSign->begin(), d_rrsetToSign->end(), dedupLessThan); - d_rrsetToSign->erase(unique(d_rrsetToSign->begin(), d_rrsetToSign->end(), dedupEqual), d_rrsetToSign->end()); + // our set contains records for one type and one name, but might not be sorted otherwise + boost::range::sort(*d_rrsetToSign, dedupLessThan); + d_rrsetToSign->erase(std::unique(d_rrsetToSign->begin(), d_rrsetToSign->end(), dedupEqual), d_rrsetToSign->end()); } bool ChunkedSigningPipe::submit(const DNSZoneRecord& rr) diff --git a/pdns/svc-records.cc b/pdns/svc-records.cc index 73b112f470249..aee3d7c0f2343 100644 --- a/pdns/svc-records.cc +++ b/pdns/svc-records.cc @@ -19,6 +19,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include + #include "svc-records.hh" #include "misc.hh" #include "base64.hh" @@ -56,7 +58,7 @@ SvcParam::SvcParamKey SvcParam::keyFromString(const std::string& k, bool &generi } std::string SvcParam::keyToString(const SvcParam::SvcParamKey& k) { - auto ret = std::find_if(SvcParams.begin(), SvcParams.end(), [&](const std::pair& e) { return e.second == k; }); + auto ret = boost::range::find_if(SvcParams, [&](const auto& param) { return param.second == k; }); if (ret != SvcParams.end()) { return ret->first; } diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc index c4696a8f72ccd..aaaa19f716bf7 100644 --- a/pdns/tcpreceiver.cc +++ b/pdns/tcpreceiver.cc @@ -23,6 +23,7 @@ #include "config.h" #endif #include +#include #include #include "auth-packetcache.hh" #include "utility.hh" @@ -748,11 +749,12 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr& q, zrr.dr.d_type=QType::CDS; vector digestAlgos; stringtok(digestAlgos, publishCDS, ", "); - if(std::find(digestAlgos.begin(), digestAlgos.end(), "0") != digestAlgos.end()) { + if (boost::algorithm::any_of_equal(digestAlgos, "0")) { doCDS = false; zrr.dr.setContent(PacketHandler::s_deleteCDSContent); zrrs.push_back(zrr); - } else { + } + else { for(auto const &digestAlgo : digestAlgos) { zrr.dr.setContent(std::make_shared(makeDSFromDNSKey(target, value.first.getDNSKEY(), pdns::checked_stoi(digestAlgo)))); zrrs.push_back(zrr); @@ -923,8 +925,8 @@ int TCPNameserver::doAXFR(const DNSName &target, std::unique_ptr& q, // Group records by name and type, signpipe stumbles over interrupted rrsets if(securedZone && !presignedZone) { - sort(zrrs.begin(), zrrs.end(), [](const DNSZoneRecord& a, const DNSZoneRecord& b) { - return std::tie(a.dr.d_name, a.dr.d_type) < std::tie(b.dr.d_name, b.dr.d_type); + boost::range::sort(zrrs, [](const auto& first, const auto& second) { + return std::tie(first.dr.d_name, first.dr.d_type) < std::tie(second.dr.d_name, second.dr.d_type); }); } diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 8dc0f3f7e3cad..e2b09263730d1 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -43,6 +43,8 @@ #include "ws-api.hh" #include "version.hh" #include "dnsseckeeper.hh" +#include +#include #include #include "zoneparser-tng.hh" #include "auth-main.hh" @@ -467,7 +469,7 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons } records.push_back(resourceRecord); } - sort(records.begin(), records.end(), [](const DNSResourceRecord& rrA, const DNSResourceRecord& rrB) { + boost::range::sort(records, [](const DNSResourceRecord& rrA, const DNSResourceRecord& rrB) { /* if you ever want to update this comparison function, please be aware that you will also need to update the conditions in the code merging the records and comments below */ @@ -487,7 +489,7 @@ static void fillZone(UeberBackend& backend, const DNSName& zonename, HttpRespons comments.push_back(comment); } } - sort(comments.begin(), comments.end(), [](const Comment& rrA, const Comment& rrB) { + boost::range::sort(comments, [](const Comment& rrA, const Comment& rrB) { /* if you ever want to update this comparison function, please be aware that you will also need to update the conditions in the code merging the records and comments below */ @@ -1102,10 +1104,7 @@ static void apiZoneMetadataPOST(HttpRequest* req, HttpResponse* resp) if (!value.is_string()) { throw ApiException("metadata must be strings"); } - if (std::find(vecMetadata.cbegin(), - vecMetadata.cend(), - value.string_value()) - == vecMetadata.cend()) { + if (boost::algorithm::none_of_equal(vecMetadata, value.string_value())) { vecMetadata.push_back(value.string_value()); } } @@ -1603,11 +1602,11 @@ static void gatherRecordsFromZone(const std::string& zonestring, vector& records, const DNSName& zone) { - sort(records.begin(), records.end(), - [](const DNSResourceRecord& rec_a, const DNSResourceRecord& rec_b) -> bool { - /* we need _strict_ weak ordering */ - return std::tie(rec_a.qname, rec_a.qtype, rec_a.content) < std::tie(rec_b.qname, rec_b.qtype, rec_b.content); - }); + boost::range::sort(records, + [](const DNSResourceRecord& rec_a, const DNSResourceRecord& rec_b) -> bool { + /* we need _strict_ weak ordering */ + return std::tie(rec_a.qname, rec_a.qtype, rec_a.content) < std::tie(rec_b.qname, rec_b.qtype, rec_b.content); + }); DNSResourceRecord previous; for (const auto& rec : records) { diff --git a/pdns/zone2json.cc b/pdns/zone2json.cc index 51e76fa03b429..0d5e551aafec5 100644 --- a/pdns/zone2json.cc +++ b/pdns/zone2json.cc @@ -26,6 +26,7 @@ #include "config.h" #endif #include +#include #include #include @@ -152,7 +153,7 @@ try } } - sort(domains.begin(), domains.end()); // put stuff in inode order + boost::range::sort(domains); // put stuff in inode order int numdomains=domains.size(); int tick=numdomains/100; diff --git a/pdns/zone2sql.cc b/pdns/zone2sql.cc index 4dfa32ed8464e..6b26ecc4b91ef 100644 --- a/pdns/zone2sql.cc +++ b/pdns/zone2sql.cc @@ -26,6 +26,7 @@ #include "config.h" #endif #include +#include #include #include @@ -279,7 +280,7 @@ try } } - sort(domains.begin(), domains.end()); // put stuff in inode order + boost::range::sort(domains); // put stuff in inode order int numdomains=domains.size(); int tick=numdomains/100;