2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 13:37:55 +00:00

[2268] Use loadZoneData() inside InMemoryClient

This commit is contained in:
Mukund Sivaraman 2012-10-12 09:51:30 +05:30
parent 97a6125c53
commit e77ef46d0c
3 changed files with 15 additions and 95 deletions

View File

@ -21,7 +21,6 @@
#include <datasrc/memory/segment_object_holder.h>
#include <datasrc/memory/treenode_rrset.h>
#include <datasrc/memory/zone_finder.h>
#include <datasrc/memory/zone_data_updater.h>
#include <datasrc/memory/zone_data_loader.h>
#include <util/memory_segment_local.h>
@ -33,9 +32,6 @@
#include <dns/name.h>
#include <dns/rdataclass.h>
#include <dns/rrclass.h>
#include <dns/masterload.h>
#include <boost/bind.hpp>
#include <algorithm>
#include <utility>
@ -84,36 +80,12 @@ InMemoryClient::~InMemoryClient() {
}
result::Result
InMemoryClient::loadInternal(const Name& zone_name,
const string& filename,
boost::function<void(internal::LoadCallback)>
rrset_installer)
InMemoryClient::loadInternal(const isc::dns::Name& zone_name,
const std::string& filename,
ZoneData* zone_data)
{
SegmentObjectHolder<ZoneData, RRClass> holder(
mem_sgmt_, ZoneData::create(mem_sgmt_, zone_name), rrclass_);
ZoneDataLoader loader(mem_sgmt_, rrclass_, zone_name, *holder.get());
rrset_installer(boost::bind(&ZoneDataLoader::addFromLoad, &loader, _1));
// Add any last RRsets that were left
loader.flushNodeRRsets();
const ZoneNode* origin_node = holder.get()->getOriginNode();
const RdataSet* set = origin_node->getData();
// If the zone is NSEC3-signed, check if it has NSEC3PARAM
if (holder.get()->isNSEC3Signed()) {
if (RdataSet::find(set, RRType::NSEC3PARAM()) == NULL) {
LOG_WARN(logger, DATASRC_MEMORY_MEM_NO_NSEC3PARAM).
arg(zone_name).arg(rrclass_);
}
}
// When an empty zone file is loaded, the origin doesn't even have
// an SOA RR. This condition should be avoided, and hence load()
// should throw when an empty zone is loaded.
if (RdataSet::find(set, RRType::SOA()) == NULL) {
isc_throw(EmptyZone,
"Won't create an empty zone for: " << zone_name);
}
mem_sgmt_, zone_data, rrclass_);
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_ADD_ZONE).
arg(zone_name).arg(rrclass_);
@ -152,32 +124,6 @@ InMemoryClient::loadInternal(const Name& zone_name,
return (result.code);
}
namespace {
// A wrapper for dns::masterLoad used by load() below. Essentially it
// converts the two callback types. Note the mostly redundant wrapper of
// boost::bind. It converts function<void(ConstRRsetPtr)> to
// function<void(RRsetPtr)> (masterLoad() expects the latter). SunStudio
// doesn't seem to do this conversion if we just pass 'callback'.
void
masterLoadWrapper(const char* const filename, const Name& origin,
const RRClass& zone_class,
internal::LoadCallback callback)
{
masterLoad(filename, origin, zone_class, boost::bind(callback, _1));
}
// The installer called from load() for the iterator version of load().
void
generateRRsetFromIterator(ZoneIterator* iterator,
internal::LoadCallback callback)
{
ConstRRsetPtr rrset;
while ((rrset = iterator->getNextRRset()) != NULL) {
callback(rrset);
}
}
}
RRClass
InMemoryClient::getClass() const {
return (rrclass_);
@ -215,17 +161,17 @@ InMemoryClient::load(const isc::dns::Name& zone_name,
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_LOAD).arg(zone_name).
arg(filename);
return (loadInternal(zone_name, filename,
boost::bind(masterLoadWrapper, filename.c_str(),
zone_name, getClass(), _1)));
ZoneData* zone_data = loadZoneData(mem_sgmt_, rrclass_, zone_name,
filename);
return (loadInternal(zone_name, filename, zone_data));
}
result::Result
InMemoryClient::load(const isc::dns::Name& zone_name,
ZoneIterator& iterator) {
return (loadInternal(zone_name, string(),
boost::bind(generateRRsetFromIterator,
&iterator, _1)));
ZoneData* zone_data = loadZoneData(mem_sgmt_, rrclass_, zone_name,
iterator);
return (loadInternal(zone_name, string(), zone_data));
}
const std::string

View File

@ -22,8 +22,6 @@
#include <datasrc/memory/zone_table.h>
#include <datasrc/memory/zone_data.h>
#include <boost/function.hpp>
#include <string>
namespace isc {
@ -36,14 +34,6 @@ class RRsetList;
namespace datasrc {
namespace memory {
namespace internal {
// Please don't use anything from here outside the InMemoryClient
// implementation.
// A functor type used for loading.
typedef boost::function<void(isc::dns::ConstRRsetPtr)> LoadCallback;
} // end of internal namespace
/// \brief A data source client that holds all necessary data in memory.
///
/// The \c InMemoryClient class provides an access to a conceptual data
@ -87,16 +77,6 @@ public:
/// \return The number of zones stored in the client.
virtual unsigned int getZoneCount() const;
/// \brief Zone is empty exception.
///
/// This is thrown if we have an empty zone created as a result of
/// load().
struct EmptyZone : public InvalidParameter {
EmptyZone(const char* file, size_t line, const char* what) :
InvalidParameter(file, line, what)
{}
};
/// \brief Load zone from masterfile.
///
/// This loads data from masterfile specified by filename. It replaces
@ -200,18 +180,11 @@ private:
typedef DomainTree<std::string> FileNameTree;
typedef DomainTreeNode<std::string> FileNameNode;
// Common process for zone load.
// rrset_installer is a functor that takes another functor as an argument,
// and expected to call the latter for each RRset of the zone. How the
// sequence of the RRsets is generated depends on the internal
// details of the loader: either from a textual master file or from
// another data source.
// filename is the file name of the master file or empty if the zone is
// loaded from another data source.
// Common process for zone load. Registers filename internally and
// adds the ZoneData to the ZoneTable.
result::Result loadInternal(const isc::dns::Name& zone_name,
const std::string& filename,
boost::function<void(internal::LoadCallback)>
rrset_installer);
ZoneData* zone_data);
util::MemorySegment& mem_sgmt_;
const isc::dns::RRClass rrclass_;

View File

@ -30,6 +30,7 @@
#include <datasrc/memory/zone_data.h>
#include <datasrc/memory/zone_table.h>
#include <datasrc/memory/zone_data_updater.h>
#include <datasrc/memory/zone_data_loader.h>
#include <datasrc/memory/memory_client.h>
#include <testutils/dnsmessage_test.h>
@ -298,7 +299,7 @@ TEST_F(MemoryClientTest, loadEmptyZoneFileThrows) {
EXPECT_THROW(client_->load(Name("."),
TEST_DATA_DIR "/empty.zone"),
InMemoryClient::EmptyZone);
EmptyZone);
EXPECT_EQ(0, client_->getZoneCount());