And rename it to hopefully prevent any confusion regarding when it can be used.
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
const std::string_view packetView(reinterpret_cast<const char*>(response.data() + sizeof(dnsheader)), response.size() - sizeof(dnsheader));
- if (qname.matches(packetView)) {
+ if (qname.matchesUncompressedName(packetView)) {
size_t pos = sizeof(dnsheader) + qname.wirelength();
rqtype = response.at(pos) * 256 + response.at(pos + 1);
rqclass = response.at(pos + 2) * 256 + response.at(pos + 3);
return d_position == 0;
}
-bool DNSName::matches(const std::string_view& wire_uncompressed) const
+bool DNSName::matchesUncompressedName(const std::string_view& wire_uncompressed) const
{
if (wire_uncompressed.empty() != empty() || wire_uncompressed.size() < d_storage.size()) {
return false;
}
- const auto* our = d_storage.cbegin();
- const auto* other = wire_uncompressed.cbegin();
- // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
- for (; our != d_storage.cend() && other != wire_uncompressed.cend(); ++our, ++other) {
- if (dns_tolower(*other) != dns_tolower(*our)) {
- return false;
- }
- }
-
- return our == d_storage.cend();
+ return pdns_ilexicographical_compare_three_way(std::string_view(wire_uncompressed.data(), d_storage.size()), d_storage) == 0;
}
#if defined(PDNS_AUTH) // [
bool isPartOf(const DNSName& rhs) const; //!< Are we part of the rhs name? Note that name.isPartOf(name).
inline bool operator==(const DNSName& rhs) const; //!< DNS-native comparison (case insensitive) - empty compares to empty
bool operator!=(const DNSName& other) const { return !(*this == other); }
- // !< DNS-native (case insensitive) comparison against raw data in wire format. The view has to start with the DNS name, but does not have to contain only a DNS name. For example passing a view of a DNS packet starting just after the DNS header is OK.
- bool matches(const std::string_view& wire_uncompressed) const;
+ // !< DNS-native (case insensitive) comparison against raw data in (uncompressed) wire format. The view has to start with the DNS name, but does not have to contain only a DNS name. Roughly, passing a view of a DNS packet starting just after the DNS header is OK, everything else is not because any names present later in the packet might be compressed.
+ bool matchesUncompressedName(const std::string_view& wire_uncompressed) const;
std::string toString(const std::string& separator=".", const bool trailing=true) const; //!< Our human-friendly, escaped, representation
void toString(std::string& output, const std::string& separator=".", const bool trailing=true) const;
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
const std::string_view raw(reinterpret_cast<const char*>(query.data()) + sizeof(dnsheader), query.size() - sizeof(dnsheader));
- BOOST_CHECK(aroot.matches(raw));
+ BOOST_CHECK(aroot.matchesUncompressedName(raw));
const DNSName differentCase("A.RooT-Servers.NET");
- BOOST_CHECK(differentCase.matches(raw));
+ BOOST_CHECK(differentCase.matchesUncompressedName(raw));
const DNSName broot("b.root-servers.net");
- BOOST_CHECK(!(broot.matches(raw)));
+ BOOST_CHECK(!(broot.matchesUncompressedName(raw)));
/* last character differs */
const DNSName notaroot("a.root-servers.nes");
- BOOST_CHECK(!(notaroot.matches(raw)));
+ BOOST_CHECK(!(notaroot.matchesUncompressedName(raw)));
}
{
/* too short */
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,cppcoreguidelines-pro-bounds-pointer-arithmetic)
const std::string_view raw(reinterpret_cast<const char*>(query.data() + sizeof(dnsheader)), aroot.wirelength() - 1);
- BOOST_CHECK(!(aroot.matches(raw)));
+ BOOST_CHECK(!(aroot.matchesUncompressedName(raw)));
}
}