26#include <boost/shared_ptr.hpp>
43CICharLess(
char c1,
char c2) {
44 return (tolower(
static_cast<unsigned char>(c1)) <
45 tolower(
static_cast<unsigned char>(c2)));
49 bool operator()(
const string& s1,
const string& s2)
const {
50 return (lexicographical_compare(s1.begin(), s1.end(),
51 s2.begin(), s2.end(), CICharLess));
56 RRTypeParam(
const string& code_string, uint16_t code) :
62 static const unsigned int MAX_CODE = 0xffff;
63 static const string& UNKNOWN_PREFIX();
64 static size_t UNKNOWN_PREFIXLEN();
65 static const string& UNKNOWN_MAX();
66 static size_t UNKNOWN_MAXLEN();
69typedef boost::shared_ptr<RRTypeParam> RRTypeParamPtr;
70typedef map<string, RRTypeParamPtr, CIStringLess> StrRRTypeMap;
71typedef map<uint16_t, RRTypeParamPtr> CodeRRTypeMap;
74RRTypeParam::UNKNOWN_PREFIX() {
75 static const string p(
"TYPE");
80RRTypeParam::UNKNOWN_PREFIXLEN() {
81 static size_t plen = UNKNOWN_PREFIX().size();
86RRTypeParam::UNKNOWN_MAX() {
87 static const string p(
"TYPE65535");
92RRTypeParam::UNKNOWN_MAXLEN() {
93 static size_t plen = UNKNOWN_MAX().size();
98 RRClassParam(
const string& code_string, uint16_t code) :
104 static const unsigned int MAX_CODE = 0xffff;
105 static const string& UNKNOWN_PREFIX();
106 static size_t UNKNOWN_PREFIXLEN();
107 static const string& UNKNOWN_MAX();
108 static size_t UNKNOWN_MAXLEN();
111typedef boost::shared_ptr<RRClassParam> RRClassParamPtr;
112typedef map<string, RRClassParamPtr, CIStringLess> StrRRClassMap;
113typedef map<uint16_t, RRClassParamPtr> CodeRRClassMap;
116RRClassParam::UNKNOWN_PREFIX() {
117 static const string p(
"CLASS");
122RRClassParam::UNKNOWN_PREFIXLEN() {
123 static size_t plen = UNKNOWN_PREFIX().size();
128RRClassParam::UNKNOWN_MAX() {
129 static const string p(
"CLASS65535");
134RRClassParam::UNKNOWN_MAXLEN() {
135 static size_t plen = UNKNOWN_MAX().size();
156 return (
RdataPtr(
new T(rdata_str)));
160 return (
RdataPtr(
new T(buffer, rdata_len)));
164 return (
RdataPtr(
new T(
dynamic_cast<const T&
>(source))));
170 return (
RdataPtr(
new T(lexer, origin, options, callbacks)));
224 addClass(
"NONE", 254);
234 addType(
"HINFO", 13);
235 addType(
"MINFO", 14);
238 addType(
"AFSDB", 18);
243 addType(
"NSAP-PTR", 23);
251 addType(
"NIMLOC", 32);
254 addType(
"NAPTR", 35);
258 addType(
"DNAME", 39);
262 addType(
"SSHFP", 44);
263 addType(
"IPSECKEY", 45);
265 addType(
"DNSKEY", 48);
266 addType(
"NSEC3", 50);
267 addType(
"NSEC3PARAM", 51);
269 addType(
"SMIMEA", 53);
272 addType(
"NINFO", 56);
274 addType(
"TALINK", 58);
276 addType(
"CDNSKEY", 60);
277 addType(
"OPENPGPKEY", 61);
278 addType(
"CSYNC", 62);
279 addType(
"ZONEMD", 63);
281 addType(
"HTTPS", 65);
284 addType(
"UINFO", 100);
287 addType(
"UNSPEC", 103);
292 addType(
"EUI48", 108);
293 addType(
"EUI64", 109);
295 addType(
"IXFR", 251);
296 addType(
"AXFR", 252);
297 addType(
"MAILB", 253);
298 addType(
"MAILA", 254);
304 addType(
"AMTRELAY", 260);
305 addType(
"RESINFO", 261);
307 addType(
"TA", 32768);
308 addType(
"DLV", 32769);
314RRParamRegistry::~RRParamRegistry() {
327 bool type_added =
false;
329 type_added =
addType(typecode_string, typecode);
330 impl_->genericrdata_factories.insert(pair<RRType, RdataFactoryPtr>(
343 const std::string& classcode_string, uint16_t classcode,
351 bool type_added =
false;
352 bool class_added =
false;
355 type_added =
addType(typecode_string, typecode);
356 class_added =
addClass(classcode_string, classcode);
357 impl_->rdata_factories.insert(pair<RRTypeClass, RdataFactoryPtr>(
375 RdataFactoryMap::iterator found =
376 impl_->rdata_factories.find(
RRTypeClass(rrtype, rrclass));
377 if (found != impl_->rdata_factories.end()) {
378 impl_->rdata_factories.erase(found);
387 GenericRdataFactoryMap::iterator found =
388 impl_->genericrdata_factories.find(rrtype);
389 if (found != impl_->genericrdata_factories.end()) {
390 impl_->genericrdata_factories.erase(found);
404bool CICharEqual(
char c1,
char c2) {
405 return (tolower(
static_cast<unsigned char>(c1)) ==
406 tolower(
static_cast<unsigned char>(c2)));
410caseStringEqual(
const string& s1,
const string& s2,
size_t n) {
413 return (mismatch(s1.begin(), s1.begin() + n, s2.begin(), CICharEqual).first
427template <
typename PT,
typename MC,
typename MS,
typename ET>
429addParam(
const string& code_string, uint16_t code, MC& codemap, MS& stringmap) {
431 typename MC::const_iterator found = codemap.find(code);
432 if (found != codemap.end()) {
433 if (found->second->code_string_ != code_string) {
434 isc_throw(ET,
"Duplicate RR parameter registration");
439 typedef boost::shared_ptr<PT> ParamPtr;
440 typedef pair<string, ParamPtr> StrParamPair;
441 typedef pair<uint16_t, ParamPtr> CodeParamPair;
442 ParamPtr param = ParamPtr(
new PT(code_string, code));
444 stringmap.insert(StrParamPair(code_string, param));
445 codemap.insert(CodeParamPair(code, param));
449 stringmap.erase(code_string);
457template <
typename MC,
typename MS>
459removeParam(uint16_t code, MC& codemap, MS& stringmap) {
460 typename MC::iterator found = codemap.find(code);
462 if (found != codemap.end()) {
463 size_t erased = stringmap.erase(found->second->code_string_);
467 codemap.erase(found);
475template <
typename PT,
typename MS>
477textToCode(
const string& code_str, MS& stringmap, uint16_t& ret_code) {
478 typename MS::const_iterator found;
480 found = stringmap.find(code_str);
481 if (found != stringmap.end()) {
482 ret_code = found->second->code_;
486 size_t l = code_str.size();
487 if (l > PT::UNKNOWN_PREFIXLEN() &&
488 l <= PT::UNKNOWN_MAXLEN() &&
489 caseStringEqual(code_str, PT::UNKNOWN_PREFIX(),
490 PT::UNKNOWN_PREFIXLEN())) {
492 istringstream iss(code_str.substr(PT::UNKNOWN_PREFIXLEN(),
493 l - PT::UNKNOWN_PREFIXLEN()));
495 if (iss.rdstate() == ios::eofbit && code <= PT::MAX_CODE) {
504template <
typename PT,
typename MC>
506codeToText(uint16_t code, MC& codemap) {
507 typename MC::const_iterator found;
509 found = codemap.find(code);
510 if (found != codemap.end()) {
511 return (found->second->code_string_);
516 return (PT::UNKNOWN_PREFIX() + ss.str());
522 return (addParam<RRTypeParam, CodeRRTypeMap, StrRRTypeMap, RRTypeExists>
523 (type_string, code, impl_->code2typemap, impl_->str2typemap));
528 return (removeParam<CodeRRTypeMap, StrRRTypeMap>(code, impl_->code2typemap,
529 impl_->str2typemap));
534 uint16_t& type_code)
const {
535 return (textToCode<RRTypeParam, StrRRTypeMap>
536 (type_string, impl_->str2typemap, type_code));
541 return (codeToText<RRTypeParam, CodeRRTypeMap>(code, impl_->code2typemap));
546 return (addParam<RRClassParam, CodeRRClassMap, StrRRClassMap, RRClassExists>
547 (class_string, code, impl_->code2classmap, impl_->str2classmap));
552 return (removeParam<CodeRRClassMap, StrRRClassMap>(code,
553 impl_->code2classmap,
554 impl_->str2classmap));
559 uint16_t& class_code)
const {
560 return (textToCode<RRClassParam, StrRRClassMap>
561 (class_string, impl_->str2classmap, class_code));
566 return (codeToText<RRClassParam, CodeRRClassMap>(code,
567 impl_->code2classmap));
574 RdataFactoryMap::const_iterator found;
577 return (found->second.get());
580 GenericRdataFactoryMap::const_iterator genfound =
583 return (genfound->second.get());
592 const std::string& rdata_string) {
597 findRdataFactory(impl_.get(), rrtype, rrclass);
599 return (factory->
create(rdata_string));
609 findRdataFactory(impl_.get(), rrtype, rrclass);
611 return (factory->
create(buffer, rdata_len));
619 const Rdata& source) {
621 findRdataFactory(impl_.get(), rrtype, rrclass);
623 return (factory->
create(source));
636 findRdataFactory(impl_.get(), rrtype, rrclass);
638 return (factory->
create(lexer, name, options, callbacks));
Tokenizer for parsing DNS master files.
Set of issue callbacks for a loader.
Options
Options how the parsing should work.
The Name class encapsulates DNS names.
The RRClass class encapsulates DNS resource record classes.
The RRParamRegistry class represents a registry of parameters to manipulate DNS resource records (RRs...
rdata::RdataPtr createRdata(const RRType &rrtype, const RRClass &rrclass, const std::string &rdata_string)
Create RDATA of a given pair of RR type and class from a string.
bool removeType(uint16_t type_code)
Remove mappings between RR type code and textual representation for a given type.
bool textToTypeCode(const std::string &type_string, uint16_t &type_code) const
Convert a textual representation of an RR type to the corresponding 16-bit integer code.
bool textToClassCode(const std::string &class_string, uint16_t &class_code) const
Convert a textual representation of an RR class to the corresponding 16-bit integer code.
std::string codeToClassText(uint16_t class_code) const
Convert class code into its textual representation.
std::string codeToTypeText(uint16_t type_code) const
Convert type code into its textual representation.
bool addClass(const std::string &class_string, uint16_t class_code)
Add mappings between RR class code and textual representation.
static RRParamRegistry & getRegistry()
Return the singleton instance of RRParamRegistry.
bool addType(const std::string &type_string, uint16_t type_code)
Add mappings between RR type code and textual representation.
bool removeRdataFactory(const RRType &rrtype, const RRClass &rrclass)
Remove registered RDATA factory for the given pair of RRType and RRClass.
void add(const std::string &type_string, uint16_t type_code, const std::string &class_string, uint16_t class_code, rdata::RdataFactoryPtr rdata_factory)
Add a set of parameters for a pair of RR type and class.
bool removeClass(uint16_t class_code)
Remove mappings between RR class code and textual representation for a given class.
The RRType class encapsulates DNS resource record types.
virtual RdataPtr create(const string &rdata_str) const
Create RDATA from a string.
virtual RdataPtr create(InputBuffer &buffer, size_t rdata_len) const
Create RDATA from wire-format data.
virtual RdataPtr create(MasterLexer &lexer, const Name *origin, MasterLoader::Options options, MasterLoaderCallbacks &callbacks) const
Create RDATA using MasterLexer.
virtual RdataPtr create(const Rdata &source) const
Create RDATA from another Rdata object of the same type.
The AbstractRdataFactory class is an abstract base class to encapsulate a set of Rdata factory method...
virtual RdataPtr create(const std::string &rdata_str) const =0
Create RDATA from a string.
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
The generic::Generic class represents generic "unknown" RDATA.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
boost::shared_ptr< AbstractRdataFactory > RdataFactoryPtr
The RdataFactoryPtr type is a pointer-like type, pointing to an object of some concrete derived class...
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...
pair< RRType, RRClass > RRTypeClass
Note: the element ordering in the type/class pair is intentional.
map< RRTypeClass, RdataFactoryPtr > RdataFactoryMap
map< RRType, RdataFactoryPtr > GenericRdataFactoryMap
Defines the logger used by the top-level component of kea-lfc.
The RRParamRegistryImpl class is the actual implementation of RRParamRegistry.
CodeRRTypeMap code2typemap
Mappings from textual representations of RR types to integer codes.
StrRRClassMap str2classmap
Mappings from RR class codes to textual representations.
RdataFactoryMap rdata_factories
CodeRRClassMap code2classmap
Mappings from textual representations of RR classes to integer codes.
GenericRdataFactoryMap genericrdata_factories
StrRRTypeMap str2typemap
Mappings from RR type codes to textual representations.