]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move pdns_i*() from misc.hh to dnsname.hh. NFCI
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 13 Jul 2026 07:03:56 +0000 (09:03 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Mon, 13 Jul 2026 07:03:56 +0000 (09:03 +0200)
This will avoid future chicken-and-egg problems.

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/dnsname.hh
pdns/misc.hh
pdns/test-dnsname_cc.cc
pdns/test-misc_hh.cc

index fae6f1f8ae5a2c90ec65598f57d02d2bacf7d43f..5f8bc17066478efeed4da9efbf78f26c0e2f4855 100644 (file)
@@ -59,6 +59,58 @@ inline unsigned char dns_tolower(unsigned char chr)
   return dns_tolower_table[chr];
 }
 
+inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b)  __attribute__((pure));
+inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b)
+{
+  const unsigned char *aPtr = (const unsigned char*)a.data(), *bPtr = (const unsigned char*)b.data();
+  const unsigned char *aEptr = aPtr + a.length(), *bEptr = bPtr + b.length();
+  while(aPtr != aEptr && bPtr != bEptr) {
+    if (*aPtr != *bPtr) {
+      if (int rc = dns_tolower(*aPtr) - dns_tolower(*bPtr); rc != 0) {
+        return rc;
+      }
+    }
+    aPtr++;
+    bPtr++;
+  }
+  // At this point, one of the strings has been completely processed.
+  // Either both have the same length, and they are equal, or one of them
+  // is larger, and compares as higher.
+  if (aPtr == aEptr) {
+    if (bPtr != bEptr) {
+      return -1; // a < b
+    }
+  }
+  else {
+    return 1; // a > b
+  }
+  return 0; // a == b
+}
+
+inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b)  __attribute__((pure));
+inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b)
+{
+  return pdns_ilexicographical_compare_three_way(a, b) < 0;
+}
+
+inline bool pdns_iequals(const std::string& a, const std::string& b) __attribute__((pure));
+inline bool pdns_iequals(const std::string& a, const std::string& b)
+{
+  if (a.length() != b.length())
+    return false;
+
+  return pdns_ilexicographical_compare_three_way(a, b) == 0;
+}
+
+inline bool pdns_iequals_ch(const char a, const char b) __attribute__((pure));
+inline bool pdns_iequals_ch(const char a, const char b)
+{
+  if ((a != b) && (dns_tolower(a) != dns_tolower(b)))
+    return false;
+
+  return true;
+}
+
 #include "burtle.hh"
 #include "views.hh"
 
index de314d1e680e71ecd3e05c94fe975ea0bccdbdf4..f488e04afadd81750906c1d79c434e6b484efbc2 100644 (file)
@@ -373,59 +373,6 @@ inline bool operator<(const struct timespec& lhs, const struct timespec& rhs)
 }
 
 
-inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b)  __attribute__((pure));
-inline int pdns_ilexicographical_compare_three_way(std::string_view a, std::string_view b)
-{
-  const unsigned char *aPtr = (const unsigned char*)a.data(), *bPtr = (const unsigned char*)b.data();
-  const unsigned char *aEptr = aPtr + a.length(), *bEptr = bPtr + b.length();
-  while(aPtr != aEptr && bPtr != bEptr) {
-    if (*aPtr != *bPtr) {
-      if (int rc = dns_tolower(*aPtr) - dns_tolower(*bPtr); rc != 0) {
-        return rc;
-      }
-    }
-    aPtr++;
-    bPtr++;
-  }
-  // At this point, one of the strings has been completely processed.
-  // Either both have the same length, and they are equal, or one of them
-  // is larger, and compares as higher.
-  if (aPtr == aEptr) {
-    if (bPtr != bEptr) {
-      return -1; // a < b
-    }
-  }
-  else {
-    return 1; // a > b
-  }
-  return 0; // a == b
-}
-
-inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b)  __attribute__((pure));
-inline bool pdns_ilexicographical_compare(const std::string& a, const std::string& b)
-{
-  return pdns_ilexicographical_compare_three_way(a, b) < 0;
-}
-
-inline bool pdns_iequals(const std::string& a, const std::string& b) __attribute__((pure));
-inline bool pdns_iequals(const std::string& a, const std::string& b)
-{
-  if (a.length() != b.length())
-    return false;
-
-  return pdns_ilexicographical_compare_three_way(a, b) == 0;
-}
-
-inline bool pdns_iequals_ch(const char a, const char b) __attribute__((pure));
-inline bool pdns_iequals_ch(const char a, const char b)
-{
-  if ((a != b) && (dns_tolower(a) != dns_tolower(b)))
-    return false;
-
-  return true;
-}
-
-
 typedef unsigned long AtomicCounterInner;
 typedef std::atomic<AtomicCounterInner> AtomicCounter ;
 
index 0aafae488b18fdd20ce927b67baa63fc248c3484..5b17e28dab81fc3eb5db9c47c208660e0ae7e78f 100644 (file)
@@ -5,6 +5,8 @@
 #define BOOST_TEST_NO_MAIN
 
 #include <boost/test/unit_test.hpp>
+#include <boost/assign/list_of.hpp>
+#include <boost/tuple/tuple.hpp>
 
 #include <cmath>
 #include <numeric>
@@ -1107,4 +1109,50 @@ BOOST_AUTO_TEST_CASE(test_variantnames) {
 }
 #endif
 
