Commit b832c3c9 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[trac550] refactored add() method: separating the validation part.

so that the main method will have a readable size.  no behavior change.
parent f1885e6e
...@@ -153,13 +153,10 @@ struct MemoryZone::MemoryZoneImpl { ...@@ -153,13 +153,10 @@ struct MemoryZone::MemoryZoneImpl {
} }
} }
/* // Validate rrset before adding it to the zone. If something is wrong
* Implementation of longer methods. We put them here, because the // it throws an exception. It doesn't modify the zone, and provides
* access is without the impl_-> and it will get inlined anyway. // the strong exception guarantee.
*/ void addValidation(const ConstRRsetPtr rrset) {
// Implementation of MemoryZone::add
result::Result add(const ConstRRsetPtr& rrset, DomainTree* domains) {
// Sanitize input
if (!rrset) { if (!rrset) {
isc_throw(NullRRset, "The rrset provided is NULL"); isc_throw(NullRRset, "The rrset provided is NULL");
} }
...@@ -176,12 +173,11 @@ struct MemoryZone::MemoryZoneImpl { ...@@ -176,12 +173,11 @@ struct MemoryZone::MemoryZoneImpl {
<< rrset->getName()); << rrset->getName());
} }
Name name(rrset->getName()); NameComparisonResult compare(origin_.compare(rrset->getName()));
NameComparisonResult compare(origin_.compare(name));
if (compare.getRelation() != NameComparisonResult::SUPERDOMAIN && if (compare.getRelation() != NameComparisonResult::SUPERDOMAIN &&
compare.getRelation() != NameComparisonResult::EQUAL) compare.getRelation() != NameComparisonResult::EQUAL)
{ {
isc_throw(OutOfZone, "The name " << name << isc_throw(OutOfZone, "The name " << rrset->getName() <<
" is not contained in zone " << origin_); " is not contained in zone " << origin_);
} }
...@@ -193,35 +189,39 @@ struct MemoryZone::MemoryZoneImpl { ...@@ -193,35 +189,39 @@ struct MemoryZone::MemoryZoneImpl {
// for more technical background. Note also that BIND 9 refuses // for more technical background. Note also that BIND 9 refuses
// NS at a wildcard, so in that sense we simply provide compatible // NS at a wildcard, so in that sense we simply provide compatible
// behavior. // behavior.
if (name.isWildcard()) { if (rrset->getName().isWildcard()) {
if (rrset->getType() == RRType::NS()) { if (rrset->getType() == RRType::NS()) {
isc_throw(AddError, "Invalid NS owner name (wildcard): " << isc_throw(AddError, "Invalid NS owner name (wildcard): " <<
name); rrset->getName());
} }
if (rrset->getType() == RRType::DNAME()) { if (rrset->getType() == RRType::DNAME()) {
isc_throw(AddError, "Invalid DNAME owner name (wildcard): " << isc_throw(AddError, "Invalid DNAME owner name (wildcard): " <<
name); rrset->getName());
} }
} }
}
/*
* Implementation of longer methods. We put them here, because the
* access is without the impl_-> and it will get inlined anyway.
*/
// Implementation of MemoryZone::add
result::Result add(const ConstRRsetPtr& rrset, DomainTree* domains) {
// Sanitize input
addValidation(rrset);
// Add wildcards possibly contained in the owner name to the domain // Add wildcards possibly contained in the owner name to the domain
// tree. // tree.
// Note: this can throw an exception, breaking strong exception // Note: this can throw an exception, breaking strong exception
// guarantee. (see also the note for contextCheck() below). // guarantee. (see also the note for contextCheck() below).
addWildcards(*domains, name); addWildcards(*domains, rrset->getName());
// Get the node // Get the node
DomainNode* node; DomainNode* node;
switch (domains->insert(name, &node)) { DomainTree::Result result = domains->insert(rrset->getName(), &node);
// Just check it returns reasonable results // Just check it returns reasonable results
case DomainTree::SUCCESS: assert((result == DomainTree::SUCCESS ||
case DomainTree::ALREADYEXISTS: result == DomainTree::ALREADYEXISTS) && node!= NULL);
break;
// Something odd got out
default:
assert(0);
}
assert(node != NULL);
// Now get the domain // Now get the domain
DomainPtr domain; DomainPtr domain;
......
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