From fa5a722bf40bfa95d2ba8c0fa3f5987b13b34503 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 26 Jan 2023 09:49:20 +0100 Subject: [PATCH] Remove the now useless pdns_string_view --- pdns/dnsdist-cache.cc | 2 +- pdns/dnsdist-ecs.cc | 8 ++++---- pdns/dnsdistdist/dnsdist-discovery.cc | 2 +- pdns/dnsdistdist/dnsdist-dnsparser.cc | 4 ++-- pdns/dnsdistdist/doh.cc | 14 +++++++------- pdns/dnsparser.cc | 4 ++-- pdns/dnsparser.hh | 8 ++++---- pdns/namespaces.hh | 2 -- pdns/packetcache.hh | 2 +- pdns/protozero.cc | 2 +- pdns/recursordist/ednsextendederror.cc | 6 +++--- 11 files changed, 26 insertions(+), 28 deletions(-) diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index 9b345e25e8..3a3691f28b 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -444,7 +444,7 @@ uint32_t DNSDistPacketCache::getKey(const DNSName::string_t& qname, size_t qname if (packet.size() > ((sizeof(dnsheader) + qnameWireLength))) { if (!d_optionsToSkip.empty()) { /* skip EDNS options if any */ - result = PacketCache::hashAfterQname(pdns_string_view(reinterpret_cast(packet.data()), packet.size()), result, sizeof(dnsheader) + qnameWireLength, d_optionsToSkip); + result = PacketCache::hashAfterQname(std::string_view(reinterpret_cast(packet.data()), packet.size()), result, sizeof(dnsheader) + qnameWireLength, d_optionsToSkip); } else { result = burtle(&packet.at(sizeof(dnsheader) + qnameWireLength), packet.size() - (sizeof(dnsheader) + qnameWireLength), result); diff --git a/pdns/dnsdist-ecs.cc b/pdns/dnsdist-ecs.cc index 51052fc24d..9e9d9c329e 100644 --- a/pdns/dnsdist-ecs.cc +++ b/pdns/dnsdist-ecs.cc @@ -52,7 +52,7 @@ int rewriteResponseWithoutEDNS(const PacketBuffer& initialPacket, PacketBuffer& if (ntohs(dh->qdcount) == 0) return ENOENT; - PacketReader pr(pdns_string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); + PacketReader pr(std::string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); size_t idx = 0; DNSName rrname; @@ -165,7 +165,7 @@ bool slowRewriteEDNSOptionInQueryWithRecords(const PacketBuffer& initialPacket, optionAdded = false; ednsAdded = true; - PacketReader pr(pdns_string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); + PacketReader pr(std::string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); size_t idx = 0; DNSName rrname; @@ -329,7 +329,7 @@ int locateEDNSOptRR(const PacketBuffer& packet, uint16_t * optStart, size_t * op if (ntohs(dh->arcount) == 0) return ENOENT; - PacketReader pr(pdns_string_view(reinterpret_cast(packet.data()), packet.size())); + PacketReader pr(std::string_view(reinterpret_cast(packet.data()), packet.size())); size_t idx = 0; DNSName rrname; @@ -760,7 +760,7 @@ int rewriteResponseWithoutEDNSOption(const PacketBuffer& initialPacket, const ui if (ntohs(dh->qdcount) == 0) return ENOENT; - PacketReader pr(pdns_string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); + PacketReader pr(std::string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); size_t idx = 0; DNSName rrname; diff --git a/pdns/dnsdistdist/dnsdist-discovery.cc b/pdns/dnsdistdist/dnsdist-discovery.cc index 4a463c616c..c042fa52f9 100644 --- a/pdns/dnsdistdist/dnsdist-discovery.cc +++ b/pdns/dnsdistdist/dnsdist-discovery.cc @@ -53,7 +53,7 @@ static bool parseSVCParams(const PacketBuffer& answer, std::map> hints; const struct dnsheader* dh = reinterpret_cast(answer.data()); - PacketReader pr(pdns_string_view(reinterpret_cast(answer.data()), answer.size())); + PacketReader pr(std::string_view(reinterpret_cast(answer.data()), answer.size())); uint16_t qdcount = ntohs(dh->qdcount); uint16_t ancount = ntohs(dh->ancount); uint16_t nscount = ntohs(dh->nscount); diff --git a/pdns/dnsdistdist/dnsdist-dnsparser.cc b/pdns/dnsdistdist/dnsdist-dnsparser.cc index 2383eb35d1..90ce075805 100644 --- a/pdns/dnsdistdist/dnsdist-dnsparser.cc +++ b/pdns/dnsdistdist/dnsdist-dnsparser.cc @@ -35,7 +35,7 @@ DNSPacketOverlay::DNSPacketOverlay(const std::string_view& packet) d_records.reserve(numRecords); try { - PacketReader reader(pdns_string_view(reinterpret_cast(packet.data()), packet.size())); + PacketReader reader(std::string_view(reinterpret_cast(packet.data()), packet.size())); for (uint16_t n = 0; n < ntohs(d_header.qdcount); ++n) { reader.xfrName(d_qname); @@ -70,7 +70,7 @@ bool changeNameInDNSPacket(PacketBuffer& initialPacket, const DNSName& from, con return false; } - PacketReader pr(pdns_string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); + PacketReader pr(std::string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); dnsheader dh; memcpy(&dh, initialPacket.data(), sizeof(dh)); diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 58a6286978..036948521d 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -930,15 +930,15 @@ static void doh_dispatch_query(DOHServerConfig* dsc, h2o_handler_t* self, h2o_re } /* can only be called from the main DoH thread */ -static bool getHTTPHeaderValue(const h2o_req_t* req, const std::string& headerName, pdns_string_view& value) +static bool getHTTPHeaderValue(const h2o_req_t* req, const std::string& headerName, std::string_view& value) { bool found = false; /* early versions of boost::string_ref didn't have the ability to compare to string */ - pdns_string_view headerNameView(headerName); + std::string_view headerNameView(headerName); for (size_t i = 0; i < req->headers.size; ++i) { - if (pdns_string_view(req->headers.entries[i].name->base, req->headers.entries[i].name->len) == headerNameView) { - value = pdns_string_view(req->headers.entries[i].value.base, req->headers.entries[i].value.len); + if (std::string_view(req->headers.entries[i].name->base, req->headers.entries[i].name->len) == headerNameView) { + value = std::string_view(req->headers.entries[i].value.base, req->headers.entries[i].value.len); /* don't stop there, we might have more than one header with the same name, and we want the last one */ found = true; } @@ -951,12 +951,12 @@ static bool getHTTPHeaderValue(const h2o_req_t* req, const std::string& headerNa static void processForwardedForHeader(const h2o_req_t* req, ComboAddress& remote) { static const std::string headerName = "x-forwarded-for"; - pdns_string_view value; + std::string_view value; if (getHTTPHeaderValue(req, headerName, value)) { try { auto pos = value.rfind(','); - if (pos != pdns_string_view::npos) { + if (pos != std::string_view::npos) { ++pos; for (; pos < value.size() && value[pos] == ' '; ++pos) { @@ -1050,7 +1050,7 @@ static int doh_handler(h2o_handler_t *self, h2o_req_t *req) } } - // would be nice to be able to use a pdns_string_view there, + // would be nice to be able to use a std::string_view there, // but regex (called by matches() internally) requires a null-terminated string string path(req->path.base, req->path.len); /* the responses map can be updated at runtime, so we need to take a copy of diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 9a2ee1a599..ae10668678 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -213,7 +213,7 @@ DNSResourceRecord DNSResourceRecord::fromWire(const DNSRecord& d) { return rr; } -void MOADNSParser::init(bool query, const pdns_string_view& packet) +void MOADNSParser::init(bool query, const std::string_view& packet) { if (packet.size() < sizeof(dnsheader)) throw MOADNSException("Packet shorter than minimal header"); @@ -793,7 +793,7 @@ static int rewritePacketWithoutRecordTypes(const PacketBuffer& initialPacket, Pa if (ntohs(dh->qdcount) == 0) return ENOENT; - auto packetView = pdns_string_view(reinterpret_cast(initialPacket.data()), initialPacket.size()); + auto packetView = std::string_view(reinterpret_cast(initialPacket.data()), initialPacket.size()); PacketReader pr(packetView); diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 0ac1903be0..ee499a8559 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -66,7 +66,7 @@ class MOADNSParser; class PacketReader { public: - PacketReader(const pdns_string_view& content, uint16_t initialPos=sizeof(dnsheader)) + PacketReader(const std::string_view& content, uint16_t initialPos=sizeof(dnsheader)) : d_pos(initialPos), d_startrecordpos(initialPos), d_content(content) { if(content.size() > std::numeric_limits::max()) @@ -184,7 +184,7 @@ private: uint16_t d_startrecordpos; // needed for getBlob later on uint16_t d_recordlen; // ditto uint16_t not_used; // Aligns the whole class on 8-byte boundaries - const pdns_string_view d_content; + const std::string_view d_content; }; struct DNSRecord; @@ -443,7 +443,7 @@ public: //! Parse from a pointer and length MOADNSParser(bool query, const char *packet, unsigned int len) : d_tsigPos(0) { - init(query, pdns_string_view(packet, len)); + init(query, std::string_view(packet, len)); } DNSName d_qname; @@ -464,7 +464,7 @@ public: bool hasEDNS() const; private: - void init(bool query, const pdns_string_view& packet); + void init(bool query, const std::string_view& packet); uint16_t d_tsigPos; }; diff --git a/pdns/namespaces.hh b/pdns/namespaces.hh index 5c8b4224a6..f7489fe859 100644 --- a/pdns/namespaces.hh +++ b/pdns/namespaces.hh @@ -48,5 +48,3 @@ using std::shared_ptr; using std::string; using std::unique_ptr; using std::vector; - -using pdns_string_view = std::string_view; diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 6149e52b25..583ecfc8a9 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -33,7 +33,7 @@ public: - EDNS Cookie options, if any ; - Any given option code present in optionsToSkip */ - static uint32_t hashAfterQname(const pdns_string_view& packet, uint32_t currentHash, size_t pos, const std::unordered_set& optionsToSkip = {EDNSOptionCode::COOKIE}) + static uint32_t hashAfterQname(const std::string_view& packet, uint32_t currentHash, size_t pos, const std::unordered_set& optionsToSkip = {EDNSOptionCode::COOKIE}) { const size_t packetSize = packet.size(); assert(packetSize >= sizeof(dnsheader)); diff --git a/pdns/protozero.cc b/pdns/protozero.cc index 218852cbc9..6f6fcf3503 100644 --- a/pdns/protozero.cc +++ b/pdns/protozero.cc @@ -95,7 +95,7 @@ void pdns::ProtoZero::Message::addRRsFromPacket(const char* packet, const size_t return; } - PacketReader pr(pdns_string_view(packet, len)); + PacketReader pr(std::string_view(packet, len)); size_t idx = 0; DNSName rrname; diff --git a/pdns/recursordist/ednsextendederror.cc b/pdns/recursordist/ednsextendederror.cc index bbb1224f9b..5010e3dba5 100644 --- a/pdns/recursordist/ednsextendederror.cc +++ b/pdns/recursordist/ednsextendederror.cc @@ -23,7 +23,7 @@ #include "ednsextendederror.hh" -static bool getEDNSExtendedErrorOptFromStringView(const pdns_string_view& option, EDNSExtendedError& eee) +static bool getEDNSExtendedErrorOptFromStringView(const std::string_view& option, EDNSExtendedError& eee) { if (option.size() < sizeof(uint16_t)) { return false; @@ -39,12 +39,12 @@ static bool getEDNSExtendedErrorOptFromStringView(const pdns_string_view& option bool getEDNSExtendedErrorOptFromString(const string& option, EDNSExtendedError& eee) { - return getEDNSExtendedErrorOptFromStringView(pdns_string_view(option), eee); + return getEDNSExtendedErrorOptFromStringView(std::string_view(option), eee); } bool getEDNSExtendedErrorOptFromString(const char* option, unsigned int len, EDNSExtendedError& eee) { - return getEDNSExtendedErrorOptFromStringView(pdns_string_view(option, len), eee); + return getEDNSExtendedErrorOptFromStringView(std::string_view(option, len), eee); } string makeEDNSExtendedErrorOptString(const EDNSExtendedError& eee) -- 2.47.2