+BOOST_AUTO_TEST_CASE(test_pdns_ilexicographical_compare) {
+  typedef boost::tuple<const std::string, const std::string, bool> case_t;
+  typedef std::list<case_t> cases_t;
+
+  cases_t cases = boost::assign::list_of
+    (case_t(std::string(""), std::string(""), false))
+    (case_t(std::string(""), std::string("abc"), true))
+    (case_t(std::string("abc"), std::string(""), false))
+    (case_t(std::string("abc"), std::string("abcd"), true))
+    (case_t(std::string("abcd"), std::string("abc"), false))
+    (case_t(std::string("abd"), std::string("abc"), false))
+    (case_t(std::string("abc"), std::string("abd"), true))
+    (case_t(std::string("abc"), std::string("Abc"), false))
+    (case_t(std::string("Abc"), std::string("abc"), false))
+  ;
+
+  for(const case_t& val :  cases) {
+    bool res;
+    res = pdns_ilexicographical_compare(val.get<0>(), val.get<1>());
+    BOOST_CHECK_EQUAL(res, val.get<2>());
+  }
+}
+
+BOOST_AUTO_TEST_CASE(test_pdns_iequals) {
+  typedef boost::tuple<const std::string, const std::string, bool> case_t;
+  typedef std::list<case_t> cases_t;
+
+  cases_t cases = boost::assign::list_of
+    (case_t(std::string(""), std::string(""), true))
+    (case_t(std::string(""), std::string("abc"), false))
+    (case_t(std::string("abc"), std::string(""), false))
+    (case_t(std::string("abc"), std::string("abcd"), false))
+    (case_t(std::string("abcd"), std::string("abc"), false))
+    (case_t(std::string("abd"), std::string("abc"), false))
+    (case_t(std::string("abc"), std::string("abd"), false))
+    (case_t(std::string("abc"), std::string("Abc"), true))
+    (case_t(std::string("Abc"), std::string("abc"), true))
+  ;
+
+  for(const case_t& val :  cases) {
+    bool res;
+    res = pdns_iequals(val.get<0>(), val.get<1>());
+    BOOST_CHECK_EQUAL(res, val.get<2>());
+  }
+}
+
 BOOST_AUTO_TEST_SUITE_END()
index 27a77de4273fb54f00331d62fe8137caab6a7754..bd5a8eff2c153c64ad8511412aa4746236a86622 100644 (file)
@@ -12,8 +12,6 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/assign/list_of.hpp>
 
-#include <boost/tuple/tuple.hpp>
-
 #include <arpa/inet.h>
 
 #include "dns.hh"
@@ -63,52 +61,6 @@ BOOST_AUTO_TEST_CASE(test_CIStringPairCompare) {
         BOOST_CHECK_EQUAL(s.str(), "(|1)(abc|1)(abc|2)(def|1)(ns.example.com|0)(ns.example.com|1)");
 }
 
-BOOST_AUTO_TEST_CASE(test_pdns_ilexicographical_compare) {
-  typedef boost::tuple<const std::string, const std::string, bool> case_t;
-  typedef std::list<case_t> cases_t;
-
-  cases_t cases = boost::assign::list_of
-    (case_t(std::string(""), std::string(""), false))
-    (case_t(std::string(""), std::string("abc"), true))
-    (case_t(std::string("abc"), std::string(""), false))
-    (case_t(std::string("abc"), std::string("abcd"), true))
-    (case_t(std::string("abcd"), std::string("abc"), false))
-    (case_t(std::string("abd"), std::string("abc"), false))
-    (case_t(std::string("abc"), std::string("abd"), true))
-    (case_t(std::string("abc"), std::string("Abc"), false))
-    (case_t(std::string("Abc"), std::string("abc"), false))
-  ;
-
-  for(const case_t& val :  cases) {
-    bool res;
-    res = pdns_ilexicographical_compare(val.get<0>(), val.get<1>());
-    BOOST_CHECK_EQUAL(res, val.get<2>());
-  }
-}
-
-BOOST_AUTO_TEST_CASE(test_pdns_iequals) {
-  typedef boost::tuple<const std::string, const std::string, bool> case_t;
-  typedef std::list<case_t> cases_t;
-
-  cases_t cases = boost::assign::list_of
-    (case_t(std::string(""), std::string(""), true))
-    (case_t(std::string(""), std::string("abc"), false))
-    (case_t(std::string("abc"), std::string(""), false))
-    (case_t(std::string("abc"), std::string("abcd"), false))
-    (case_t(std::string("abcd"), std::string("abc"), false))
-    (case_t(std::string("abd"), std::string("abc"), false))
-    (case_t(std::string("abc"), std::string("abd"), false))
-    (case_t(std::string("abc"), std::string("Abc"), true))
-    (case_t(std::string("Abc"), std::string("abc"), true))
-  ;
-
-  for(const case_t& val :  cases) {
-    bool res;
-    res = pdns_iequals(val.get<0>(), val.get<1>());
-    BOOST_CHECK_EQUAL(res, val.get<2>());
-  }
-}
-
 BOOST_AUTO_TEST_CASE(test_stripDot) {
   BOOST_CHECK_EQUAL(stripDot("."), "");
   BOOST_CHECK_EQUAL(stripDot(""), "");