Kea  2.1.7-git
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. More...
 
void toWire (AbstractMessageRenderer &renderer) const
 Render the RRTTL in the wire format. More...
 
void toWire (isc::util::OutputBuffer &buffer) const
 Render the RRTTL in the wire format. More...
 
Getter Methods
uint32_t getValue () const
 Returns the TTL value as a 32-bit unsigned integer. More...
 
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. More...
 
bool operator== (const RRTTL &other) const
 Same as equals(). More...
 
bool nequals (const RRTTL &other) const
 Return true iff two RRTTLs are not equal. More...
 
bool operator!= (const RRTTL &other) const
 Same as nequals(). More...
 
bool leq (const RRTTL &other) const
 Less-than or equal comparison for RRTTL against other. More...
 
bool operator<= (const RRTTL &other) const
 Same as leq() More...
 
bool geq (const RRTTL &other) const
 Greater-than or equal comparison for RRTTL against other. More...
 
bool operator>= (const RRTTL &other) const
 Same as geq() More...
 
bool lthan (const RRTTL &other) const
 Less-than comparison for RRTTL against other. More...
 
bool operator< (const RRTTL &other) const
 Same as lthan() More...
 
bool gthan (const RRTTL &other) const
 Greater-than comparison for RRTTL against other. More...
 
bool operator> (const RRTTL &other) const
 Same as gthan() More...
 

Static Public Member Functions

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

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. More...
 
 RRTTL (const std::string &ttlstr)
 Constructor from a string. More...
 
 RRTTL (isc::util::InputBuffer &buffer)
 Constructor from wire-format data. More...
 
static RRTTLcreateFromText (const std::string &ttlstr)
 A separate factory of RRTTL from text. More...
 

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 55 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 68 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 buffer)
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
bufferA 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.

Referenced by isc::dns::MasterLoader::MasterLoaderImpl::getPosition().

◆ 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 192 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 228 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 176 of file rrttl.h.

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

◆ 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 256 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 214 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 242 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 274 of file rrttl.h.

Referenced by isc::dns::MasterLoader::MasterLoaderImpl::getPosition().

◆ 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 202 of file rrttl.h.

◆ operator!=()

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

Same as nequals().

Definition at line 205 of file rrttl.h.

◆ operator<()

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

Same as lthan()

Definition at line 246 of file rrttl.h.

◆ operator<=()

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

Same as leq()

Definition at line 218 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 260 of file rrttl.h.

References isc::util::operator<<().

+ Here is the call graph for this function:

◆ operator>=()

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

Same as geq()

Definition at line 232 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::MasterLoader::MasterLoaderImpl::getPosition(), isc::dns::operator<<(), and isc::dns::TSIGRecord::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::AbstractRRset::toText().

+ Here is the call graph for this function:

◆ toWire() [2/2]

void isc::dns::RRTTL::toWire ( isc::util::OutputBuffer buffer) 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
bufferAn 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: