Kea 2.5.8
isc::dns::RRTTL Class Reference

The RRTTL class encapsulates TTLs used in DNS resource records. More...

#include <rrttl.h>

Public Member Functions

Converter methods
const std::string toText () const
 Convert the RRTTL to a string.
 
void toWire (AbstractMessageRenderer &renderer) const
 Render the RRTTL in the wire format.
 
void toWire (isc::util::OutputBuffer &buff) const
 Render the RRTTL in the wire format.
 
Getter Methods
uint32_t getValue () const
 Returns the TTL value as a 32-bit unsigned integer.
 
Comparison methods

Comparison between two RRTTL objects is performed in a straightforward way, that is, comparing the corresponding TTL values (which is the result of the getValue() method) as 32-bit unsigned integers.

bool equals (const RRTTL &other) const
 Return true iff two RRTTLs are equal.
 
bool operator== (const RRTTL &other) const
 Same as equals().
 
bool nequals (const RRTTL &other) const
 Return true iff two RRTTLs are not equal.
 
bool operator!= (const RRTTL &other) const
 Same as nequals().
 
bool leq (const RRTTL &other) const
 Less-than or equal comparison for RRTTL against other.
 
bool operator<= (const RRTTL &other) const
 Same as leq()
 
bool geq (const RRTTL &other) const
 Greater-than or equal comparison for RRTTL against other.
 
bool operator>= (const RRTTL &other) const
 Same as geq()
 
bool lthan (const RRTTL &other) const
 Less-than comparison for RRTTL against other.
 
bool operator< (const RRTTL &other) const
 Same as lthan()
 
bool gthan (const RRTTL &other) const
 Greater-than comparison for RRTTL against other.
 
bool operator> (const RRTTL &other) const
 Same as gthan()
 

Protocol constants

static const RRTTLMAX_TTL ()
 The TTL of the max allowable value, per RFC2181 Section 8.
 

Constructors, Factory and Destructor

Note: We use the default copy constructor and the default copy assignment operator intentionally.

 RRTTL (uint32_t ttlval)
 Constructor from an integer TTL value.
 
 RRTTL (const std::string &ttlstr)
 Constructor from a string.
 
 RRTTL (isc::util::InputBuffer &buff)
 Constructor from wire-format data.
 
static RRTTLcreateFromText (const std::string &ttlstr)
 A separate factory of RRTTL from text.
 

Detailed Description

The RRTTL class encapsulates TTLs used in DNS resource records.

This is a straightforward class; an RRTTL object simply maintains a 32-bit unsigned integer corresponding to the TTL value. The main purpose of this class is to provide convenient interfaces to convert a textual representation into the integer TTL value and vice versa, and to handle wire-format representations.

Definition at line 51 of file rrttl.h.

Constructor & Destructor Documentation

◆ RRTTL() [1/3]

isc::dns::RRTTL::RRTTL ( uint32_t  ttlval)
inlineexplicit

Constructor from an integer TTL value.

This constructor never throws an exception.

Parameters
ttlvalAn 32-bit integer of the RRTTL.

Definition at line 64 of file rrttl.h.

◆ RRTTL() [2/3]

isc::dns::RRTTL::RRTTL ( const std::string &  ttlstr)
explicit

Constructor from a string.

It accepts either a decimal number, specifying number of seconds. Or, it can be given a sequence of numbers and units, like "2H" (meaning two hours), "1W3D" (one week and 3 days). The allowed units are W (week), D (day), H (hour), M (minute) and S (second). They can be also specified in lower-case. No further restrictions are checked (so they can be specified in arbitrary order and even things like "1D1D" can be used to specify two days).

Parameters
ttlstrA string representation of the RRTTL.
Exceptions
InvalidRRTTLin case the string is not recognized as valid TTL representation.

Definition at line 168 of file rrttl.cc.

References isc_throw.

◆ RRTTL() [3/3]

isc::dns::RRTTL::RRTTL ( isc::util::InputBuffer buff)
explicit

Constructor from wire-format data.

The buffer parameter normally stores a complete DNS message containing the RRTTL to be constructed. The current read position of the buffer points to the head of the type.

If the given data does not large enough to contain a 16-bit integer, an exception of class IncompleteRRTTL will be thrown.

Parameters
buffA buffer storing the wire format data.

Definition at line 184 of file rrttl.cc.

References isc::util::InputBuffer::getLength(), isc::util::InputBuffer::getPosition(), isc_throw, and isc::util::InputBuffer::readUint32().

+ Here is the call graph for this function:

Member Function Documentation

◆ createFromText()

RRTTL * isc::dns::RRTTL::createFromText ( const std::string &  ttlstr)
static

A separate factory of RRTTL from text.

This static method is similar to the constructor that takes a string object, but works as a factory and reports parsing failure in the form of the return value. Normally the constructor version should suffice, but in some cases the caller may have to expect mixture of valid and invalid input, and may want to minimize the overhead of possible exception handling. This version is provided for such purpose.

If the given text represents a valid RRTTL, it returns a pointer to a new RRTTL object. If the given text does not represent a valid RRTTL, it returns null..

One main purpose of this function is to minimize the overhead when the given text does not represent a valid RR TTL. For this reason this function intentionally omits the capability of delivering a detailed reason for the parse failure, such as in the want() string when exception is thrown from the constructor (it will internally require a creation of string object, which is relatively expensive). If such detailed information is necessary, the constructor version should be used to catch the resulting exception.

