27 #include <boost/shared_ptr.hpp> 52 CICharLess(
char c1,
char c2) {
53 return (tolower(static_cast<unsigned char>(c1)) <
54 tolower(static_cast<unsigned char>(c2)));
58 public binary_function<string, string, bool>
60 bool operator()(
const string& s1,
const string& s2)
const 62 return (lexicographical_compare(s1.begin(), s1.end(),
63 s2.begin(), s2.end(), CICharLess));
68 RRTypeParam(
const string& code_string, uint16_t code) :
74 static const unsigned int MAX_CODE = 0xffff;
75 static const string& UNKNOWN_PREFIX();
76 static size_t UNKNOWN_PREFIXLEN();
77 static const string& UNKNOWN_MAX();
78 static size_t UNKNOWN_MAXLEN();
81 typedef boost::shared_ptr<RRTypeParam> RRTypeParamPtr;
82 typedef map<string, RRTypeParamPtr, CIStringLess> StrRRTypeMap;
83 typedef map<uint16_t, RRTypeParamPtr> CodeRRTypeMap;
86 RRTypeParam::UNKNOWN_PREFIX() {
87 static const string p(
"TYPE");
92 RRTypeParam::UNKNOWN_PREFIXLEN() {
93 static size_t plen = UNKNOWN_PREFIX().size();
98 RRTypeParam::UNKNOWN_MAX() {
99 static const string p(
"TYPE65535");
104 RRTypeParam::UNKNOWN_MAXLEN() {
105 static size_t plen = UNKNOWN_MAX().size();
109 struct RRClassParam {
110 RRClassParam(
const string& code_string, uint16_t code) :
116 static const unsigned int MAX_CODE = 0xffff;
117 static const string& UNKNOWN_PREFIX();
118 static size_t UNKNOWN_PREFIXLEN();
119 static const string& UNKNOWN_MAX();
120 static size_t UNKNOWN_MAXLEN();
123 typedef boost::shared_ptr<RRClassParam> RRClassParamPtr;
124 typedef map<string, RRClassParamPtr, CIStringLess> StrRRClassMap;
125 typedef map<uint16_t, RRClassParamPtr> CodeRRClassMap;
128 RRClassParam::UNKNOWN_PREFIX() {
129 static const string p(
"CLASS");
134 RRClassParam::UNKNOWN_PREFIXLEN() {
135 static size_t plen = UNKNOWN_PREFIX().size();
140 RRClassParam::UNKNOWN_MAX() {
141 static const string p(
"CLASS65535");
146 RRClassParam::UNKNOWN_MAXLEN() {
147 static size_t plen = UNKNOWN_MAX().size();
164 template <
typename T>
169 return (
RdataPtr(
new T(rdata_str)));
174 return (
RdataPtr(
new T(buffer, rdata_len)));
179 return (
RdataPtr(
new T(dynamic_cast<const T&>(source))));
186 return (
RdataPtr(
new T(lexer, origin, options, callbacks)));
210 RRParamRegistry::RRParamRegistry() {
272 addType(
"IPSECKEY", 45);
278 addType(
"UNSPEC", 103);
279 addType(
"MAILA", 254);
280 addType(
"MAILB", 253);
286 addType(
"TKEY", 249);
289 addType(
"IXFR", 251);
292 addType(
"AXFR", 252);
302 addType(
"NSAP-PTR", 23);
309 addClass(
"NONE", 254);
317 RRParamRegistry::~RRParamRegistry() {
322 RRParamRegistry::getRegistry() {
329 RRParamRegistry::add(
const std::string& typecode_string, uint16_t typecode,
332 bool type_added =
false;
334 type_added = addType(typecode_string, typecode);
335 impl_->genericrdata_factories.insert(pair<RRType, RdataFactoryPtr>(
340 removeType(typecode);
347 RRParamRegistry::add(
const std::string& typecode_string, uint16_t typecode,
348 const std::string& classcode_string, uint16_t classcode,
357 bool type_added =
false;
358 bool class_added =
false;
361 type_added = addType(typecode_string, typecode);
362 class_added = addClass(classcode_string, classcode);
363 impl_->rdata_factories.insert(pair<RRTypeClass, RdataFactoryPtr>(
369 removeType(typecode);
372 removeClass(classcode);
379 RRParamRegistry::removeRdataFactory(
const RRType& rrtype,
382 RdataFactoryMap::iterator found =
383 impl_->rdata_factories.find(
RRTypeClass(rrtype, rrclass));
384 if (found != impl_->rdata_factories.end()) {
385 impl_->rdata_factories.erase(found);
393 RRParamRegistry::removeRdataFactory(
const RRType& rrtype) {
394 GenericRdataFactoryMap::iterator found =
395 impl_->genericrdata_factories.find(rrtype);
396 if (found != impl_->genericrdata_factories.end()) {
397 impl_->genericrdata_factories.erase(found);
411 bool CICharEqual(
char c1,
char c2) {
412 return (tolower(static_cast<unsigned char>(c1)) ==
413 tolower(static_cast<unsigned char>(c2)));
417 caseStringEqual(
const string& s1,
const string& s2,
size_t n) {
418 assert(s1.size() >= n && s2.size() >= n);
420 return (mismatch(s1.begin(), s1.begin() + n, s2.begin(), CICharEqual).first
434 template <
typename PT,
typename MC,
typename MS,
typename ET>
436 addParam(
const string& code_string, uint16_t code, MC& codemap, MS& stringmap)
439 typename MC::const_iterator found = codemap.find(code);
440 if (found != codemap.end()) {
441 if (found->second->code_string_ != code_string) {
442 isc_throw(ET,
"Duplicate RR parameter registration");
447 typedef boost::shared_ptr<PT> ParamPtr;
448 typedef pair<string, ParamPtr> StrParamPair;
449 typedef pair<uint16_t, ParamPtr> CodeParamPair;
450 ParamPtr param = ParamPtr(
new PT(code_string, code));
452 stringmap.insert(StrParamPair(code_string, param));
453 codemap.insert(CodeParamPair(code, param));
457 stringmap.erase(code_string);
465 template <
typename MC,
typename MS>
467 removeParam(uint16_t code, MC& codemap, MS& stringmap) {
468 typename MC::iterator found = codemap.find(code);
470 if (found != codemap.end()) {
471 size_t erased = stringmap.erase(found->second->code_string_);
475 codemap.erase(found);
483 template <
typename PT,
typename MS>
485 textToCode(
const string& code_str, MS& stringmap, uint16_t& ret_code) {
486 typename MS::const_iterator found;
488 found = stringmap.find(code_str);
489 if (found != stringmap.end()) {
490 ret_code = found->second->code_;
494 size_t l = code_str.size();
495 if (l > PT::UNKNOWN_PREFIXLEN() &&
496 l <= PT::UNKNOWN_MAXLEN() &&
497 caseStringEqual(code_str, PT::UNKNOWN_PREFIX(),
498 PT::UNKNOWN_PREFIXLEN())) {
500 istringstream iss(code_str.substr(PT::UNKNOWN_PREFIXLEN(),
501 l - PT::UNKNOWN_PREFIXLEN()));
503 if (iss.rdstate() == ios::eofbit && code <= PT::MAX_CODE) {
512 template <
typename PT,
typename MC>
514 codeToText(uint16_t code, MC& codemap) {
515 typename MC::const_iterator found;
517 found = codemap.find(code);
518 if (found != codemap.end()) {
519 return (found->second->code_string_);
524 return (PT::UNKNOWN_PREFIX() + ss.str());
529 RRParamRegistry::addType(
const string& type_string, uint16_t code) {
530 return (addParam<RRTypeParam, CodeRRTypeMap, StrRRTypeMap, RRTypeExists>
531 (type_string, code, impl_->code2typemap, impl_->str2typemap));
535 RRParamRegistry::removeType(uint16_t code) {
536 return (removeParam<CodeRRTypeMap, StrRRTypeMap>(code, impl_->code2typemap,
537 impl_->str2typemap));
541 RRParamRegistry::textToTypeCode(
const string& type_string,
542 uint16_t& type_code)
const 544 return (textToCode<RRTypeParam, StrRRTypeMap>
545 (type_string, impl_->str2typemap, type_code));
549 RRParamRegistry::codeToTypeText(uint16_t code)
const {
550 return (codeToText<RRTypeParam, CodeRRTypeMap>(code, impl_->code2typemap));
554 RRParamRegistry::addClass(
const string& class_string, uint16_t code) {
555 return (addParam<RRClassParam, CodeRRClassMap, StrRRClassMap, RRClassExists>
556 (class_string, code, impl_->code2classmap, impl_->str2classmap));
560 RRParamRegistry::removeClass(uint16_t code) {
561 return (removeParam<CodeRRClassMap, StrRRClassMap>(code,
562 impl_->code2classmap,
563 impl_->str2classmap));
567 RRParamRegistry::textToClassCode(
const string& class_string,
568 uint16_t& class_code)
const 570 return (textToCode<RRClassParam, StrRRClassMap>
571 (class_string, impl_->str2classmap, class_code));
575 RRParamRegistry::codeToClassText(uint16_t code)
const {
576 return (codeToText<RRClassParam, CodeRRClassMap>(code,
577 impl_->code2classmap));
585 RdataFactoryMap::const_iterator found;
588 return (found->second.get());
591 GenericRdataFactoryMap::const_iterator genfound =
594 return (genfound->second.get());
603 const std::string& rdata_string)
609 findRdataFactory(impl_, rrtype, rrclass);
610 if (factory != NULL) {
611 return (factory->
create(rdata_string));
622 findRdataFactory(impl_, rrtype, rrclass);
623 if (factory != NULL) {
624 return (factory->
create(buffer, rdata_len));
635 findRdataFactory(impl_, rrtype, rrclass);
636 if (factory != NULL) {
637 return (factory->
create(source));
641 dynamic_cast<const generic::Generic&>(source))));
651 findRdataFactory(impl_, rrtype, rrclass);
652 if (factory != NULL) {
653 return (factory->
create(lexer, name, options, callbacks));
The Name class encapsulates DNS names.
StrRRTypeMap str2typemap
Mappings from RR type codes to textual representations.
virtual RdataPtr create(InputBuffer &buffer, size_t rdata_len) const
Create RDATA from wire-format data.
The RRParamRegistryImpl class is the actual implementation of RRParamRegistry.
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
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.
The generic::Generic class represents generic "unknown" RDATA.
The RRClass class encapsulates DNS resource record classes.
Options
Options how the parsing should work.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
The AbstractRdataFactory class is an abstract base class to encapsulate a set of Rdata factory method...
GenericRdataFactoryMap genericrdata_factories
The RRParamRegistry class represents a registry of parameters to manipulate DNS resource records (RRs...
boost::shared_ptr< AbstractRdataFactory > RdataFactoryPtr
The RdataFactoryPtr type is a pointer-like type, pointing to an object of some concrete derived class...
Defines the logger used by the top-level component of kea-dhcp-ddns.
pair< RRType, RRClass > RRTypeClass
Note: the element ordering in the type/class pair is intentional.
virtual RdataPtr create(const Rdata &source) const
Create RDATA from another Rdata object of the same type.
virtual RdataPtr create(MasterLexer &lexer, const Name *origin, MasterLoader::Options options, MasterLoaderCallbacks &callbacks) const
Create RDATA using MasterLexer.
The RRType class encapsulates DNS resource record types.
map< RRType, RdataFactoryPtr > GenericRdataFactoryMap
CodeRRClassMap code2classmap
Mappings from textual representations of RR classes to integer codes.
StrRRClassMap str2classmap
Mappings from RR class codes to textual representations.
virtual RdataPtr create(const string &rdata_str) const
Create RDATA from a string.
virtual RdataPtr create(const std::string &rdata_str) const =0
Create RDATA from a string.
map< RRTypeClass, RdataFactoryPtr > RdataFactoryMap
CodeRRTypeMap code2typemap
Mappings from textual representations of RR types to integer codes.
RdataFactoryMap rdata_factories
Tokenizer for parsing DNS master files.
Set of issue callbacks for a loader.
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...