Parcourir la source

supported class-indepent RRtypes explicitly

git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@618 e5f2f494-b856-4b98-b285-d166d9295462
JINMEI Tatuya il y a 15 ans
Parent
commit
774ebcf90e

+ 2 - 0
src/lib/dns/cpp/rdata_unittest.cc

@@ -243,6 +243,8 @@ TEST_F(RdataTest, createFromText_NS)
     EXPECT_EQ(0, rdata_ns.compare(generic::NS("ns.example.com.")));
     // should be case sensitive.
     EXPECT_EQ(0, rdata_ns.compare(generic::NS("NS.EXAMPLE.COM")));
+    EXPECT_EQ(0, rdata_ns.compare(*createRdata(RRType("NS"), RRClass(65000),
+                                               "ns.example.com")));
 }
 
 TEST_F(RdataTest, createFromWire_NS)

+ 42 - 7
src/lib/dns/cpp/rrparamregistry.cc

@@ -124,6 +124,7 @@ const size_t RRClassParam::UNKNOWN_MAXLEN =
 /// cases.
 typedef pair<RRType, RRClass> RRTypeClass;
 typedef map<RRTypeClass, RdataFactoryPtr> RdataFactoryMap;
+typedef map<RRType, RdataFactoryPtr> GenericRdataFactoryMap;
 
 template <typename T>
 class RdataFactory : public AbstractRdataFactory {
@@ -161,6 +162,7 @@ struct RRParamRegistryImpl {
     /// Mappings from textual representations of RR classes to integer codes.
     CodeRRClassMap code2classmap;
     RdataFactoryMap rdata_factories;
+    GenericRdataFactoryMap genericrdata_factories;
 };
 
 RRParamRegistry::RRParamRegistry()
@@ -181,19 +183,16 @@ RRParamRegistry::RRParamRegistry()
         // each class repeatedly?  Or should we have a special mapping category
         // of "generic" as a last resort?
         add("NS", 2, "IN", 1, RdataFactoryPtr(new RdataFactory<generic::NS>()));
-        add("NS", 2, "CH", 3, RdataFactoryPtr(new RdataFactory<generic::NS>()));
+        add("NS", 2, RdataFactoryPtr(new RdataFactory<generic::NS>()));
         add("SOA", 6, "IN", 1,
             RdataFactoryPtr(new RdataFactory<generic::SOA>()));
-        add("SOA", 6, "CH", 3,
-            RdataFactoryPtr(new RdataFactory<generic::SOA>()));
+        add("SOA", 6, RdataFactoryPtr(new RdataFactory<generic::SOA>()));
         add("MX", 15, "IN", 1,
             RdataFactoryPtr(new RdataFactory<generic::MX>()));
-        add("MX", 15, "CH", 3,
-            RdataFactoryPtr(new RdataFactory<generic::MX>()));
+        add("MX", 15, RdataFactoryPtr(new RdataFactory<generic::MX>()));
         add("TXT", 16, "IN", 1,
             RdataFactoryPtr(new RdataFactory<generic::TXT>()));
-        add("TXT", 16, "CH", 3,
-            RdataFactoryPtr(new RdataFactory<generic::TXT>()));
+        add("TXT", 16, RdataFactoryPtr(new RdataFactory<generic::TXT>()));
     } catch (...) {
         delete impl_;
         throw;
@@ -215,6 +214,24 @@ RRParamRegistry::getRegistry()
 
 void
 RRParamRegistry::add(const string& typecode_string, uint16_t typecode,
+                     RdataFactoryPtr rdata_factory)
+{
+    bool type_added = false;
+    try {
+        type_added = addType(typecode_string, typecode);
+        impl_->genericrdata_factories.insert(pair<RRType, RdataFactoryPtr>(
+                                                 RRType(typecode),
+                                                 rdata_factory));
+    } catch (...) {
+        if (type_added) {
+            removeType(typecode);
+        }
+        throw;
+    }
+}
+
+void
+RRParamRegistry::add(const string& typecode_string, uint16_t typecode,
                      const string& classcode_string, uint16_t classcode,
                      RdataFactoryPtr rdata_factory)
 {
@@ -439,6 +456,12 @@ RRParamRegistry::createRdata(const RRType& rrtype, const RRClass& rrclass,
         return (found->second->create(rdata_string));
     }
 
+    GenericRdataFactoryMap::const_iterator genfound =
+        impl_->genericrdata_factories.find(rrtype);
+    if (genfound != impl_->genericrdata_factories.end()) {
+        return (genfound->second->create(rdata_string));
+    }
+
     dns_throw(InvalidRdataText, "Unrecognized Rdata type to create from text");
 }
 
@@ -452,6 +475,12 @@ RRParamRegistry::createRdata(const RRType& rrtype, const RRClass& rrclass,
         return (found->second->create(buffer, rdata_len));
     }
 
+    GenericRdataFactoryMap::const_iterator genfound =
+        impl_->genericrdata_factories.find(rrtype);
+    if (genfound != impl_->genericrdata_factories.end()) {
+        return (genfound->second->create(buffer, rdata_len));
+    }
+
     // construct an "unknown" type of RDATA
     return (RdataPtr(new generic::Generic(buffer, rdata_len)));
 }
@@ -466,6 +495,12 @@ RRParamRegistry::createRdata(const RRType& rrtype, const RRClass& rrclass,
         return (found->second->create(source));
     }
 
+    GenericRdataFactoryMap::const_iterator genfound =
+        impl_->genericrdata_factories.find(rrtype);
+    if (genfound != impl_->genericrdata_factories.end()) {
+        return (genfound->second->create(source));
+    }
+
     dns_throw(InvalidRdataText, "TBD");
 }
 }

+ 4 - 0
src/lib/dns/cpp/rrparamregistry.h

@@ -179,6 +179,10 @@ public:
              const std::string& class_string, uint16_t class_code,
              rdata::RdataFactoryPtr rdata_factory);
 
+    /// TBD
+    void add(const std::string& type_string, uint16_t type_code,
+             rdata::RdataFactoryPtr rdata_factory);
+
     /// \brief Add mappings between RR type code and textual representation.
     ///
     /// This method adds a mapping from the type code of an RR to its textual