From 606400e75a0a538c63eb9de82d0b4ea392025776 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Wed, 13 Feb 2019 16:54:12 +0100 Subject: [PATCH] SuffixMatchNode: implement a proper toString() --- pdns/dnsname.hh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index f55d6cbf68..5c2b6bf016 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -348,6 +348,20 @@ struct SuffixMatchTree return child->lookup(labels); } + // Returns all end-nodes, fully qualified (not as separate labels) + std::vector getNodes() const { + std::vector ret; + if (endNode) { + ret.push_back(DNSName(d_name)); + } + for (const auto& child : children) { + auto nodes = child.getNodes(); + for (const auto &node: nodes) { + ret.push_back(node + DNSName(d_name)); + } + } + return ret; + } }; /* Quest in life: serve as a rapid block list. If you add a DNSName to a root SuffixMatchNode, @@ -356,15 +370,10 @@ struct SuffixMatchNode { SuffixMatchNode() {} - std::string d_human; SuffixMatchTree d_tree; void add(const DNSName& dnsname) { - if(!d_human.empty()) - d_human.append(", "); - d_human += dnsname.toString(); - d_tree.add(dnsname, true); } @@ -390,7 +399,16 @@ struct SuffixMatchNode std::string toString() const { - return d_human; + std::string ret; + bool first = true; + for (const auto &n: d_tree.getNodes()) { + if (!first) { + ret += ", "; + } + first = false; + ret += n.toString(); + } + return ret; } }; -- 2.47.2