This function never throws the InvalidRRTTL exception.

Parameters
ttlstrA string representation of the RRTTL.
Returns
A new RRTTL object for the given text or a null value.

Definition at line 176 of file rrttl.cc.

◆ equals()

bool isc::dns::RRTTL::equals ( const RRTTL other) const
inline

Return true iff two RRTTLs are equal.

This method never throws an exception.

Parameters
otherthe RRTTL object to compare against.

Definition at line 191 of file rrttl.h.

◆ geq()

bool isc::dns::RRTTL::geq ( const RRTTL other) const
inline

Greater-than or equal comparison for RRTTL against other.

This method never throws an exception.

Parameters
otherthe RRTTL object to compare against.
Returns
true if this RRTTL is greater than or equal to the other; otherwise false.

Definition at line 233 of file rrttl.h.

◆ getValue()

uint32_t isc::dns::RRTTL::getValue ( ) const
inline

Returns the TTL value as a 32-bit unsigned integer.

This method never throws an exception.

Returns
An 32-bit integer corresponding to the RRTTL.

Definition at line 173 of file rrttl.h.

Referenced by isc::dns::EDNS::EDNS(), and isc::dns::createEDNSFromRR().

◆ gthan()

bool isc::dns::RRTTL::gthan ( const RRTTL other) const
inline

Greater-than comparison for RRTTL against other.

This method never throws an exception.

Parameters
otherthe RRTTL object to compare against.
Returns
true if this RRTTL is greater than the other; otherwise false.

Definition at line 265 of file rrttl.h.

◆ leq()

bool isc::dns::RRTTL::leq ( const RRTTL other) const
inline

Less-than or equal comparison for RRTTL against other.

This method never throws an exception.

Parameters
otherthe RRTTL object to compare against.
Returns
true if this RRTTL is less than or equal to the other; otherwise false.

Definition at line 217 of file rrttl.h.

◆ lthan()

bool isc::dns::RRTTL::lthan ( const RRTTL other) const
inline

Less-than comparison for RRTTL against other.

This method never throws an exception.

Parameters
otherthe RRTTL object to compare against.
Returns
true if this RRTTL is less than the other; otherwise false.

Definition at line 249 of file rrttl.h.

◆ MAX_TTL()

static const RRTTL & isc::dns::RRTTL::MAX_TTL ( )
inlinestatic

The TTL of the max allowable value, per RFC2181 Section 8.

The max value is the largest unsigned 31 bit integer, 2^31-1.

Note
At the moment an RRTTL object can have a value larger than this limit. We may revisit it in a future version.

Definition at line 285 of file rrttl.h.

◆ nequals()

bool isc::dns::RRTTL::nequals ( const RRTTL other) const
inline

Return true iff two RRTTLs are not equal.

This method never throws an exception.

Parameters
otherthe RRTTL object to compare against.

Definition at line 203 of file rrttl.h.

◆ operator!=()

bool isc::dns::RRTTL::operator!= ( const RRTTL other) const
inline

Same as nequals().

Definition at line 207 of file rrttl.h.

◆ operator<()

bool isc::dns::RRTTL::operator< ( const RRTTL other) const
inline

Same as lthan()

Definition at line 254 of file rrttl.h.

◆ operator<=()

bool isc::dns::RRTTL::operator<= ( const RRTTL other) const
inline

Same as leq()

Definition at line 222 of file rrttl.h.

◆ operator==()

bool isc::dns::RRTTL::operator== ( const RRTTL other) const
inline

Same as equals().

Definition at line 195 of file rrttl.h.

◆ operator>()

bool isc::dns::RRTTL::operator> ( const RRTTL other) const
inline

Same as gthan()

Definition at line 270 of file rrttl.h.

◆ operator>=()

bool isc::dns::RRTTL::operator>= ( const RRTTL other) const
inline

Same as geq()

Definition at line 238 of file rrttl.h.

◆ toText()

const string isc::dns::RRTTL::toText ( ) const

Convert the RRTTL to a string.

This version of implementation simply converts the TTL value into the numeric textual representation. We may introduce more human-readable format depending on the context in future versions.

If resource allocation in rendering process fails, a corresponding standard exception will be thrown.

Returns
A string representation of the RRTTL.

Definition at line 192 of file rrttl.cc.

Referenced by isc::dns::operator<<(), and isc::dns::AbstractRRset::toText().

◆ toWire() [1/2]

void isc::dns::RRTTL::toWire ( AbstractMessageRenderer renderer) const

Render the RRTTL in the wire format.

This method renders the TTL value in network byte order via renderer, which encapsulates output buffer and other rendering contexts.

If resource allocation in rendering process fails, a corresponding standard exception will be thrown.

Parameters
rendererDNS message rendering context that encapsulates the output buffer in which the RRTTL is to be stored.

Definition at line 204 of file rrttl.cc.

References isc::dns::AbstractMessageRenderer::writeUint32().

Referenced by isc::dns::BasicRRsetImpl::toWire().

+ Here is the call graph for this function:

◆ toWire() [2/2]

void isc::dns::RRTTL::toWire ( isc::util::OutputBuffer buff) const

Render the RRTTL in the wire format.

This method renders the TTL value in network byte order into the buffer.

If resource allocation in rendering process fails, a corresponding standard exception will be thrown.

Parameters
buffAn output buffer to store the wire data.

Definition at line 199 of file rrttl.cc.

References isc::util::OutputBuffer::writeUint32().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: