mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 06:25:34 +00:00
[2268] Use loadZoneData() inside InMemoryClient
This commit is contained in:
@@ -21,7 +21,6 @@
|
|||||||
#include <datasrc/memory/segment_object_holder.h>
|
#include <datasrc/memory/segment_object_holder.h>
|
||||||
#include <datasrc/memory/treenode_rrset.h>
|
#include <datasrc/memory/treenode_rrset.h>
|
||||||
#include <datasrc/memory/zone_finder.h>
|
#include <datasrc/memory/zone_finder.h>
|
||||||
#include <datasrc/memory/zone_data_updater.h>
|
|
||||||
#include <datasrc/memory/zone_data_loader.h>
|
#include <datasrc/memory/zone_data_loader.h>
|
||||||
|
|
||||||
#include <util/memory_segment_local.h>
|
#include <util/memory_segment_local.h>
|
||||||
@@ -33,9 +32,6 @@
|
|||||||
#include <dns/name.h>
|
#include <dns/name.h>
|
||||||
#include <dns/rdataclass.h>
|
#include <dns/rdataclass.h>
|
||||||
#include <dns/rrclass.h>
|
#include <dns/rrclass.h>
|
||||||
#include <dns/masterload.h>
|
|
||||||
|
|
||||||
#include <boost/bind.hpp>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@@ -84,36 +80,12 @@ InMemoryClient::~InMemoryClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
result::Result
|
result::Result
|
||||||
InMemoryClient::loadInternal(const Name& zone_name,
|
InMemoryClient::loadInternal(const isc::dns::Name& zone_name,
|
||||||
const string& filename,
|
const std::string& filename,
|
||||||
boost::function<void(internal::LoadCallback)>
|
ZoneData* zone_data)
|
||||||
rrset_installer)
|
|
||||||
{
|
{
|
||||||
SegmentObjectHolder<ZoneData, RRClass> holder(
|
SegmentObjectHolder<ZoneData, RRClass> holder(
|
||||||
mem_sgmt_, ZoneData::create(mem_sgmt_, zone_name), rrclass_);
|
mem_sgmt_, zone_data, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_ADD_ZONE).
|
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_ADD_ZONE).
|
||||||
arg(zone_name).arg(rrclass_);
|
arg(zone_name).arg(rrclass_);
|
||||||
@@ -152,32 +124,6 @@ InMemoryClient::loadInternal(const Name& zone_name,
|
|||||||
return (result.code);
|
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
|
RRClass
|
||||||
InMemoryClient::getClass() const {
|
InMemoryClient::getClass() const {
|
||||||
return (rrclass_);
|
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).
|
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEMORY_MEM_LOAD).arg(zone_name).
|
||||||
arg(filename);
|
arg(filename);
|
||||||
|
|
||||||
return (loadInternal(zone_name, filename,
|
ZoneData* zone_data = loadZoneData(mem_sgmt_, rrclass_, zone_name,
|
||||||
boost::bind(masterLoadWrapper, filename.c_str(),
|
filename);
|
||||||
zone_name, getClass(), _1)));
|
return (loadInternal(zone_name, filename, zone_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
result::Result
|
result::Result
|
||||||
InMemoryClient::load(const isc::dns::Name& zone_name,
|
InMemoryClient::load(const isc::dns::Name& zone_name,
|
||||||
ZoneIterator& iterator) {
|
ZoneIterator& iterator) {
|
||||||
return (loadInternal(zone_name, string(),
|
ZoneData* zone_data = loadZoneData(mem_sgmt_, rrclass_, zone_name,
|
||||||
boost::bind(generateRRsetFromIterator,
|
iterator);
|
||||||
&iterator, _1)));
|
return (loadInternal(zone_name, string(), zone_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string
|
const std::string
|
||||||
|
@@ -22,8 +22,6 @@
|
|||||||
#include <datasrc/memory/zone_table.h>
|
#include <datasrc/memory/zone_table.h>
|
||||||
#include <datasrc/memory/zone_data.h>
|
#include <datasrc/memory/zone_data.h>
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace isc {
|
namespace isc {
|
||||||
@@ -36,14 +34,6 @@ class RRsetList;
|
|||||||
namespace datasrc {
|
namespace datasrc {
|
||||||
namespace memory {
|
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.
|
/// \brief A data source client that holds all necessary data in memory.
|
||||||
///
|
///
|
||||||
/// The \c InMemoryClient class provides an access to a conceptual data
|
/// 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.
|
/// \return The number of zones stored in the client.
|
||||||
virtual unsigned int getZoneCount() const;
|
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.
|
/// \brief Load zone from masterfile.
|
||||||
///
|
///
|
||||||
/// This loads data from masterfile specified by filename. It replaces
|
/// This loads data from masterfile specified by filename. It replaces
|
||||||
@@ -200,18 +180,11 @@ private:
|
|||||||
typedef DomainTree<std::string> FileNameTree;
|
typedef DomainTree<std::string> FileNameTree;
|
||||||
typedef DomainTreeNode<std::string> FileNameNode;
|
typedef DomainTreeNode<std::string> FileNameNode;
|
||||||
|
|
||||||
// Common process for zone load.
|
// Common process for zone load. Registers filename internally and
|
||||||
// rrset_installer is a functor that takes another functor as an argument,
|
// adds the ZoneData to the ZoneTable.
|
||||||
// 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.
|
|
||||||
result::Result loadInternal(const isc::dns::Name& zone_name,
|
result::Result loadInternal(const isc::dns::Name& zone_name,
|
||||||
const std::string& filename,
|
const std::string& filename,
|
||||||
boost::function<void(internal::LoadCallback)>
|
ZoneData* zone_data);
|
||||||
rrset_installer);
|
|
||||||
|
|
||||||
util::MemorySegment& mem_sgmt_;
|
util::MemorySegment& mem_sgmt_;
|
||||||
const isc::dns::RRClass rrclass_;
|
const isc::dns::RRClass rrclass_;
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include <datasrc/memory/zone_data.h>
|
#include <datasrc/memory/zone_data.h>
|
||||||
#include <datasrc/memory/zone_table.h>
|
#include <datasrc/memory/zone_table.h>
|
||||||
#include <datasrc/memory/zone_data_updater.h>
|
#include <datasrc/memory/zone_data_updater.h>
|
||||||
|
#include <datasrc/memory/zone_data_loader.h>
|
||||||
#include <datasrc/memory/memory_client.h>
|
#include <datasrc/memory/memory_client.h>
|
||||||
|
|
||||||
#include <testutils/dnsmessage_test.h>
|
#include <testutils/dnsmessage_test.h>
|
||||||
@@ -298,7 +299,7 @@ TEST_F(MemoryClientTest, loadEmptyZoneFileThrows) {
|
|||||||
|
|
||||||
EXPECT_THROW(client_->load(Name("."),
|
EXPECT_THROW(client_->load(Name("."),
|
||||||
TEST_DATA_DIR "/empty.zone"),
|
TEST_DATA_DIR "/empty.zone"),
|
||||||
InMemoryClient::EmptyZone);
|
EmptyZone);
|
||||||
|
|
||||||
EXPECT_EQ(0, client_->getZoneCount());
|
EXPECT_EQ(0, client_->getZoneCount());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user