]> granicus.if.org Git - pdns/commitdiff
add pre-made DNSName objects for the root and wildcard. Move DNSName== inline. Revers...
authorbert hubert <bert.hubert@powerdns.com>
Fri, 26 Aug 2016 13:04:35 +0000 (15:04 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Sat, 27 Aug 2016 12:15:54 +0000 (14:15 +0200)
pdns/dnsname.cc
pdns/dnsname.hh

index 0d7eaa94f81ebc1822c8fe8fa7493f850db9af7e..8c5b2834f613d9a62435d0884d1953407752f3ea 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <boost/functional/hash.hpp>
 
+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)
 {
index 1815bbecf7fec481c465597933cfb1d580af2d0c..7a668068a9024d083626bd0ad4e6533a2abcc4d4 100644 (file)
@@ -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;