Commit 4d5a9275 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

renamed filenames to masterload*.*

renamed MasterError to MasterLoadError
based on review comments


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac423@3855 e5f2f494-b856-4b98-b285-d166d9295462
parent 7f8e3a94
......@@ -69,7 +69,7 @@ libdns___la_SOURCES += dnssectime.h dnssectime.cc
libdns___la_SOURCES += edns.h edns.cc
libdns___la_SOURCES += exceptions.h exceptions.cc
libdns___la_SOURCES += util/hex.h
libdns___la_SOURCES += master.h master.cc
libdns___la_SOURCES += masterload.h masterload.cc
libdns___la_SOURCES += message.h message.cc
libdns___la_SOURCES += messagerenderer.h messagerenderer.cc
libdns___la_SOURCES += name.h name.cc
......
......@@ -22,7 +22,7 @@
#include <exceptions/exceptions.h>
#include <dns/master.h>
#include <dns/masterload.h>
#include <dns/name.h>
#include <dns/rdata.h>
#include <dns/rrclass.h>
......@@ -44,7 +44,7 @@ masterLoad(const char* const filename, const Name& origin,
ifs.open(filename, ios_base::in);
if (ifs.fail()) {
isc_throw(MasterError, "Failed to open master file: " << filename);
isc_throw(MasterLoadError, "Failed to open master file: " << filename);
}
masterLoad(ifs, origin, zone_class, callback);
ifs.close();
......@@ -61,7 +61,7 @@ masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
do {
getline(input, line);
if (input.bad() || (input.fail() && !input.eof())) {
isc_throw(MasterError, "Unexpectedly failed to read a line");
isc_throw(MasterLoadError, "Unexpectedly failed to read a line");
}
// blank/comment lines should be simply skipped.
......@@ -72,7 +72,7 @@ masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
// The line shouldn't have leading space (which means omitting the
// owner name).
if (isspace(line[0])) {
isc_throw(MasterError, "Leading space at line " << line_count);
isc_throw(MasterLoadError, "Leading space at line " << line_count);
}
// Parse a single RR
......@@ -81,21 +81,21 @@ masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
stringbuf rdatabuf;
iss >> owner_txt >> ttl_txt >> rrclass_txt >> rrtype_txt >> &rdatabuf;
if (iss.bad() || iss.fail()) {
isc_throw(MasterError, "Parse failure for a valid RR at line "
isc_throw(MasterLoadError, "Parse failure for a valid RR at line "
<< line_count);
}
// This simple version doesn't support relative owner names with a
// separate origin.
if (owner_txt.empty() || *(owner_txt.end() - 1) != '.') {
isc_throw(MasterError, "Owner name is not absolute at line "
isc_throw(MasterLoadError, "Owner name is not absolute at line "
<< line_count);
}
// XXX: this part is a bit tricky (and less efficient). We are going
// to validate the text for the RR parameters, and throw an exception
// if any of them is invalid by converting an underlying exception
// to MasterError. To do that, we need to define the corresponding
// to MasterLoadError. To do that, we need to define the corresponding
// variables used for RRset construction outside the try-catch block,
// but we don't like to use a temporary variable with a meaningless
// initial value. So we define pointers outside the try block
......@@ -113,7 +113,7 @@ masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
rrtype.reset(new RRType(rrtype_txt));
rdata = createRdata(*rrtype, *rrclass, rdatabuf.str());
} catch (const Exception& ex) {
isc_throw(MasterError, "Invalid RR text at line " << line_count
isc_throw(MasterLoadError, "Invalid RR text at line " << line_count
<< ": " << ex.what());
}
......@@ -123,17 +123,18 @@ masterLoad(istream& input, const Name& origin, const RRClass& zone_class,
const NameComparisonResult cmp_result = owner->compare(origin);
if (cmp_result.getRelation() != NameComparisonResult::EQUAL &&
cmp_result.getRelation() != NameComparisonResult::SUBDOMAIN) {
isc_throw(MasterError, "Out-of-zone data at line " << line_count);
isc_throw(MasterLoadError, "Out-of-zone data at line "
<< line_count);
}
if (*rrtype == RRType::SOA() &&
cmp_result.getRelation() != NameComparisonResult::EQUAL) {
isc_throw(MasterError, "SOA not at top of zone at line "
isc_throw(MasterLoadError, "SOA not at top of zone at line "
<< line_count);
}
// Reject RR class mismatching
if (*rrclass != zone_class) {
isc_throw(MasterError, "RR class (" << rrclass_txt
isc_throw(MasterLoadError, "RR class (" << rrclass_txt
<< ") does not match the zone class (" << zone_class
<< ") at line " << line_count);
}
......
......@@ -12,8 +12,8 @@
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef __MASTER_H
#define __MASTER_H 1
#ifndef __MASTERLOAD_H
#define __MASTERLOAD_H 1
#include <iosfwd>
......@@ -30,9 +30,9 @@ class RRClass;
/// \brief An exception that is thrown if an error occurs while loading a
/// master zone data.
class MasterError : public Exception {
class MasterLoadError : public Exception {
public:
MasterError(const char* file, size_t line, const char* what) :
MasterLoadError(const char* file, size_t line, const char* what) :
isc::Exception(file, line, what) {}
};
......@@ -71,7 +71,7 @@ typedef boost::function<void(RRsetPtr rrset)> MasterLoadCallback;
/// (that can be equal to the origin).
/// - If an SOA RR is included, its owner name must be the origin name.
/// If any of these validation checks fails, this function throws an
/// exception of class \c MasterError.
/// exception of class \c MasterLoadError.
///
/// It does not perform other semantical checks, however. For example,
/// it doesn't check if an NS RR of the origin name is included or if
......@@ -139,8 +139,8 @@ typedef boost::function<void(RRsetPtr rrset)> MasterLoadCallback;
///
/// <b>Exceptions</b>
///
/// This function throws an exception of class \c MasterError in the following
/// cases:
/// This function throws an exception of class \c MasterLoadError in the
/// following cases:
/// - Any of the validation checks fails (see the class description).
/// - The input data is not in the acceptable format (see the details of
/// the format above).
......@@ -239,7 +239,7 @@ void masterLoad(std::istream& input, const Name& origin,
//@}
}
#endif // __MASTER_H
#endif // __MASTERLOAD_H
// Local Variables:
// mode: c++
......
......@@ -42,7 +42,7 @@ run_unittests_SOURCES += rdata_tsig_unittest.cc
run_unittests_SOURCES += rrset_unittest.cc rrsetlist_unittest.cc
run_unittests_SOURCES += question_unittest.cc
run_unittests_SOURCES += rrparamregistry_unittest.cc
run_unittests_SOURCES += master_unittest.cc
run_unittests_SOURCES += masterload_unittest.cc
run_unittests_SOURCES += message_unittest.cc
run_unittests_SOURCES += base32hex_unittest.cc
run_unittests_SOURCES += base64_unittest.cc
......
......@@ -23,7 +23,7 @@
#include <gtest/gtest.h>
#include <dns/master.h>
#include <dns/masterload.h>
#include <dns/name.h>
#include <dns/rrclass.h>
#include <dns/rrset.h>
......@@ -166,57 +166,69 @@ TEST_F(MasterTest, loadEmpty) {
TEST_F(MasterTest, loadWithBeginningSpace) {
rr_stream << " " << a_rr1;
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback),
MasterLoadError);
}
TEST_F(MasterTest, loadWithBeginningTab) {
rr_stream << "\t" << a_rr1;
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback),
MasterLoadError);
}
TEST_F(MasterTest, loadInvalidRRClass) {
rr_stream << "example.com. 3600 CH TXT \"test text\"";
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback),
MasterLoadError);
}
TEST_F(MasterTest, loadOutOfZoneData) {
rr_stream << "example.org. 3600 IN A 192.0.2.255";
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback),
MasterLoadError);
}
TEST_F(MasterTest, loadNonAtopSOA) {
// SOA's owner name must be zone's origin.
rr_stream << "soa.example.com. 3600 IN SOA . . 0 0 0 0 0";
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback),
MasterLoadError);
}
TEST_F(MasterTest, loadBadRRText) {
rr_stream << "example..com. 3600 IN A 192.0.2.1"; // bad owner name
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, callback),
MasterLoadError);
// currently we only support numeric TTLs
stringstream rr_stream2("example.com. 1D IN A 192.0.2.1");
EXPECT_THROW(masterLoad(rr_stream2, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream2, origin, zclass, callback),
MasterLoadError);
// bad RR class text
stringstream rr_stream3("example.com. 3600 BAD A 192.0.2.1");
EXPECT_THROW(masterLoad(rr_stream3, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream3, origin, zclass, callback),
MasterLoadError);
// bad RR type text
stringstream rr_stream4("example.com. 3600 IN BAD 192.0.2.1");
EXPECT_THROW(masterLoad(rr_stream4, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream4, origin, zclass, callback),
MasterLoadError);
// bad RDATA text
stringstream rr_stream5("example.com. 3600 IN A 2001:db8::1");
EXPECT_THROW(masterLoad(rr_stream5, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream5, origin, zclass, callback),
MasterLoadError);
// incomplete RR text
stringstream rr_stream6("example.com. 3600 IN A");
EXPECT_THROW(masterLoad(rr_stream6, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream6, origin, zclass, callback),
MasterLoadError);
// owner name is not absolute
stringstream rr_stream7("example.com 3600 IN A 192.0.2.1");
EXPECT_THROW(masterLoad(rr_stream7, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(rr_stream7, origin, zclass, callback),
MasterLoadError);
}
// This is a helper callback to test the case the input stream becomes bad
......@@ -235,7 +247,7 @@ TEST_F(MasterTest, loadBadStream) {
rr_stream << txt_rr << a_rr1;
StreamInvalidator invalidator(rr_stream);
EXPECT_THROW(masterLoad(rr_stream, origin, zclass, invalidator),
MasterError);
MasterLoadError);
}
TEST_F(MasterTest, loadFromFile) {
......@@ -247,10 +259,10 @@ TEST_F(MasterTest, loadFromFile) {
EXPECT_EQ(string(a_rr1) + string(a_rr2), results[1]->toText());
// NULL file name. Should result in exception.
EXPECT_THROW(masterLoad(NULL, origin, zclass, callback), MasterError);
EXPECT_THROW(masterLoad(NULL, origin, zclass, callback), MasterLoadError);
// Non existent file name. Ditto.
EXPECT_THROW(masterLoad(TEST_DATA_BUILDDIR "/notexistent.txt", origin,
zclass, callback), MasterError);
zclass, callback), MasterLoadError);
}
} // end namespace
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment