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() {
274 addType(
"IXFR", 251);
275 addType(
"AXFR", 252);
284 addType(
"MAILA", 254);
290 addType(
"NSAP-PTR", 23);
300 addType(
"IPSECKEY", 45);
302 addType(
"UNSPEC", 103);
307 addType(
"MAILB", 253);
310 addClass(
"NONE", 254);
318 RRParamRegistry::~RRParamRegistry() {
323 RRParamRegistry::getRegistry() {
330 RRParamRegistry::add(
const std::string& typecode_string, uint16_t typecode,
333 bool type_added =
false;
335 type_added = addType(typecode_string, typecode);
336 impl_->genericrdata_factories.insert(pair<RRType, RdataFactoryPtr>(
341 removeType(typecode);
348 RRParamRegistry::add(
const std::string& typecode_string, uint16_t typecode,
349 const std::string& classcode_string, uint16_t classcode,
358 bool type_added =
false;
359 bool class_added =
false;
362 type_added = addType(typecode_string, typecode);
363 class_added = addClass(classcode_string, classcode);
364 impl_->rdata_factories.insert(pair<RRTypeClass, RdataFactoryPtr>(
370 removeType(typecode);
373 removeClass(classcode);
380 RRParamRegistry::removeRdataFactory(
const RRType& rrtype,
383 RdataFactoryMap::iterator found =
384 impl_->rdata_factories.find(
RRTypeClass(rrtype, rrclass));
385 if (found != impl_->rdata_factories.end()) {
386 impl_->rdata_factories.erase(found);
394 RRParamRegistry::removeRdataFactory(
const RRType& rrtype) {
395 GenericRdataFactoryMap::iterator found =
396 impl_->genericrdata_factories.find(rrtype);
397 if (found != impl_->genericrdata_factories.end()) {
398 impl_->genericrdata_factories.erase(found);
412 bool CICharEqual(
char c1,
char c2) {
413 return (tolower(static_cast<unsigned char>(c1)) ==
414 tolower(static_cast<unsigned char>(c2)));
418 caseStringEqual(
const string& s1,
const string& s2,
size_t n) {
419 assert(s1.size() >= n && s2.size() >= n);
421 return (mismatch(s1.begin(), s1.begin() + n, s2.begin(), CICharEqual).first
435 template <
typename PT,
typename MC,
typename MS,
typename ET>
437 addParam(
const string& code_string, uint16_t code, MC& codemap, MS& stringmap)
440 typename MC::const_iterator found = codemap.find(code);
441 if (found != codemap.end()) {
442 if (found->second->code_string_ != code_string) {
443 isc_throw(ET,
"Duplicate RR parameter registration");
448 typedef boost::shared_ptr<PT> ParamPtr;
449 typedef pair<string, ParamPtr> StrParamPair;
450 typedef pair<uint16_t, ParamPtr> CodeParamPair;
451 ParamPtr param = ParamPtr(
new PT(code_string, code));
453 stringmap.insert(StrParamPair(code_string, param));
454 codemap.insert(CodeParamPair(code, param));
458 stringmap.erase(code_string);
466 template <
typename MC,
typename MS>
468 removeParam(uint16_t code, MC& codemap, MS& stringmap) {
469 typename MC::iterator found = codemap.find(code);
471 if (found != codemap.end()) {
472 size_t erased = stringmap.erase(found->second->code_string_);
476 codemap.erase(found);
484 template <
typename PT,
typename MS>
486 textToCode(
const string& code_str, MS& stringmap, uint16_t& ret_code) {
487 typename MS::const_iterator found;
489 found = stringmap.find(code_str);
490 if (found != stringmap.end()) {
491 ret_code = found->second->code_;
495 size_t l = code_str.size();
496 if (l > PT::UNKNOWN_PREFIXLEN() &&
497 l <= PT::UNKNOWN_MAXLEN() &&
498 caseStringEqual(code_str, PT::UNKNOWN_PREFIX(),
499 PT::UNKNOWN_PREFIXLEN())) {
501 istringstream iss(code_str.substr(PT::UNKNOWN_PREFIXLEN(),
502 l - PT::UNKNOWN_PREFIXLEN()));
504 if (iss.rdstate() == ios::eofbit && code <= PT::MAX_CODE) {
513 template <
typename PT,
typename MC>
515 codeToText(uint16_t code, MC& codemap) {
516 typename MC::const_iterator found;
518 found = codemap.find(code);
519 if (found != codemap.end()) {
520 return (found->second->code_string_);
525 return (PT::UNKNOWN_PREFIX() + ss.str());
530 RRParamRegistry::addType(
const string& type_string, uint16_t code) {
531 return (addParam<RRTypeParam, CodeRRTypeMap, StrRRTypeMap, RRTypeExists>
532 (type_string, code, impl_->code2typemap, impl_->str2typemap));
536 RRParamRegistry::removeType(uint16_t code) {
537 return (removeParam<CodeRRTypeMap, StrRRTypeMap>(code, impl_->code2typemap,
538 impl_->str2typemap));
542 RRParamRegistry::textToTypeCode(
const string& type_string,
543 uint16_t& type_code)
const
545 return (textToCode<RRTypeParam, StrRRTypeMap>
546 (type_string, impl_->str2typemap, type_code));
550 RRParamRegistry::codeToTypeText(uint16_t code)
const {
551 return (codeToText<RRTypeParam, CodeRRTypeMap>(code, impl_->code2typemap));
555 RRParamRegistry::addClass(
const string& class_string, uint16_t code) {
556 return (addParam<RRClassParam, CodeRRClassMap, StrRRClassMap, RRClassExists>
557 (class_string, code, impl_->code2classmap, impl_->str2classmap));
561 RRParamRegistry::removeClass(uint16_t code) {
562 return (removeParam<CodeRRClassMap, StrRRClassMap>(code,
563 impl_->code2classmap,
564 impl_->str2classmap));
568 RRParamRegistry::textToClassCode(
const string& class_string,
569 uint16_t& class_code)
const
571 return (textToCode<RRClassParam, StrRRClassMap>
572 (class_string, impl_->str2classmap, class_code));
576 RRParamRegistry::codeToClassText(uint16_t code)
const {
577 return (codeToText<RRClassParam, CodeRRClassMap>(code,
578 impl_->code2classmap));
586 RdataFactoryMap::const_iterator found;
589 return (found->second.get());
592 GenericRdataFactoryMap::const_iterator genfound =
595 return (genfound->second.get());
604 const std::string& rdata_string)
610 findRdataFactory(impl_, rrtype, rrclass);
611 if (factory != NULL) {
612 return (factory->
create(rdata_string));
623 findRdataFactory(impl_, rrtype, rrclass);
624 if (factory != NULL) {
625 return (factory->
create(buffer, rdata_len));
636 findRdataFactory(impl_, rrtype, rrclass);
637 if (factory != NULL) {
638 return (factory->
create(source));
642 dynamic_cast<const generic::Generic&>(source))));
652 findRdataFactory(impl_, rrtype, rrclass);
653 if (factory != NULL) {
654 return (factory->
create(lexer, name, options, callbacks));
The Name class encapsulates DNS names.
virtual RdataPtr create(const string &rdata_str) const
Create RDATA from a string.
StrRRTypeMap str2typemap
Mappings from RR type codes to textual representations.
virtual RdataPtr create(MasterLexer &lexer, const Name *origin, MasterLoader::Options options, MasterLoaderCallbacks &callbacks) const
Create RDATA using MasterLexer.
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.
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(InputBuffer &buffer, size_t rdata_len) const
Create RDATA from wire-format data.
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...