Kea 2.7.5
rrclass.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 RRCLASS_H
8#define RRCLASS_H
9
10#include <util/buffer.h>
11
12#include <stdint.h>
13
14#include <string>
15#include <ostream>
16
17#include <dns/exceptions.h>
18
19#include <boost/optional.hpp>
20
21// Undefine the macro IN which is defined in some operating systems
22// but conflicts the IN RR class.
23
24#ifdef IN
25#undef IN
26#endif
27
28namespace isc {
29
30namespace dns {
31
32// forward declarations
33class AbstractMessageRenderer;
34
40public:
41 InvalidRRClass(const char* file, size_t line, const char* what) :
42 DNSTextError(file, line, what) {}
43};
44
50public:
51 IncompleteRRClass(const char* file, size_t line, const char* what) :
52 isc::dns::Exception(file, line, what) {}
53};
54
89class RRClass {
90public:
94
95
100 explicit RRClass(uint16_t classcode) : classcode_(classcode) {
101 }
127 explicit RRClass(const std::string& class_str);
138 explicit RRClass(isc::util::InputBuffer& buffer);
139
171 static RRClass* createFromText(const std::string& class_str);
172
175
176
178
182
183
195 const std::string toText() const;
207 void toWire(AbstractMessageRenderer& renderer) const;
217 void toWire(isc::util::OutputBuffer& buffer) const;
219
223
224
229 uint16_t getCode() const {
230 return (classcode_);
231 }
233
237
238
246 bool equals(const RRClass& other) const {
247 return (classcode_ == other.classcode_);
248 }
249
251 bool operator==(const RRClass& other) const {
252 return (equals(other));
253 }
254
261 bool nequals(const RRClass& other) const {
262 return (classcode_ != other.classcode_);
263 }
265 bool operator!=(const RRClass& other) const {
266 return (nequals(other));
267 }
268
284 bool operator<(const RRClass& other) const {
285 return (classcode_ < other.classcode_);
286 }
287
288 static const RRClass& ANY();
289 static const RRClass& IN();
290 static const RRClass& CH();
291 static const RRClass& NONE();
292
293private:
294 uint16_t classcode_;
295};
296
297inline const RRClass&
299 static RRClass rrclass(255);
300 return (rrclass);
301}
302
303inline const RRClass&
305 static RRClass rrclass(1);
306 return (rrclass);
307}
308
309inline const RRClass&
311 static RRClass rrclass(3);
312 return (rrclass);
313}
314
315inline const RRClass&
317 static RRClass rrclass(254);
318 return (rrclass);
319}
320
335std::ostream&
336operator<<(std::ostream& os, const RRClass& rrclass);
337}
338}
339#endif // RRCLASS_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.
A standard DNS module exception that is thrown if an RRClass object is being constructed from a incom...
Definition rrclass.h:49
IncompleteRRClass(const char *file, size_t line, const char *what)
Definition rrclass.h:51
A standard DNS module exception that is thrown if an RRClass object is being constructed from an unre...
Definition rrclass.h:39
InvalidRRClass(const char *file, size_t line, const char *what)
Definition rrclass.h:41
The RRClass class encapsulates DNS resource record classes.
Definition rrclass.h:89
bool operator!=(const RRClass &other) const
Same as nequals().
Definition rrclass.h:265
static const RRClass & ANY()
Definition rrclass.h:298
static const RRClass & NONE()
Definition rrclass.h:316
bool operator==(const RRClass &other) const
Same as equals().
Definition rrclass.h:251
static const RRClass & CH()
Definition rrclass.h:310
uint16_t getCode() const
Returns the RR class code as a 16-bit unsigned integer.
Definition rrclass.h:229
void toWire(AbstractMessageRenderer &renderer) const
Render the RRClass in the wire format.
Definition rrclass.cc:53
static RRClass * createFromText(const std::string &class_str)
A separate factory of RRClass from text.
Definition rrclass.cc:58
bool operator<(const RRClass &other) const
Less-than comparison for RRClass against other.
Definition rrclass.h:284
static const RRClass & IN()
Definition rrclass.h:304
bool nequals(const RRClass &other) const
Return true iff two RRClasses are not equal.
Definition rrclass.h:261
const std::string toText() const
Convert the RRClass to a string.
Definition rrclass.cc:43
RRClass(uint16_t classcode)
Constructor from an integer class code.
Definition rrclass.h:100
bool equals(const RRClass &other) const
Return true iff two RRClasses are equal.
Definition rrclass.h:246
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
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Definition edns.cc:163
Defines the logger used by the top-level component of kea-lfc.