]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move stripDomainSuffix() to its only user and make it static.
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 27 Jun 2025 05:50:28 +0000 (07:50 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Fri, 27 Jun 2025 06:43:08 +0000 (08:43 +0200)
This also moves ciEqual() and endsOn() which are only used by
stripDomainSuffix().

Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
modules/bindbackend/bindbackend2.cc
pdns/misc.cc
pdns/misc.hh

index f9beb39cd1dd4f8e94dbd2cc82ab32002334f095..b0a54c68c9ddc87aeafa479d9a689d0a3c937328 100644 (file)
@@ -281,6 +281,69 @@ bool Bind2Backend::abortTransaction()
   return true;
 }
 
+static bool ciEqual(const string& lhs, const string& rhs)
+{
+  if (lhs.size() != rhs.size()) {
+    return false;
+  }
+
+  string::size_type pos = 0;
+  const string::size_type epos = lhs.size();
+  for (; pos < epos; ++pos) {
+    if (dns_tolower(lhs[pos]) != dns_tolower(rhs[pos])) {
+      return false;
+    }
+  }
+  return true;
+}
+
+/** does domain end on suffix? Is smart about "wwwds9a.nl" "ds9a.nl" not matching */
+static bool endsOn(const string& domain, const string& suffix)
+{
+  if (suffix.empty() || ciEqual(domain, suffix)) {
+    return true;
+  }
+
+  if (domain.size() <= suffix.size()) {
+    return false;
+  }
+
+  string::size_type dpos = domain.size() - suffix.size() - 1;
+  string::size_type spos = 0;
+
+  if (domain[dpos++] != '.') {
+    return false;
+  }
+
+  for (; dpos < domain.size(); ++dpos, ++spos) {
+    if (dns_tolower(domain[dpos]) != dns_tolower(suffix[spos])) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+/** strips a domain suffix from a domain, returns true if it stripped */
+static bool stripDomainSuffix(string* qname, const string& domain)
+{
+  if (!endsOn(*qname, domain)) {
+    return false;
+  }
+
+  if (toLower(*qname) == toLower(domain)) {
+    *qname = "@";
+  }
+  else {
+    if ((*qname)[qname->size() - domain.size() - 1] != '.') {
+      return false;
+    }
+
+    qname->resize(qname->size() - domain.size() - 1);
+  }
+  return true;
+}
+
 bool Bind2Backend::feedRecord(const DNSResourceRecord& rr, const DNSName& /* ordername */, bool /* ordernameIsNSEC3 */)
 {
   if (d_transaction_id == UnknownDomainID) {
index a8b5694f7655e7b9d9b51bedd3b8610f45cf0d53..913848fabf7f1163dfe86bfb9055067215395346 100644 (file)
@@ -308,69 +308,6 @@ string nowTime()
   return {buffer.data()};
 }
 
-static bool ciEqual(const string& lhs, const string& rhs)
-{
-  if (lhs.size() != rhs.size()) {
-    return false;
-  }
-
-  string::size_type pos = 0;
-  const string::size_type epos = lhs.size();
-  for (; pos < epos; ++pos) {
-    if (dns_tolower(lhs[pos]) != dns_tolower(rhs[pos])) {
-      return false;
-    }
-  }
-  return true;
-}
-
-/** does domain end on suffix? Is smart about "wwwds9a.nl" "ds9a.nl" not matching */
-static bool endsOn(const string &domain, const string &suffix)
-{
-  if( suffix.empty() || ciEqual(domain, suffix) ) {
-    return true;
-  }
-
-  if(domain.size() <= suffix.size()) {
-    return false;
-  }
-
-  string::size_type dpos = domain.size() - suffix.size() - 1;
-  string::size_type spos = 0;
-
-  if (domain[dpos++] != '.') {
-    return false;
-  }
-
-  for(; dpos < domain.size(); ++dpos, ++spos) {
-    if (dns_tolower(domain[dpos]) != dns_tolower(suffix[spos])) {
-      return false;
-    }
-  }
-
-  return true;
-}
-
-/** strips a domain suffix from a domain, returns true if it stripped */
-bool stripDomainSuffix(string *qname, const string &domain)
-{
-  if (!endsOn(*qname, domain)) {
-    return false;
-  }
-
-  if (toLower(*qname) == toLower(domain)) {
-    *qname="@";
-  }
-  else {
-    if ((*qname)[qname->size() - domain.size() - 1] != '.') {
-      return false;
-    }
-
-    qname->resize(qname->size() - domain.size()-1);
-  }
-  return true;
-}
-
 // returns -1 in case if error, 0 if no data is available, 1 if there is. In the first two cases, errno is set
 int waitForData(int fileDesc, int seconds, int useconds)
 {
index 0b2d0883833edec5fd1c77c17bdec0951b6505f2..5471df6cfef7605c01ff83706573febdded3f66e 100644 (file)
@@ -102,7 +102,6 @@ namespace OpenSSL
 string nowTime();
 string unquotify(const string &item);
 string humanDuration(time_t passed);
-bool stripDomainSuffix(string *qname, const string &domain);
 void stripLine(string &line);
 std::optional<string> getHostname();
 std::string getCarbonHostName();