29#include <boost/shared_ptr.hpp>
54CICharLess(
char c1,
char c2) {
55 return (tolower(
static_cast<unsigned char>(c1)) <
56 tolower(
static_cast<unsigned char>(c2)));
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() {
318RRParamRegistry::~RRParamRegistry() {
333 bool type_added =
false;
335 type_added =
addType(typecode_string, 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);
383 RdataFactoryMap::iterator found =
395 GenericRdataFactoryMap::iterator found =
412bool CICharEqual(
char c1,
char c2) {
413 return (tolower(
static_cast<unsigned char>(c1)) ==
414 tolower(
static_cast<unsigned char>(c2)));
418caseStringEqual(
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
435template <
typename PT,
typename MC,
typename MS,
typename ET>
437addParam(
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);
466template <
typename MC,
typename MS>
468removeParam(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);
484template <
typename PT,
typename MS>
486textToCode(
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) {
513template <
typename PT,
typename MC>
515codeToText(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());
531 return (addParam<RRTypeParam, CodeRRTypeMap, StrRRTypeMap, RRTypeExists>
537 return (removeParam<CodeRRTypeMap, StrRRTypeMap>(code, impl_->
code2typemap,
543 uint16_t& type_code)
const
545 return (textToCode<RRTypeParam, StrRRTypeMap>
551 return (codeToText<RRTypeParam, CodeRRTypeMap>(code, impl_->
code2typemap));
556 return (addParam<RRClassParam, CodeRRClassMap, StrRRClassMap, RRClassExists>
562 return (removeParam<CodeRRClassMap, StrRRClassMap>(code,
569 uint16_t& class_code)
const
571 return (textToCode<RRClassParam, StrRRClassMap>
577 return (codeToText<RRClassParam, CodeRRClassMap>(code,
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));
652 findRdataFactory(impl_, rrtype, rrclass);
653 if (factory != NULL) {
654 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-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.