BIND 10 trac2377, updated. 11ed5b5ca1fb48c7754c1d85b65fa00b00630d78 [2377] Handle expected errors
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Dec 4 10:44:12 UTC 2012
The branch, trac2377 has been updated
via 11ed5b5ca1fb48c7754c1d85b65fa00b00630d78 (commit)
from ad9807ad75f8b76413de4ab0478cff9611a2817a (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 11ed5b5ca1fb48c7754c1d85b65fa00b00630d78
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Tue Dec 4 11:43:20 2012 +0100
[2377] Handle expected errors
By catching all exceptions. It is questionable, if we want to do it that
way, but it seems to work at least for now.
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_loader.cc | 117 ++++++++++++++++++---------
src/lib/dns/tests/master_loader_unittest.cc | 4 +-
2 files changed, 82 insertions(+), 39 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index 5a5aa13..4b59cef 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -64,45 +64,88 @@ public:
}
size_t count = 0;
while (ok_ && count < count_limit) {
- // Skip all EOLNs (empty lines) and finish on EOF
- bool empty = true;
- do {
- const MasterToken& empty_token(lexer_.getNextToken());
- if (empty_token.getType() == MasterToken::END_OF_FILE) {
- // TODO: Check if this is the last source, possibly pop
+ try {
+ // Skip all EOLNs (empty lines) and finish on EOF
+ bool empty = true;
+ do {
+ const MasterToken& empty_token(lexer_.getNextToken());
+ if (empty_token.getType() == MasterToken::END_OF_FILE) {
+ // TODO: Check if this is the last source, possibly pop
+ return (true);
+ }
+ empty = empty_token.getType() == MasterToken::END_OF_LINE;
+ } while (empty);
+ // Return the last token, as it was not empty
+ lexer_.ungetToken();
+
+ const MasterToken::StringRegion
+ name_string(lexer_.getNextToken(MasterToken::QSTRING).
+ getStringRegion());
+ // TODO $ handling
+ const Name name(name_string.beg, name_string.len,
+ &zone_origin_);
+ // TODO: Some more flexibility. We don't allow omitting
+ // anything yet
+
+ // The parameters
+ const RRTTL ttl(getString());
+ const RRClass rrclass(getString());
+ const RRType rrtype(getString());
+
+ // TODO: Some more validation?
+ if (rrclass != zone_class_) {
+ // It doesn't really matter much what type of exception
+ // we throw, we catch it just below.
+ isc_throw(isc::BadValue, "Class mismatch: " << rrclass <<
+ "vs. " << zone_class_);
+ }
+
+ const rdata::RdataPtr data(rdata::createRdata(rrtype, rrclass,
+ lexer_,
+ &zone_origin_,
+ options_,
+ callbacks_));
+ // In case we get NULL, it means there was error creating
+ // the Rdata. The errors should have been reported by
+ // callbacks_ already. We need to decide if we want to continue
+ // or not.
+ if (data != rdata::RdataPtr()) {
+ add_callback_(name, rrclass, rrtype, ttl, data);
+
+ // Good, we loaded another one
+ ++count;
+ } else if (!(options_ & MANY_ERRORS)) {
+ return (true);
+ }
+ } catch (const isc::Exception& e) {
+ // TODO: Do we want to list expected exceptions here instead?
+ callbacks_.error(lexer_.getSourceName(),
+ lexer_.getSourceLine(),
+ e.what());
+ if (options_ & MANY_ERRORS) {
+ // We want to continue. Try to read until the end of line
+ bool end = false;
+ do {
+ const MasterToken& token(lexer_.getNextToken());
+ switch (token.getType()) {
+ case MasterToken::END_OF_FILE:
+ // TODO: Try pop in case this is not the only
+ // source
+ return (true);
+ case MasterToken::END_OF_LINE:
+ end = true;
+ break;
+ default:
+ // Do nothing. This is just to make compiler
+ // happy
+ break;
+ }
+ } while (!end);
+ } else {
+ // We abort on first error. We are therefore done.
return (true);
}
- empty = empty_token.getType() == MasterToken::END_OF_LINE;
- } while (empty);
- // Return the last token, as it was not empty
- lexer_.ungetToken();
-
- const MasterToken::StringRegion
- name_string(lexer_.getNextToken(MasterToken::QSTRING).
- getStringRegion());
- // TODO $ handling
- const Name name(name_string.beg, name_string.len, &zone_origin_);
- // TODO: Some more flexibility. We don't allow omitting anything yet
-
- // The parameters
- const RRTTL ttl(getString());
- const RRClass rrclass(getString());
- const RRType rrtype(getString());
-
- const rdata::RdataPtr data(rdata::createRdata(rrtype, rrclass,
- lexer_,
- &zone_origin_,
- options_,
- callbacks_));
- // In case we get NULL, it means there was error creating
- // the Rdata. The errors should have been reported by
- // callbacks_ already, so we just need to not report the RR
- if (data != rdata::RdataPtr()) {
- add_callback_(name, rrclass, rrtype, ttl, data);
-
- // Good, we loaded another one
- ++count;
- };
+ }
}
// When there was a fatal error and ok is false, we say we are done.
return (!ok_);
diff --git a/src/lib/dns/tests/master_loader_unittest.cc b/src/lib/dns/tests/master_loader_unittest.cc
index b359cf8..58b347a 100644
--- a/src/lib/dns/tests/master_loader_unittest.cc
+++ b/src/lib/dns/tests/master_loader_unittest.cc
@@ -79,8 +79,8 @@ public:
ofstream out(filename.c_str(),
std::ios_base::out | std::ios_base::trunc);
ASSERT_FALSE(out.fail());
- out << "example.org. 3600 IN SOA ns1.example.org.filename "
- "admin.example.org.filename 1234 3600 1800 2419200 7200" << endl;
+ out << "example.org. 3600 IN SOA ns1.example.org. "
+ "admin.example.org. 1234 3600 1800 2419200 7200" << endl;
out << line << endl;
out << "correct 3600 IN A 192.0.2.2" << endl;
out.close();
More information about the bind10-changes
mailing list