]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Let ZoneName::toString*() output the variant, if any.
authorMiod Vallat <miod.vallat@powerdns.com>
Fri, 27 Jun 2025 06:33:58 +0000 (08:33 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Fri, 27 Jun 2025 08:15:09 +0000 (10:15 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/dnsname.cc
pdns/dnsname.hh
pdns/ws-auth.cc

index cdbc101380b2ae9e9a11cf420381a199be0e7f9c..5edcf7d0dd12932050144c34d5b149e3899be2c3 100644 (file)
@@ -828,7 +828,7 @@ std::string ZoneName::toLogString() const
   return ret;
 }
 
-std::string ZoneName::toStringFull(const std::string& separator, const bool trailing) const
+std::string ZoneName::toString(const std::string& separator, const bool trailing) const
 {
   std::string ret = d_name.toString(separator, trailing);
   if (!d_variant.empty()) {
@@ -841,6 +841,29 @@ std::string ZoneName::toStringFull(const std::string& separator, const bool trai
   return ret;
 }
 
+std::string ZoneName::toStringNoDot() const
+{
+  std::string ret = d_name.toStringNoDot();
+  if (!d_variant.empty()) {
+    ret += "..";
+    ret += d_variant;
+  }
+  return ret;
+}
+
+std::string ZoneName::toStringRootDot() const
+{
+  std::string ret = d_name.toStringRootDot();
+  if (!d_variant.empty()) {
+    if (!d_name.isRoot()) {
+      ret.push_back('.');
+    }
+    ret.push_back('.');
+    ret += d_variant;
+  }
+  return ret;
+}
+
 size_t ZoneName::hash(size_t init) const
 {
   if (!d_variant.empty()) {
index 6880fdfd45e0ef810b6a0dd5e8b5e740a850e876..601904aac912206e7de9c8732cc8889c50e47bf6 100644 (file)
@@ -361,13 +361,12 @@ public:
   bool operator==(const ZoneName& rhs) const { return d_name == rhs.d_name && d_variant == rhs.d_variant; }
   bool operator!=(const ZoneName& rhs) const { return !operator==(rhs); }
 
-  // IMPORTANT! None of the "toString" routines will output the variant, but toLogString() and toStringFull().
-  std::string toString(const std::string& separator=".", const bool trailing=true) const { return d_name.toString(separator, trailing); }
-  void toString(std::string& output, const std::string& separator=".", const bool trailing=true) const { d_name.toString(output, separator, trailing); }
+  std::string toString(const std::string& separator=".", const bool trailing=true) const;
+  void toString(std::string& output, const std::string& separator=".", const bool trailing=true) const { output = toString(separator, trailing); }
   std::string toLogString() const;
-  std::string toStringNoDot() const { return d_name.toStringNoDot(); }
-  std::string toStringRootDot() const { return d_name.toStringRootDot(); }
-  std::string toStringFull(const std::string& separator=".", const bool trailing=true) const;
+  std::string toStringNoDot() const;
+  std::string toStringRootDot() const;
+  std::string toStringFull(const std::string& separator=".", const bool trailing=true) const { return toString(separator, trailing); }
 
   bool chopOff() { return d_name.chopOff(); }
   ZoneName makeLowerCase() const
index b49df078c6df266da59e3ec6d92ce4c490cccb72..8c7e3219313555ec8ed760f05c42b5b4113ae863 100644 (file)
@@ -2694,13 +2694,7 @@ static void prometheusMetrics(HttpRequest* /* req */, HttpResponse* resp)
 static void jsonFillZoneNameArray(Json::array& array, std::vector<ZoneName>& zones)
 {
   for (const auto& zone : zones) {
-    // Remember ZoneName::toString() intentionally omits the variant
-    std::string name(zone.toString());
-    if (zone.hasVariant()) {
-      name.push_back('.');
-      name += zone.getVariant();
-    }
-    array.emplace_back(name);
+    array.emplace_back(zone.toString());
   }
 }