diff --git a/src/lib/datasrc/memory/memory_client.cc b/src/lib/datasrc/memory/memory_client.cc index df15f6ac55..4ad87c83ca 100644 --- a/src/lib/datasrc/memory/memory_client.cc +++ b/src/lib/datasrc/memory/memory_client.cc @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -33,9 +32,6 @@ #include #include #include -#include - -#include #include #include @@ -84,36 +80,12 @@ InMemoryClient::~InMemoryClient() { } result::Result -InMemoryClient::loadInternal(const Name& zone_name, - const string& filename, - boost::function - rrset_installer) +InMemoryClient::loadInternal(const isc::dns::Name& zone_name, + const std::string& filename, + ZoneData* zone_data) { SegmentObjectHolder 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 to -// function (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 diff --git a/src/lib/datasrc/memory/memory_client.h b/src/lib/datasrc/memory/memory_client.h index 1a17613331..b08e916963 100644 --- a/src/lib/datasrc/memory/memory_client.h +++ b/src/lib/datasrc/memory/memory_client.h @@ -22,8 +22,6 @@ #include #include -#include - #include 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 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 FileNameTree; typedef DomainTreeNode 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 - rrset_installer); + ZoneData* zone_data); util::MemorySegment& mem_sgmt_; const isc::dns::RRClass rrclass_; diff --git a/src/lib/datasrc/tests/memory/memory_client_unittest.cc b/src/lib/datasrc/tests/memory/memory_client_unittest.cc index 74d7aa81d6..4b4341a941 100644 --- a/src/lib/datasrc/tests/memory/memory_client_unittest.cc +++ b/src/lib/datasrc/tests/memory/memory_client_unittest.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -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());