Browse Source

[2497] Introduce a new AbstractRdataFactory::create() that takes a MasterLexer

Also have a default implementation that simply concatenates
all token data into a string and calls the create() variant
which accepts a string.
Mukund Sivaraman 12 years ago
parent
commit
1b6614825a

+ 2 - 0
src/lib/dns/rrparamregistry-placeholder.cc

@@ -163,6 +163,8 @@ typedef map<RRType, RdataFactoryPtr> GenericRdataFactoryMap;
 template <typename T>
 template <typename T>
 class RdataFactory : public AbstractRdataFactory {
 class RdataFactory : public AbstractRdataFactory {
 public:
 public:
+    using AbstractRdataFactory::create;
+
     virtual RdataPtr create(const string& rdata_str) const
     virtual RdataPtr create(const string& rdata_str) const
     {
     {
         return (RdataPtr(new T(rdata_str)));
         return (RdataPtr(new T(rdata_str)));

+ 29 - 3
src/lib/dns/rrparamregistry.h

@@ -24,6 +24,9 @@
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
 
 
 #include <dns/rdata.h>
 #include <dns/rdata.h>
+#include <dns/master_lexer.h>
+#include <dns/master_loader.h>
+#include <dns/master_loader_callbacks.h>
 
 
 namespace isc {
 namespace isc {
 namespace dns {
 namespace dns {
@@ -82,7 +85,7 @@ public:
     /// \name Factory methods for polymorphic creation.
     /// \name Factory methods for polymorphic creation.
     ///
     ///
     //@{
     //@{
-    ///
+
     /// \brief Create RDATA from a string.
     /// \brief Create RDATA from a string.
     ///
     ///
     /// This method creates from a string an \c Rdata object of specific class
     /// This method creates from a string an \c Rdata object of specific class
@@ -91,7 +94,7 @@ public:
     /// \param rdata_str A string of textual representation of the \c Rdata.
     /// \param rdata_str A string of textual representation of the \c Rdata.
     /// \return An \c RdataPtr object pointing to the created \c Rdata object.
     /// \return An \c RdataPtr object pointing to the created \c Rdata object.
     virtual RdataPtr create(const std::string& rdata_str) const = 0;
     virtual RdataPtr create(const std::string& rdata_str) const = 0;
-    ///
+
     /// \brief Create RDATA from wire-format data.
     /// \brief Create RDATA from wire-format data.
     ///
     ///
     /// This method creates from wire-format binary data an \c Rdata object
     /// This method creates from wire-format binary data an \c Rdata object
@@ -103,7 +106,7 @@ public:
     /// \param rdata_len The length in buffer of the \c Rdata.  In bytes.
     /// \param rdata_len The length in buffer of the \c Rdata.  In bytes.
     /// \return An \c RdataPtr object pointing to the created \c Rdata object.
     /// \return An \c RdataPtr object pointing to the created \c Rdata object.
     virtual RdataPtr create(isc::util::InputBuffer& buffer, size_t rdata_len) const = 0;
     virtual RdataPtr create(isc::util::InputBuffer& buffer, size_t rdata_len) const = 0;
-    ///
+
     /// \brief Create RDATA from another \c Rdata object of the same type.
     /// \brief Create RDATA from another \c Rdata object of the same type.
     ///
     ///
     /// This method creates an \c Rdata object of specific class corresponding
     /// This method creates an \c Rdata object of specific class corresponding
@@ -118,6 +121,29 @@ public:
     /// be copied to the created \c Rdata object.
     /// be copied to the created \c Rdata object.
     /// \return An \c RdataPtr object pointing to the created \c Rdata object.
     /// \return An \c RdataPtr object pointing to the created \c Rdata object.
     virtual RdataPtr create(const rdata::Rdata& source) const = 0;
     virtual RdataPtr create(const rdata::Rdata& source) const = 0;
+
+    /// \brief Create RDATA from MasterLexer
+    virtual RdataPtr create(MasterLexer& lexer, const Name*,
+                            MasterLoader::Options,
+                            MasterLoaderCallbacks&) const {
+        std::string s;
+
+        while (true) {
+            const MasterLexer::Token& token = lexer.getNextToken();
+            if (token.getType() == MasterLexer::Token::END_OF_FILE) {
+                break;
+            }
+
+            if (!s.empty()) {
+                s += " ";
+            }
+
+            s += token.getString();
+        }
+
+        return (create(s));
+    }
+
     //@}
     //@}
 };
 };
 
 

+ 1 - 0
src/lib/dns/tests/rrparamregistry_unittest.cc

@@ -104,6 +104,7 @@ TEST_F(RRParamRegistryTest, addError) {
 
 
 class TestRdataFactory : public AbstractRdataFactory {
 class TestRdataFactory : public AbstractRdataFactory {
 public:
 public:
+    using AbstractRdataFactory::create;
     virtual RdataPtr create(const string& rdata_str) const
     virtual RdataPtr create(const string& rdata_str) const
     { return (RdataPtr(new in::A(rdata_str))); }
     { return (RdataPtr(new in::A(rdata_str))); }
     virtual RdataPtr create(InputBuffer& buffer, size_t rdata_len) const
     virtual RdataPtr create(InputBuffer& buffer, size_t rdata_len) const