Commit 774ebcf9 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

supported class-indepent RRtypes explicitly


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/parkinglot@618 e5f2f494-b856-4b98-b285-d166d9295462
parent eedff945
......@@ -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)
......
......@@ -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;
......@@ -213,6 +212,24 @@ RRParamRegistry::getRegistry()
return (registry);
}
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,
......@@ -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");
}
}
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment