Kea 2.7.5
rdata.h
Go to the documentation of this file.
1// Copyright (C) 2010-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef RDATA_H
8#define RDATA_H
9
10#include <dns/master_lexer.h>
11#include <dns/master_loader.h>
13#include <dns/exceptions.h>
14#include <util/buffer.h>
15
16#include <boost/shared_ptr.hpp>
17
18#include <memory>
19#include <stdint.h>
20
21namespace isc {
22namespace dns {
23class AbstractMessageRenderer;
24class RRType;
25class RRClass;
26class Name;
27
28namespace rdata {
29
35public:
36 InvalidRdataLength(const char* file, size_t line, const char* what) :
37 DNSTextError(file, line, what) {}
38};
39
45public:
46 InvalidRdataText(const char* file, size_t line, const char* what) :
47 DNSTextError(file, line, what) {}
48};
49
56public:
57 CharStringTooLong(const char* file, size_t line, const char* what) :
58 DNSTextError(file, line, what) {}
59};
60
61// Forward declaration to define RdataPtr.
62class Rdata;
63
68typedef boost::shared_ptr<Rdata> RdataPtr;
69typedef boost::shared_ptr<const Rdata> ConstRdataPtr;
70
73const size_t MAX_RDLENGTH = 65535;
74
77const unsigned int MAX_CHARSTRING_LEN = 255;
78
120class Rdata {
127
128protected:
136 Rdata() {}
137private:
138 Rdata(const Rdata& source);
139 void operator=(const Rdata& source);
140public:
142 virtual ~Rdata() {};
144
148
149
158 virtual std::string toText() const = 0;
159
167 virtual void toWire(isc::util::OutputBuffer& buff) const = 0;
168
178 virtual void toWire(AbstractMessageRenderer& renderer) const = 0;
180
184
185
211 virtual int compare(const Rdata& other) const = 0;
213
227 virtual uint16_t getLength() const;
228};
229
230namespace generic {
231
239struct GenericImpl;
240
246class Generic : public Rdata {
247public:
251
252
265 explicit Generic(const std::string& rdata_string);
266
288 Generic(isc::util::InputBuffer& buff, size_t rdata_len);
289
292 Generic(MasterLexer& lexer, const Name* name,
293 MasterLoader::Options options, MasterLoaderCallbacks& callbacks);
294
297 virtual ~Generic();
305 Generic(const Generic& source);
306
314 Generic& operator=(const Generic& source);
316
320
321
330 virtual std::string toText() const;
331
341 virtual void toWire(isc::util::OutputBuffer& buff) const;
342
353 virtual void toWire(AbstractMessageRenderer& renderer) const;
355
359
360
381 virtual int compare(const Rdata& other) const;
383
384private:
385 std::unique_ptr<GenericImpl> constructFromLexer(MasterLexer& lexer);
386
387 std::unique_ptr<GenericImpl> impl_;
388};
389
404std::ostream& operator<<(std::ostream& os, const Generic& rdata);
405} // end of namespace "generic"
406
407//
408// Non class-member functions related to Rdata
409//
410
438
439
449RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
450 const std::string& rdata_string);
451
473RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
474 isc::util::InputBuffer& buff, size_t len);
475
489RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
490 const Rdata& source);
491
533RdataPtr createRdata(const RRType& rrtype, const RRClass& rrclass,
534 MasterLexer& lexer, const Name* origin,
535 MasterLoader::Options options,
536 MasterLoaderCallbacks& callbacks);
537
539
570int compareNames(const Name& n1, const Name& n2);
571
572} // end of namespace "rdata"
573}
574}
575#endif // RDATA_H
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
Base class for all sorts of text parse errors.
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.
Definition name.h:219
The RRClass class encapsulates DNS resource record classes.
Definition rrclass.h:89
The RRType class encapsulates DNS resource record types.
Definition rrtype.h:96
A standard DNS module exception that is thrown if RDATA parser encounters a character-string (as defi...
Definition rdata.h:55
CharStringTooLong(const char *file, size_t line, const char *what)
Definition rdata.h:57
A standard DNS module exception that is thrown if RDATA parser encounters an invalid or inconsistent ...
Definition rdata.h:34
InvalidRdataLength(const char *file, size_t line, const char *what)
Definition rdata.h:36
A standard DNS module exception that is thrown if RDATA parser fails to recognize a given textual rep...
Definition rdata.h:44
InvalidRdataText(const char *file, size_t line, const char *what)
Definition rdata.h:46
The Rdata class is an abstract base class that provides a set of common interfaces to manipulate conc...
Definition rdata.h:120
virtual std::string toText() const =0
Convert an Rdata to a string.
virtual ~Rdata()
The destructor.
Definition rdata.h:142
Rdata()
The default constructor.
Definition rdata.h:136
virtual int compare(const Rdata &other) const =0
Compare two instances of Rdata.
virtual void toWire(AbstractMessageRenderer &renderer) const =0
Render the Rdata in the wire format into a MessageRenderer object.
virtual uint16_t getLength() const
Get the wire format length of an Rdata.
Definition rdata.cc:43
virtual void toWire(isc::util::OutputBuffer &buff) const =0
Render the Rdata in the wire format into a buffer.
The generic::Generic class represents generic "unknown" RDATA.
Definition rdata.h:246
virtual ~Generic()
The destructor.
Definition rdata.cc:297
Generic & operator=(const Generic &source)
The assignment operator.
Definition rdata.cc:308
Generic(const std::string &rdata_string)
Constructor from a string.
Definition rdata.cc:273
virtual std::string toText() const
Convert an generic::Generic object to a string.
Definition rdata.cc:332
virtual void toWire(isc::util::OutputBuffer &buff) const
Render the generic::Generic in the wire format into a buffer.
Definition rdata.cc:344
virtual int compare(const Rdata &other) const
Compare two instances of generic::Generic objects.
Definition rdata.cc:374
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition buffer.h:81
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition buffer.h:343
std::ostream & operator<<(std::ostream &os, const Generic &rdata)
Insert the name as a string into stream.
Definition rdata.cc:381
int compareNames(const Name &n1, const Name &n2)
Gives relative ordering of two names in terms of DNSSEC RDATA ordering.
Definition rdata.cc:174
boost::shared_ptr< const Rdata > ConstRdataPtr
Definition rdata.h:69
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.
Definition rdata.cc:54
const size_t MAX_RDLENGTH
Possible maximum length of RDATA, which is the maximum unsigned 16 bit value.
Definition rdata.h:73
const unsigned int MAX_CHARSTRING_LEN
The maximum allowable length of character-string containing in RDATA as defined in RFC1035,...
Definition rdata.h:77
boost::shared_ptr< Rdata > RdataPtr
The RdataPtr type is a pointer-like type, pointing to an object of some concrete derived class of Rda...
Defines the logger used by the top-level component of kea-lfc.