Kea  1.9.9-git
rrclass.h
Go to the documentation of this file.
1 
8 // Copyright (C) 2010-2017 Internet Systems Consortium, Inc. ("ISC")
9 //
10 // This Source Code Form is subject to the terms of the Mozilla Public
11 // License, v. 2.0. If a copy of the MPL was not distributed with this
12 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 
14 #ifndef RRCLASS_H
15 #define RRCLASS_H 1
16 
17 #include <stdint.h>
18 
19 #include <string>
20 #include <ostream>
21 
22 #include <dns/exceptions.h>
23 
24 #include <boost/optional.hpp>
25 
26 // Undefine the macro IN which is defined in some operating systems
27 // but conflicts the IN RR class.
28 
29 #ifdef IN
30 #undef IN
31 #endif
32 
33 namespace isc {
34 namespace util {
35 class InputBuffer;
36 class OutputBuffer;
37 }
38 
39 namespace dns {
40 
41 // forward declarations
42 class AbstractMessageRenderer;
43 
48 class InvalidRRClass : public DNSTextError {
49 public:
50  InvalidRRClass(const char* file, size_t line, const char* what) :
51  DNSTextError(file, line, what) {}
52 };
53 
59 public:
60  IncompleteRRClass(const char* file, size_t line, const char* what) :
61  isc::dns::Exception(file, line, what) {}
62 };
63 
98 class RRClass {
99 public:
103 
104  explicit RRClass(uint16_t classcode) : classcode_(classcode) {}
135  explicit RRClass(const std::string& class_str);
146  explicit RRClass(isc::util::InputBuffer& buffer);
147 
180  static RRClass* createFromText(const std::string& class_str);
181 
184 
185 
191 
192  const std::string toText() const;
216  void toWire(AbstractMessageRenderer& renderer) const;
226  void toWire(isc::util::OutputBuffer& buffer) const;
228 
232 
233  uint16_t getCode() const { return (classcode_); }
240 
244 
245  bool equals(const RRClass& other) const
254  { return (classcode_ == other.classcode_); }
256  bool operator==(const RRClass& other) const { return (equals(other)); }
257 
264  bool nequals(const RRClass& other) const
265  { return (classcode_ != other.classcode_); }
267  bool operator!=(const RRClass& other) const { return (nequals(other)); }
268 
284  bool operator<(const RRClass& other) const
285  { return (classcode_ < other.classcode_); }
286 
287  // BEGIN_WELL_KNOWN_CLASS_DECLARATIONS
288  static const RRClass& ANY();
289  static const RRClass& CH();
290  static const RRClass& HS();
291  static const RRClass& IN();
292  static const RRClass& NONE();
293  // END_WELL_KNOWN_CLASS_DECLARATIONS
294 
295 private:
296  uint16_t classcode_;
297 };
298 
299 // BEGIN_WELL_KNOWN_CLASS_DEFINITIONS
300 inline const RRClass&
302  static RRClass rrclass(255);
303  return (rrclass);
304 }
305 
306 inline const RRClass&
308  static RRClass rrclass(3);
309  return (rrclass);
310 }
311 
312 inline const RRClass&
314  static RRClass rrclass(4);
315  return (rrclass);
316 }
317 
318 inline const RRClass&
320  static RRClass rrclass(1);
321  return (rrclass);
322 }
323 
324 inline const RRClass&
326  static RRClass rrclass(254);
327  return (rrclass);
328 }
329 
330 // END_WELL_KNOWN_CLASS_DEFINITIONS
331 
346 std::ostream&
347 operator<<(std::ostream& os, const RRClass& rrclass);
348 }
349 }
350 #endif // RRCLASS_H
351 
352 // Local Variables:
353 // mode: c++
354 // End:
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition: edns.cc:172
Base class for all sorts of text parse errors.
static const RRClass & CH()
Definition: rrclass.h:307
static const RRClass & IN()
Definition: rrclass.h:319
A standard DNS module exception that is thrown if an RRClass object is being constructed from a incom...
Definition: rrclass.h:58
static const RRClass & HS()
Definition: rrclass.h:313
uint16_t getCode() const
Returns the RR class code as a 16-bit unsigned integer.
Definition: rrclass.h:238
static RRClass * createFromText(const std::string &class_str)
A separate factory of RRClass from text.
Definition: rrclass.cc:59
The RRClass class encapsulates DNS resource record classes.
Definition: rrclass.h:98
bool operator==(const RRClass &other) const
Same as equals().
Definition: rrclass.h:256
A standard DNS module exception that is thrown if an RRClass object is being constructed from an unre...
Definition: rrclass.h:48
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
const std::string toText() const
Convert the RRClass to a string.
Definition: rrclass.cc:44
IncompleteRRClass(const char *file, size_t line, const char *what)
Definition: rrclass.h:60
void toWire(AbstractMessageRenderer &renderer) const
Render the RRClass in the wire format.
Definition: rrclass.cc:54
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static const RRClass & ANY()
Definition: rrclass.h:301
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Definition: buffer.h:294
Defines the logger used by the top-level component of kea-dhcp-ddns.
InvalidRRClass(const char *file, size_t line, const char *what)
Definition: rrclass.h:50
bool equals(const RRClass &other) const
Return true iff two RRClasses are equal.
Definition: rrclass.h:253
The InputBuffer class is a buffer abstraction for manipulating read-only data.
Definition: buffer.h:81
static const RRClass & NONE()
Definition: rrclass.h:325
RRClass(uint16_t classcode)
Constructor from an integer class code.
Definition: rrclass.h:109
bool nequals(const RRClass &other) const
Return true iff two RRClasses are not equal.
Definition: rrclass.h:264
bool operator!=(const RRClass &other) const
Same as nequals().
Definition: rrclass.h:267
bool operator<(const RRClass &other) const
Less-than comparison for RRClass against other.
Definition: rrclass.h:284