[svn] commit: r1425 - in /trunk/src/lib/dns: dnssectime.cc tests/dnssectime_unittest.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Mar 15 22:59:58 UTC 2010
Author: jinmei
Date: Mon Mar 15 22:59:58 2010
New Revision: 1425
Log:
cleanup:
- style guidline
- use anonymous namespace rather than file-local static
- missing header file / removing unnecessary one
- simplify the isc_throw usage
- constify
Modified:
trunk/src/lib/dns/dnssectime.cc
trunk/src/lib/dns/tests/dnssectime_unittest.cc
Modified: trunk/src/lib/dns/dnssectime.cc
==============================================================================
--- trunk/src/lib/dns/dnssectime.cc (original)
+++ trunk/src/lib/dns/dnssectime.cc Mon Mar 15 22:59:58 2010
@@ -20,6 +20,11 @@
#include <sstream>
#include <vector>
+#include <stdio.h>
+#include <time.h>
+
+#include <exceptions/exceptions.h>
+
#include "base64.h"
#include "buffer.h"
#include "messagerenderer.h"
@@ -28,11 +33,6 @@
#include "rrttl.h"
#include "rdata.h"
#include "rdataclass.h"
-#include <boost/lexical_cast.hpp>
-
-#include <stdio.h>
-#include <time.h>
-
#include "dnssectime.h"
using namespace std;
@@ -45,9 +45,8 @@
};
string
-timeToText(const time_t timeval)
-{
- struct tm *t = gmtime(&timeval);
+timeToText(const time_t timeval) {
+ struct tm* const t = gmtime(&timeval);
// gmtime() will keep most values within range, but it can
// produce a five-digit year; check for this.
@@ -66,36 +65,34 @@
return (oss.str());
}
-static inline void
-checkRange(int min, int max, int value, const string& valname) {
+namespace {
+inline void
+checkRange(const int min, const int max, const int value,
+ const string& valname)
+{
if ((value >= min) && (value <= max)) {
return;
}
- ostringstream oss;
- oss << "Invalid " << valname << " value: " << value;
- isc_throw(InvalidTime, oss.str().c_str());
+ isc_throw(InvalidTime, "Invalid " << valname << "value: " << value);
}
-static int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+int days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
-static inline bool
-isLeap(int y) {
+inline bool
+isLeap(const int y) {
return ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0);
+}
}
time_t
-timeFromText(const string& time_txt)
-{
- time_t timeval;
- ostringstream oss;
-
+timeFromText(const string& time_txt) {
// first try reading YYYYMMDDHHmmSS format
int year, month, day, hour, minute, second;
for (int i = 0; i < time_txt.length(); ++i) {
if (!isdigit(time_txt.at(i))) {
- oss << "Couldn't convert non-numeric time value: " << time_txt;
- isc_throw(InvalidTime, oss.str().c_str());
+ isc_throw(InvalidTime,
+ "Couldn't convert non-numeric time value: " << time_txt);
}
}
@@ -103,8 +100,7 @@
sscanf(time_txt.c_str(), "%4d%2d%2d%2d%2d%2d",
&year, &month, &day, &hour, &minute, &second) != 6)
{
- oss << "Couldn't convert time value: " << time_txt;
- isc_throw(InvalidTime, oss.str().c_str());
+ isc_throw(InvalidTime, "Couldn't convert time value: " << time_txt);
}
checkRange(1970, 9999, year, "year");
@@ -115,7 +111,8 @@
checkRange(0, 59, minute, "minute");
checkRange(0, 60, second, "second"); // 60 == leap second.
- timeval = second + (60 * minute) + (3600 * hour) + ((day - 1) * 86400);
+ time_t timeval = second + (60 * minute) + (3600 * hour) +
+ ((day - 1) * 86400);
for (int m = 0; m < (month - 1); m++) {
timeval += days[m] * 86400;
}
Modified: trunk/src/lib/dns/tests/dnssectime_unittest.cc
==============================================================================
--- trunk/src/lib/dns/tests/dnssectime_unittest.cc (original)
+++ trunk/src/lib/dns/tests/dnssectime_unittest.cc Mon Mar 15 22:59:58 2010
@@ -27,8 +27,7 @@
namespace {
-TEST(DNSSECTimeTest, fromText)
-{
+TEST(DNSSECTimeTest, fromText) {
// These are bogus and should be rejected
EXPECT_THROW(timeFromText("2011 101120000"), InvalidTime);
EXPECT_THROW(timeFromText("201101011200-0"), InvalidTime);
@@ -57,14 +56,12 @@
EXPECT_THROW(timeFromText("20110101120061"), InvalidTime); // SS=61
}
-TEST(DNSSECTimeTest, toText)
-{
+TEST(DNSSECTimeTest, toText) {
EXPECT_EQ("19700101000000", timeToText(0));
EXPECT_EQ("20100311233000", timeToText(1268350200));
}
-TEST(DNSSECTimeTest, overflow)
-{
+TEST(DNSSECTimeTest, overflow) {
// Jan 1, Year 10,000.
if (sizeof(time_t) > 4) {
EXPECT_THROW(timeToText(253402300800LL), InvalidTime);
More information about the bind10-changes
mailing list