20#include <boost/lexical_cast.hpp>
32 return (isalpha(c) != 0);
43 {
'S', 1, 0xffffffff / 1 },
44 {
'M', 60, 0xffffffff / 60 },
45 {
'H', 60 * 60, 0xffffffff / (60 * 60) },
46 {
'D', 24 * 60 * 60, 0xffffffff / (24 * 60 * 60) },
47 {
'W', 7 * 24 * 60 * 60, 0xffffffff / (7 * 24 * 60 * 60) }
57parseTTLString(
const string& ttlstr, uint32_t& ttlval,
string* error_txt) {
60 *error_txt =
"Empty TTL string";
67 const string::const_iterator end = ttlstr.end();
68 string::const_iterator pos = ttlstr.begin();
72 bool units_mode =
false;
76 const string::const_iterator unit = find_if(pos, end, myIsalpha);
82 *error_txt =
"Missing the last unit: " + ttlstr;
88 val = boost::lexical_cast<uint64_t>(ttlstr);
95 uint32_t multiply = 1;
96 uint32_t max_allowed = 0xffffffff;
98 for (
size_t i = 0; i <
sizeof(units) /
sizeof(*units); ++i) {
99 if (toupper(*unit) == units[i].unit) {
101 multiply = units[i].multiply;
102 max_allowed = units[i].max_allowed;
108 *error_txt =
"Unknown unit used: " +
109 boost::lexical_cast<string>(*unit) +
" in: " + ttlstr;
116 *error_txt =
"Missing number in TTL: " + ttlstr;
120 const uint64_t value =
121 boost::lexical_cast<uint64_t>(
string(pos, unit));
122 if (value > max_allowed) {
124 *error_txt =
"Part of TTL out of range: " + ttlstr;
130 const uint64_t seconds = value * multiply;
138 if (val < seconds || val > 0xffffffff) {
140 *error_txt =
"Part of TTL out of range: " + ttlstr;
147 }
catch (
const boost::bad_lexical_cast&) {
149 *error_txt =
"invalid TTL: " + ttlstr;
154 if (val <= 0xffffffff) {
159 *error_txt =
"TTL out of range: " + ttlstr;
170 if (!parseTTLString(ttlstr, ttlval_, &error_txt)) {
178 if (parseTTLString(ttlstr, ttlval, 0)) {
179 return (
new RRTTL(ttlval));
185 if (buffer.getLength() - buffer.getPosition() <
sizeof(uint32_t)) {
188 ttlval_ = buffer.readUint32();
200 buffer.writeUint32(ttlval_);
205 renderer.writeUint32(ttlval_);
210 os << rrttl.toText();
The AbstractMessageRenderer class is an abstract base class that provides common interfaces for rende...
A standard DNS module exception that is thrown if an RRTTL object is being constructed from a incompl...
A standard DNS module exception that is thrown if an RRTTL object is being constructed from an unreco...
The RRTTL class encapsulates TTLs used in DNS resource records.
void toWire(AbstractMessageRenderer &renderer) const
Render the RRTTL in the wire format.
static RRTTL * createFromText(const std::string &ttlstr)
A separate factory of RRTTL from text.
RRTTL(uint32_t ttlval)
Constructor from an integer TTL value.
const std::string toText() const
Convert the RRTTL to a string.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define isc_throw_assert(expr)
Replacement for assert() that throws if the expression is false.
ostream & operator<<(std::ostream &os, const EDNS &edns)
Insert the EDNS as a string into stream.
Defines the logger used by the top-level component of kea-lfc.