BIND 10 trac2384, updated. 7460fff538000fa1f1c0d88f99ac2ed5b130fd1c [2376] Documentation update
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Nov 9 11:58:53 UTC 2012
The branch, trac2384 has been updated
via 7460fff538000fa1f1c0d88f99ac2ed5b130fd1c (commit)
via 1a238859593b2fdbaebc9f9b9b430dc19aa4f22d (commit)
via 45d598bed63a8d036d821085310a6ab1f5d45434 (commit)
from a4d16a18e39291ccaeaa3c1ebb712ae7e15a5d0a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7460fff538000fa1f1c0d88f99ac2ed5b130fd1c
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Nov 9 12:58:20 2012 +0100
[2376] Documentation update
commit 1a238859593b2fdbaebc9f9b9b430dc19aa4f22d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Nov 9 12:51:13 2012 +0100
[2376] Disallow missing last unit
Also, simplify the code little bit and make it run faster in the case of
TTL without any units.
commit 45d598bed63a8d036d821085310a6ab1f5d45434
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Fri Nov 9 12:44:41 2012 +0100
[2376] Disallow case with the last unit missing
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/rrttl.cc | 50 +++++++++++++++++++++--------------
src/lib/dns/rrttl.h | 10 +++----
src/lib/dns/tests/rrttl_unittest.cc | 8 +++---
3 files changed, 39 insertions(+), 29 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/rrttl.cc b/src/lib/dns/rrttl.cc
index 02fbe33..2fb755f 100644
--- a/src/lib/dns/rrttl.cc
+++ b/src/lib/dns/rrttl.cc
@@ -69,27 +69,41 @@ RRTTL::RRTTL(const std::string& ttlstr) {
const string::const_iterator end = ttlstr.end();
string::const_iterator pos = ttlstr.begin();
+ // When we detect we have some units
+ bool units_mode = false;
+
try {
while (pos != end) {
// Find the first unit, if there's any.
const string::const_iterator unit = find_if(pos, end, myIsalpha);
- // Default multiplication if no unit.
- uint32_t multiply = 1;
- if (unit != end) {
- // Find the unit and get the size.
- bool found = false;
- for (size_t i = 0; i < sizeof(units) / sizeof(*units); ++i) {
- if (toupper(*unit) == units[i].unit) {
- found = true;
- multiply = units[i].multiply;
- break;
- }
+ // No unit
+ if (unit == end) {
+ if (units_mode) {
+ // We had some units before. The last one is missing unit.
+ isc_throw(InvalidRRTTL, "Missing the last unit: " <<
+ ttlstr);
+ } else {
+ // Case without any units at all. Just convert and store it.
+ val = boost::lexical_cast<int64_t>(ttlstr);
+ break;
}
- if (!found) {
- isc_throw(InvalidRRTTL, "Unknown unit used: " << *unit <<
- " in: " << ttlstr);
+ }
+ // There's a unit now.
+ units_mode = true;
+ // Find the unit and get the size.
+ uint32_t multiply;
+ bool found = false;
+ for (size_t i = 0; i < sizeof(units) / sizeof(*units); ++i) {
+ if (toupper(*unit) == units[i].unit) {
+ found = true;
+ multiply = units[i].multiply;
+ break;
}
}
+ if (!found) {
+ isc_throw(InvalidRRTTL, "Unknown unit used: " << *unit <<
+ " in: " << ttlstr);
+ }
// Now extract the number.
if (unit == pos) {
isc_throw(InvalidRRTTL, "Missing number in TTL: " << ttlstr);
@@ -105,12 +119,8 @@ RRTTL::RRTTL(const std::string& ttlstr) {
isc_throw(InvalidRRTTL, "Part of TTL out of range: " <<
ttlstr);
}
- // Move to after the unit (if any). But make sure not to increment
- // past end, which is, strictly speaking, illegal.
- pos = unit;
- if (pos != end) {
- ++pos;
- }
+ // Move to after the unit.
+ pos = unit + 1;
}
} catch (const boost::bad_lexical_cast&) {
isc_throw(InvalidRRTTL, "invalid TTL: " << ttlstr);
diff --git a/src/lib/dns/rrttl.h b/src/lib/dns/rrttl.h
index 3b2bf42..5acd3b1 100644
--- a/src/lib/dns/rrttl.h
+++ b/src/lib/dns/rrttl.h
@@ -76,11 +76,11 @@ public:
///
/// 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, D,
- /// H, M and S. 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). The
- /// unit at the last number can be omitted in case it is seconds.
+ /// 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).
///
/// \param ttlstr A string representation of the \c RRTTL.
///
diff --git a/src/lib/dns/tests/rrttl_unittest.cc b/src/lib/dns/tests/rrttl_unittest.cc
index 7fbd529..61e7849 100644
--- a/src/lib/dns/tests/rrttl_unittest.cc
+++ b/src/lib/dns/tests/rrttl_unittest.cc
@@ -106,7 +106,7 @@ TEST_F(RRTTLTest, fromTextUnit) {
checkUnit(24 * 60 * 60, 'D');
checkUnit(7 * 24 * 60 * 60, 'W');
- // Some border cases
+ // Some border cases (with units)
EXPECT_EQ(4294967295, RRTTL("4294967295S").getValue());
EXPECT_EQ(0, RRTTL("0W0D0H0M0S").getValue());
EXPECT_EQ(4294967295, RRTTL("1193046H1695S").getValue());
@@ -114,10 +114,8 @@ TEST_F(RRTTLTest, fromTextUnit) {
EXPECT_EQ(4294967295, RRTTL("0000000000000004294967295S").getValue());
// Now some compound ones. We allow any order (it would be much work to
- // check the order anyway). The last part can be without unit, in which
- // case it is considered seconds.
+ // check the order anyway).
EXPECT_EQ(60 * 60 + 3, RRTTL("1H3S").getValue());
- EXPECT_EQ(2 * 24 * 60 * 60 + 75 * 60 + 4, RRTTL("75M2D4").getValue());
// Awkward, but allowed case - the same unit used twice.
EXPECT_EQ(20 * 3600, RRTTL("12H8H").getValue());
@@ -145,6 +143,8 @@ TEST_F(RRTTLTest, fromTextUnit) {
// Empty string is not allowed
EXPECT_THROW(RRTTL(""), InvalidRRTTL);
+ // Missing the last unit is not allowed
+ EXPECT_THROW(RRTTL("3D5"), InvalidRRTTL);
// There are some wrong units
EXPECT_THROW(RRTTL("13X"), InvalidRRTTL);
More information about the bind10-changes
mailing list