]> granicus.if.org Git - pdns/commitdiff
pdns: remove duplicated dns2_tolower() function
authorThiago Farina <tfarina@chromium.org>
Wed, 29 Mar 2017 01:12:43 +0000 (22:12 -0300)
committerThiago Farina <tfarina@chromium.org>
Fri, 7 Apr 2017 11:19:39 +0000 (08:19 -0300)
There is already a version of dns2_tolower() in misc.hh, called
simply dns_tolower(), but due to some inclusion issues it was necessary
to extract it into another header file (named ascii.hh).

pdns/ascii.hh [new file with mode: 0644]
pdns/dnsdistdist/ascii.hh [new symlink]
pdns/dnsname.cc
pdns/dnsname.hh
pdns/misc.hh
pdns/recursordist/ascii.hh [new symlink]

diff --git a/pdns/ascii.hh b/pdns/ascii.hh
new file mode 100644 (file)
index 0000000..69b1a39
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#pragma once
+
+inline unsigned char dns_tolower(unsigned char c)
+{
+  if(c>='A' && c<='Z')
+    c+='a'-'A';
+  return c;
+}
diff --git a/pdns/dnsdistdist/ascii.hh b/pdns/dnsdistdist/ascii.hh
new file mode 120000 (symlink)
index 0000000..6d5e3eb
--- /dev/null
@@ -0,0 +1 @@
+../ascii.hh
\ No newline at end of file
index 3f98d84877a9f284096a7a3b80ba0f49cc2e3ecc..6f5eab5c778c0015524718524876b52e047c9b0c 100644 (file)
@@ -225,7 +225,7 @@ bool DNSName::isPartOf(const DNSName& parent) const
     if (static_cast<size_t>(distance) == parent.d_storage.size()) {
       auto p = parent.d_storage.cbegin();
       for(; us != d_storage.cend(); ++us, ++p) {
-        if(dns2_tolower(*p) != dns2_tolower(*us))
+        if(dns_tolower(*p) != dns_tolower(*us))
           return false;
       }
       return true;
index eba45665cab76660b73a54a9d02f838dbef228e7..9dd388a5b2c170d9b00ce4c6fe7bece43f4fd969 100644 (file)
@@ -34,6 +34,8 @@
 #include <boost/container/string.hpp>
 #endif
 
+#include "ascii.hh"
+
 uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t init);
 
 // #include "dns.hh"
@@ -53,13 +55,6 @@ uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t init);
    NOTE: For now, everything MUST be . terminated, otherwise it is an error
 */
 
-inline unsigned char dns2_tolower(unsigned char c)
-{
-  if(c>='A' && c<='Z')
-    return c+('a'-'A');
-  return c;
-}
-
 class DNSName
 {
 public:
@@ -90,7 +85,7 @@ public:
     DNSName ret;
     ret.d_storage = d_storage;
     for(auto & c : ret.d_storage) {
-      c=dns2_tolower(c);
+      c=dns_tolower(c);
     }
     return ret;
   }
@@ -128,7 +123,7 @@ public:
     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 dns2_tolower(a) < dns2_tolower(b); 
+                                         return dns_tolower(a) < dns_tolower(b);
                                        }); // note that this is case insensitive, including on the label lengths
   }
 
@@ -192,7 +187,7 @@ inline bool DNSName::canonCompare(const DNSName& rhs) const
                                          rhs.d_storage.c_str() + rhspos[rhscount] + 1, 
                                          rhs.d_storage.c_str() + rhspos[rhscount] + 1 + *(rhs.d_storage.c_str() + rhspos[rhscount]),
                                          [](const unsigned char& a, const unsigned char& b) {
-                                           return dns2_tolower(a) < dns2_tolower(b); 
+                                           return dns_tolower(a) < dns_tolower(b);
                                          });
     
     //    cout<<"Forward: "<<res<<endl;
@@ -204,7 +199,7 @@ inline bool DNSName::canonCompare(const DNSName& rhs) const
                                          d_storage.c_str() + ourpos[ourcount] + 1, 
                                          d_storage.c_str() + ourpos[ourcount] + 1 + *(d_storage.c_str() + ourpos[ourcount]),
                                          [](const unsigned char& a, const unsigned char& b) {
-                                           return dns2_tolower(a) < dns2_tolower(b); 
+                                           return dns_tolower(a) < dns_tolower(b);
                                          });
     //    cout<<"Reverse: "<<res<<endl;
     if(res)
@@ -374,7 +369,7 @@ bool DNSName::operator==(const DNSName& rhs) const
   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))
+    if(dns_tolower(*p) != dns_tolower(*us))
       return false;
   }
   return true;
index 95493279fdcfafda802f7fbd4cab81e9c6e1338b..fe5f796fdcbad87f08260158e3ace748f86edd8f 100644 (file)
@@ -235,13 +235,6 @@ inline bool dns_isspace(char c)
   return c==' ' || c=='\t' || c=='\r' || c=='\n';
 }
 
-inline unsigned char dns_tolower(unsigned char c)
-{
-  if(c>='A' && c<='Z')
-    c+='a'-'A';
-  return c;
-}
-
 inline unsigned char dns_toupper(unsigned char c)
 {
   if(c>='a' && c<='z')
diff --git a/pdns/recursordist/ascii.hh b/pdns/recursordist/ascii.hh
new file mode 120000 (symlink)
index 0000000..6d5e3eb
--- /dev/null
@@ -0,0 +1 @@
+../ascii.hh
\ No newline at end of file