From: bert hubert Date: Fri, 20 Feb 2015 08:59:10 +0000 (+0100) Subject: add appending to DNSName X-Git-Tag: dnsdist-1.0.0-alpha1~248^2~88^2~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6dcedea6018fe6bb72c28540ad98cfaf837c9bab;p=thirdparty%2Fpdns.git add appending to DNSName --- diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index f043364635..4b6d5a26a1 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -34,12 +34,25 @@ public: void prependRawLabel(const std::string& str); //!< Prepend this unescaped label std::deque 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 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 */ diff --git a/pdns/test-dnsname_cc.cc b/pdns/test-dnsname_cc.cc index b1212f77bf..6dc35e8c4c 100644 --- a/pdns/test-dnsname_cc.cc +++ b/pdns/test-dnsname_cc.cc @@ -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 packet; DNSPacketWriter dpw(packet, "www.ds9a.nl.", QType::AAAA);