From: bert hubert Date: Fri, 26 Aug 2016 13:04:35 +0000 (+0200) Subject: add pre-made DNSName objects for the root and wildcard. Move DNSName== inline. Revers... X-Git-Tag: dnsdist-1.1.0-beta2~166^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c21484dfdd7a70da21defc322b2140fa02ac607a;p=pdns add pre-made DNSName objects for the root and wildcard. Move DNSName== inline. Reverse its comparison order. --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 0d7eaa94f..8c5b2834f 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -28,6 +28,8 @@ #include +const DNSName g_rootdnsname("."), g_wildcarddnsname("*"); + /* raw storage in DNS label format, with trailing 0. W/o trailing 0, we are 'empty' www.powerdns.com = 3www8powerdns3com0 @@ -355,19 +357,6 @@ void DNSName::trimToLabels(unsigned int to) ; } -bool DNSName::operator==(const DNSName& rhs) const -{ - if(rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size()) - return false; - - auto us = d_storage.crbegin(); - auto p = rhs.d_storage.crbegin(); - for(; us != d_storage.crend() && p != rhs.d_storage.crend(); ++us, ++p) { // why does this go backward? - if(dns2_tolower(*p) != dns2_tolower(*us)) - return false; - } - return true; -} size_t hash_value(DNSName const& d) { diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 1815bbecf..7a668068a 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -56,7 +56,7 @@ uint32_t burtleCI(const unsigned char* k, uint32_t lengh, uint32_t init); inline char dns2_tolower(char c) { if(c>='A' && c<='Z') - c+='a'-'A'; + return c+('a'-'A'); return c; } @@ -69,7 +69,7 @@ public: DNSName(const char* p, int len, int offset, bool uncompress, uint16_t* qtype=0, uint16_t* qclass=0, unsigned int* consumed=0, uint16_t minOffset=0); //!< Construct from a DNS Packet, taking the first question if offset=12 bool isPartOf(const DNSName& rhs) const; //!< Are we part of the rhs name? - bool operator==(const DNSName& rhs) const; //!< DNS-native comparison (case insensitive) - empty compares to empty + 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); } std::string toString(const std::string& separator=".", const bool trailing=true) const; //!< Our human-friendly, escaped, representation @@ -138,7 +138,9 @@ public: #else typedef std::string string_t; #endif - + const string_t& getStorage() const { + return d_storage; + } private: string_t d_storage; @@ -299,3 +301,18 @@ namespace std { } DNSName::string_t segmentDNSNameRaw(const char* input); // from ragel +bool DNSName::operator==(const DNSName& rhs) const +{ + if(rhs.empty() != empty() || rhs.d_storage.size() != d_storage.size()) + return false; + + auto us = d_storage.cbegin(); + auto p = rhs.d_storage.cbegin(); + for(; us != d_storage.cend() && p != rhs.d_storage.cend(); ++us, ++p) { + if(dns2_tolower(*p) != dns2_tolower(*us)) + return false; + } + return true; +} + +extern const DNSName g_rootdnsname, g_wildcarddnsname;