]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1397] Add std::string version of Rset::addRdata()
authorMukund Sivaraman <muks@isc.org>
Thu, 16 Jan 2014 12:38:41 +0000 (18:08 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 16 Jan 2014 12:38:41 +0000 (18:08 +0530)
src/lib/dns/rrset.cc
src/lib/dns/rrset.h
src/lib/dns/tests/rrset_unittest.cc

index 0d34d1921b8a33192a48b059cee9255044ee3700..e128c76079bb1f0b3020baaba1ba30353c309282 100644 (file)
@@ -194,6 +194,11 @@ BasicRRset::addRdata(const Rdata& rdata) {
     AbstractRRset::addRdata(rdata);
 }
 
+void
+BasicRRset::addRdata(const std::string& rdata_str) {
+    addRdata(createRdata(getType(), getClass(), rdata_str));
+}
+
 unsigned int
 BasicRRset::getRdataCount() const {
     return (impl_->rdatalist_.size());
index eb8fa6ed0c7e7851b4cbbcd2c68c753d9fc40806..f1bd4fc3c12c84f762c08f07fe282b6a9e0a29a1 100644 (file)
@@ -380,6 +380,16 @@ public:
     /// object, a copy of which is to be added to the \c RRset.
     virtual void addRdata(const rdata::Rdata& rdata) = 0;
 
+    /// \brief Add an RDATA to the RRset (string version).
+    ///
+    /// This method constructs an Rdata object from the the given
+    /// \c rdata_str in presentation format and adds it to the \c RRset.
+    ///
+    /// \param rdata_str RDATA string in presentation format.
+    /// \throw InvalidRdataText if the \c rdata_str is invalid for this
+    /// \c RRset.
+    virtual void addRdata(const std::string& rdata_str) = 0;
+
     /// \brief Return an iterator to go through all RDATA stored in the
     /// \c RRset.
     ///
@@ -727,6 +737,13 @@ public:
     /// See \c AbstractRRset::addRdata(const rdata::Rdata&).
     virtual void addRdata(const rdata::Rdata& rdata);
 
+    /// \brief Add an RDATA to the RRset (string version).
+    ///
+    /// \param rdata_str RDATA string in presentation format.
+    /// \throw InvalidRdataText if the \c rdata_str is invalid for this
+    /// \c RRset.
+    virtual void addRdata(const std::string& rdata_str);
+
     /// \brief Return an iterator to go through all RDATA stored in the
     /// \c BasicRRset.
     ///
index 78276cbbae5f78bc2606e647d4e3189a41a842e4..6e85380a6f8b83b8dff7bb3f18f331b2da7caa2d 100644 (file)
@@ -166,6 +166,18 @@ TEST_F(RRsetTest, addRdataPtr) {
     EXPECT_EQ(3, rrset_a_empty.getRdataCount());
 }
 
+TEST_F(RRsetTest, addRdataString) {
+    rrset_a_empty.addRdata("192.0.2.1");
+    rrset_a_empty.addRdata("192.0.2.2");
+
+    addRdataTestCommon(rrset_a_empty);
+
+    // String version of addRdata() will throw for bad RDATA for
+    // RRType::A().
+    EXPECT_THROW(rrset_a_empty.addRdata("ns.example.com."), InvalidRdataText);
+    addRdataTestCommon(rrset_a_empty);
+}
+
 TEST_F(RRsetTest, iterator) {
     // Iterator for an empty RRset.
     RdataIteratorPtr it = rrset_a_empty.getRdataIterator();