Kea 2.7.6
rrttl.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 RRTTL_H
8#define RRTTL_H
9
10#include <dns/exceptions.h>
11#include <util/buffer.h>
12
13#include <boost/optional.hpp>
14
15#include <stdint.h>
16
17namespace isc {
18namespace dns {
19
20// forward declarations
21class AbstractMessageRenderer;
22
27class InvalidRRTTL : public DNSTextError {
28public:
29 InvalidRRTTL(const char* file, size_t line, const char* what) :
30 DNSTextError(file, line, what) {}
31};
32
38public:
39 IncompleteRRTTL(const char* file, size_t line, const char* what) :
40 isc::dns::Exception(file, line, what) {}
41};
42
51class RRTTL {
52public:
58
59
64 explicit RRTTL(uint32_t ttlval) : ttlval_(ttlval) {
65 }
66
81 explicit RRTTL(const std::string& ttlstr);
82
93 explicit RRTTL(isc::util::InputBuffer& buff);
94
122 static RRTTL* createFromText(const std::string& ttlstr);
124
125
129
130
140 const std::string toText() const;
151 void toWire(AbstractMessageRenderer& renderer) const;
161 void toWire(isc::util::OutputBuffer& buff) const;
163
167
168
173 uint32_t getValue() const {
174 return (ttlval_);
175 }
177
185
186
191 bool equals(const RRTTL& other) const {
192 return (ttlval_ == other.ttlval_);
193 }
195 bool operator==(const RRTTL& other) const {
196 return (ttlval_ == other.ttlval_);
197 }
203 bool nequals(const RRTTL& other) const {
204 return (ttlval_ != other.ttlval_);
205 }
207 bool operator!=(const RRTTL& other) const {
208 return (ttlval_ != other.ttlval_);
209 }
217 bool leq(const RRTTL& other) const {
218 return (ttlval_ <= other.ttlval_);
219 }
220
222 bool operator<=(const RRTTL& other) const {
223 return (ttlval_ <= other.ttlval_);
224 }
225
233 bool geq(const RRTTL& other) const {
234 return (ttlval_ >= other.ttlval_);
235 }
236
238 bool operator>=(const RRTTL& other) const {
239 return (ttlval_ >= other.ttlval_);
240 }
241
249 bool lthan(const RRTTL& other) const {
250 return (ttlval_ < other.ttlval_);
251 }
252
254 bool operator<(const RRTTL& other) const {
255 return (ttlval_ < other.ttlval_);
256 }
257
265 bool gthan(const RRTTL& other) const {
266 return (ttlval_ > other.ttlval_);
267 }
268
270 bool operator>(const RRTTL& other) const {
271 return (ttlval_ > other.ttlval_);
272 }
274
278
279
285 static const RRTTL& MAX_TTL() {
286 static const RRTTL max_ttl(0x7fffffff);
287 return (max_ttl);
288 }
290
291private:
292 uint32_t ttlval_;
293};
294
309std::ostream&
310operator<<(std::ostream& os, const RRTTL& rrttl);
311}
312}
313#endif // RRTTL_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 RRTTL object is being constructed from a incompl...
Definition rrttl.h:37
IncompleteRRTTL(const char *file, size_t line, const char *what)
Definition rrttl.h:39
A standard DNS module exception that is thrown if an RRTTL object is being constructed from an unreco...
Definition rrttl.h:27
InvalidRRTTL(const char *file, size_t line, const char *what)
Definition rrttl.h:29
The RRTTL class encapsulates TTLs used in DNS resource records.
Definition rrttl.h:51
bool operator!=(const RRTTL &other) const
Same as nequals().
Definition rrttl.h:207
bool operator>(const RRTTL &other) const
Same as gthan()
Definition rrttl.h:270
void toWire(AbstractMessageRenderer &renderer) const
Render the RRTTL in the wire format.
Definition rrttl.cc:204
bool geq(const RRTTL &other) const
Greater-than or equal comparison for RRTTL against other.
Definition rrttl.h:233
static RRTTL * createFromText(const std::string &ttlstr)
A separate factory of RRTTL from text.
Definition rrttl.cc:176
bool equals(const RRTTL &other) const
Return true iff two RRTTLs are equal.
Definition rrttl.h:191
bool operator==(const RRTTL &other) const
Same as equals().
Definition rrttl.h:195
bool leq(const RRTTL &other) const
Less-than or equal comparison for RRTTL against other.
Definition rrttl.h:217
RRTTL(uint32_t ttlval)
Constructor from an integer TTL value.
Definition rrttl.h:64
bool operator>=(const RRTTL &other) const
Same as geq()
Definition rrttl.h:238
bool nequals(const RRTTL &other) const
Return true iff two RRTTLs are not equal.
Definition rrttl.h:203
bool gthan(const RRTTL &other) const
Greater-than comparison for RRTTL against other.
Definition rrttl.h:265
uint32_t getValue() const
Returns the TTL value as a 32-bit unsigned integer.
Definition rrttl.h:173
bool operator<(const RRTTL &other) const
Same as lthan()
Definition rrttl.h:254
static const RRTTL & MAX_TTL()
The TTL of the max allowable value, per RFC2181 Section 8.
Definition rrttl.h:285
bool lthan(const RRTTL &other) const
Less-than comparison for RRTTL against other.
Definition rrttl.h:249
const std::string toText() const
Convert the RRTTL to a string.
Definition rrttl.cc:192
bool operator<=(const RRTTL &other) const
Same as leq()
Definition rrttl.h:222
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.