27#include <boost/shared_ptr.hpp>
52CICharLess(
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();
81typedef boost::shared_ptr<RRTypeParam> RRTypeParamPtr;
82typedef map<string, RRTypeParamPtr, CIStringLess> StrRRTypeMap;
83typedef map<uint16_t, RRTypeParamPtr> CodeRRTypeMap;
86RRTypeParam::UNKNOWN_PREFIX() {
87 static const string p(
"TYPE");
92RRTypeParam::UNKNOWN_PREFIXLEN() {
93 static size_t plen = UNKNOWN_PREFIX().size();
98RRTypeParam::UNKNOWN_MAX() {
99 static const string p(
"TYPE65535");
104RRTypeParam::UNKNOWN_MAXLEN() {
105 static size_t plen = UNKNOWN_MAX().size();
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();
123typedef boost::shared_ptr<RRClassParam> RRClassParamPtr;
124typedef map<string, RRClassParamPtr, CIStringLess> StrRRClassMap;
125typedef map<uint16_t, RRClassParamPtr> CodeRRClassMap;
128RRClassParam::UNKNOWN_PREFIX() {
129 static const string p(
"CLASS");
134RRClassParam::UNKNOWN_PREFIXLEN() {
135 static size_t plen = UNKNOWN_PREFIX().size();
140RRClassParam::UNKNOWN_MAX() {
141 static const string p(
"CLASS65535");
146RRClassParam::UNKNOWN_MAXLEN() {
147 static size_t plen = UNKNOWN_MAX().size();
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)));
210RRParamRegistry::RRParamRegistry() {
317RRParamRegistry::~RRParamRegistry() {
332 bool type_added =
false;
334 type_added =
addType(typecode_string, 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);
382 RdataFactoryMap::iterator found =
394 GenericRdataFactoryMap::iterator found =
411bool CICharEqual(
char c1,
char c2) {
412 return (tolower(
static_cast<unsigned char>(c1)) ==
413 tolower(
static_cast<unsigned char>(c2)));
417caseStringEqual(
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
434template <
typename PT,
typename MC,
typename MS,
typename ET>
436addParam(
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);
465template <
typename MC,
typename MS>
467removeParam(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);
483template <
typename PT,
typename MS>
485textToCode(
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) {
512template <
typename PT,
typename MC>
514codeToText(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());
530 return (addParam<RRTypeParam, CodeRRTypeMap, StrRRTypeMap, RRTypeExists>
536 return (removeParam<CodeRRTypeMap, StrRRTypeMap>(code, impl_->
code2typemap,
542 uint16_t& type_code)
const
544 return (textToCode<RRTypeParam, StrRRTypeMap>
550 return (codeToText<RRTypeParam, CodeRRTypeMap>(code, impl_->
code2typemap));
555 return (addParam<RRClassParam, CodeRRClassMap, StrRRClassMap, RRClassExists>
561 return (removeParam<CodeRRClassMap, StrRRClassMap>(code,
568 uint16_t& class_code)
const
570 return (textToCode<RRClassParam, StrRRClassMap>
576 return (codeToText<RRClassParam, CodeRRClassMap>(code,
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));
651 findRdataFactory(impl_, rrtype, rrclass);
652 if (factory != NULL) {
653 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.
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-dhcp-ddns.
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.