]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
add appending to DNSName
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 20 Feb 2015 08:59:10 +0000 (09:59 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 20 Feb 2015 08:59:10 +0000 (09:59 +0100)
pdns/dnsname.hh
pdns/test-dnsname_cc.cc

index f043364635a8cb5c84fe89bd2f53865e54a4735a..4b6d5a26a1898617426f2322f0ed9e43588d4d08 100644 (file)
@@ -34,12 +34,25 @@ public:
   void prependRawLabel(const std::string& str); //!< Prepend this unescaped label
   std::deque<std::string> getRawLabels() const; //!< Individual raw unescaped labels
   bool chopOff();                               //!< Turn www.powerdns.com. into powerdns.com., returns false for .
+
+  DNSName& operator+=(const DNSName& rhs)
+  {
+    for(const auto& r : rhs.d_labels)
+      d_labels.push_back(r);
+    return *this;
+  }
 private:
   std::deque<std::string> d_labels;
   static std::string escapeLabel(const std::string& orig);
   static std::string unescapeLabel(const std::string& orig);
 };
 
+inline DNSName operator+(const DNSName& lhs, const DNSName& rhs)
+{
+  DNSName ret=lhs;
+  ret += rhs;
+  return ret;
+}
 
 /* Quest in life: serve as a rapid block list. If you add a DNSName to a root SuffixMatchNode, 
    anything part of that domain will return 'true' in check */
index b1212f77bf8452e19e564f47bbedb6a7ed0b82a1..6dc35e8c4c6350be2a7555f8eef3c61742282cd3 100644 (file)
@@ -123,6 +123,18 @@ BOOST_AUTO_TEST_CASE(test_chopping) {
   BOOST_CHECK_EQUAL(w.toString(), "a.root-servers.net.");
 }
 
+BOOST_AUTO_TEST_CASE(test_Append) {
+  DNSName dn("www."), powerdns("powerdns.com.");
+  DNSName tot=dn+powerdns;
+  
+  BOOST_CHECK_EQUAL(tot.toString(), "www.powerdns.com.");
+  BOOST_CHECK(tot == DNSName("www.powerdns.com."));
+
+  dn+=powerdns;
+
+  BOOST_CHECK(dn == DNSName("www.powerdns.com."));
+}
+
 BOOST_AUTO_TEST_CASE(test_packetParse) {
   vector<unsigned char> packet;
   DNSPacketWriter dpw(packet, "www.ds9a.nl.", QType::AAAA);