12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007 |
- #include <map>
- #include <cassert>
- #include <boost/shared_ptr.hpp>
- #include <boost/bind.hpp>
- #include <boost/foreach.hpp>
- #include <exceptions/exceptions.h>
- #include <dns/name.h>
- #include <dns/rrclass.h>
- #include <dns/rrsetlist.h>
- #include <dns/masterload.h>
- #include <datasrc/memory_datasrc.h>
- #include <datasrc/rbtree.h>
- #include <datasrc/logger.h>
- #include <datasrc/iterator.h>
- #include <datasrc/data_source.h>
- #include <datasrc/factory.h>
- #include <cc/data.h>
- using namespace std;
- using namespace isc::dns;
- using namespace isc::data;
- namespace isc {
- namespace datasrc {
- namespace {
- typedef map<RRType, ConstRRsetPtr> Domain;
- typedef Domain::value_type DomainPair;
- typedef boost::shared_ptr<Domain> DomainPtr;
- typedef RBTree<Domain> DomainTree;
- typedef RBNode<Domain> DomainNode;
- }
- struct InMemoryZoneFinder::InMemoryZoneFinderImpl {
-
- InMemoryZoneFinderImpl(const RRClass& zone_class, const Name& origin) :
- zone_class_(zone_class), origin_(origin), origin_data_(NULL),
- domains_(true)
- {
-
- domains_.insert(origin, &origin_data_);
- DomainPtr origin_domain(new Domain);
- origin_data_->setData(origin_domain);
- }
- static const DomainNode::Flags DOMAINFLAG_WILD = DomainNode::FLAG_USER1;
-
- RRClass zone_class_;
- Name origin_;
- DomainNode* origin_data_;
- string file_name_;
-
- DomainTree domains_;
-
-
-
-
-
-
-
-
-
-
-
-
-
- void addWildcards(DomainTree& domains, const Name& name) {
- Name wname(name);
- const unsigned int labels(wname.getLabelCount());
- const unsigned int origin_labels(origin_.getLabelCount());
- for (unsigned int l = labels;
- l > origin_labels;
- --l, wname = wname.split(1)) {
- if (wname.isWildcard()) {
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ADD_WILDCARD).
- arg(name);
-
-
- DomainNode* node;
- DomainTree::Result result(domains.insert(wname.split(1),
- &node));
- assert(result == DomainTree::SUCCESS ||
- result == DomainTree::ALREADYEXISTS);
- node->setFlag(DOMAINFLAG_WILD);
-
-
-
-
- result = domains.insert(wname, &node);
- assert(result == DomainTree::SUCCESS ||
- result == DomainTree::ALREADYEXISTS);
- }
- }
- }
-
- void contextCheck(const ConstRRsetPtr& rrset,
- const DomainPtr& domain) const {
-
-
- if (rrset->getType() == RRType::CNAME()) {
-
-
-
- if (!domain->empty()) {
- LOG_ERROR(logger, DATASRC_MEM_CNAME_TO_NONEMPTY).
- arg(rrset->getName());
- isc_throw(AddError, "CNAME can't be added with other data for "
- << rrset->getName());
- }
- } else if (domain->find(RRType::CNAME()) != domain->end()) {
- LOG_ERROR(logger, DATASRC_MEM_CNAME_COEXIST).arg(rrset->getName());
- isc_throw(AddError, "CNAME and " << rrset->getType() <<
- " can't coexist for " << rrset->getName());
- }
-
- if (rrset->getName() != origin_ &&
-
- ((rrset->getType() == RRType::DNAME() &&
- domain->find(RRType::NS()) != domain->end()) ||
-
- (rrset->getType() == RRType::NS() &&
- domain->find(RRType::DNAME()) != domain->end())))
- {
- LOG_ERROR(logger, DATASRC_MEM_DNAME_NS).arg(rrset->getName());
- isc_throw(AddError, "DNAME can't coexist with NS in non-apex "
- "domain " << rrset->getName());
- }
- }
-
-
-
- void addValidation(const ConstRRsetPtr rrset) {
- if (!rrset) {
- isc_throw(NullRRset, "The rrset provided is NULL");
- }
-
-
- if ((rrset->getType() == RRType::CNAME() ||
- rrset->getType() == RRType::DNAME()) &&
- rrset->getRdataCount() > 1)
- {
-
-
-
- LOG_ERROR(logger, DATASRC_MEM_SINGLETON).arg(rrset->getName()).
- arg(rrset->getType());
- isc_throw(AddError, "multiple RRs of singleton type for "
- << rrset->getName());
- }
- NameComparisonResult compare(origin_.compare(rrset->getName()));
- if (compare.getRelation() != NameComparisonResult::SUPERDOMAIN &&
- compare.getRelation() != NameComparisonResult::EQUAL)
- {
- LOG_ERROR(logger, DATASRC_MEM_OUT_OF_ZONE).arg(rrset->getName()).
- arg(origin_);
- isc_throw(OutOfZone, "The name " << rrset->getName() <<
- " is not contained in zone " << origin_);
- }
-
-
-
-
-
-
-
-
- if (rrset->getName().isWildcard()) {
- if (rrset->getType() == RRType::NS()) {
- LOG_ERROR(logger, DATASRC_MEM_WILDCARD_NS).
- arg(rrset->getName());
- isc_throw(AddError, "Invalid NS owner name (wildcard): " <<
- rrset->getName());
- }
- if (rrset->getType() == RRType::DNAME()) {
- LOG_ERROR(logger, DATASRC_MEM_WILDCARD_DNAME).
- arg(rrset->getName());
- isc_throw(AddError, "Invalid DNAME owner name (wildcard): " <<
- rrset->getName());
- }
- }
- }
-
-
- result::Result add(const ConstRRsetPtr& rrset, DomainTree* domains) {
-
-
- addValidation(rrset);
-
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ADD_RRSET).
- arg(rrset->getName()).arg(rrset->getType()).arg(origin_);
-
-
-
-
- addWildcards(*domains, rrset->getName());
-
- DomainNode* node;
- DomainTree::Result result = domains->insert(rrset->getName(), &node);
-
- assert((result == DomainTree::SUCCESS ||
- result == DomainTree::ALREADYEXISTS) && node!= NULL);
-
- DomainPtr domain;
-
- if (node->isEmpty()) {
- domain.reset(new Domain);
- node->setData(domain);
- } else {
- domain = node->getData();
- }
-
-
-
-
-
- contextCheck(rrset, domain);
-
- if (domain->insert(DomainPair(rrset->getType(), rrset)).second) {
-
-
-
- if (rrset->getType() == RRType::NS() &&
- rrset->getName() != origin_) {
- node->setFlag(DomainNode::FLAG_CALLBACK);
-
- } else if (rrset->getType() == RRType::DNAME()) {
- node->setFlag(DomainNode::FLAG_CALLBACK);
- }
- return (result::SUCCESS);
- } else {
-
- return (result::EXIST);
- }
- }
-
- void addFromLoad(const ConstRRsetPtr& set, DomainTree* domains) {
- switch (add(set, domains)) {
- case result::EXIST:
- LOG_ERROR(logger, DATASRC_MEM_DUP_RRSET).
- arg(set->getName()).arg(set->getType());
- isc_throw(dns::MasterLoadError, "Duplicate rrset: " <<
- set->toText());
- case result::SUCCESS:
- return;
- default:
- assert(0);
- }
- }
-
-
-
-
-
- struct FindState {
- FindState(FindOptions options) :
- zonecut_node_(NULL),
- dname_node_(NULL),
- options_(options)
- {}
- const DomainNode* zonecut_node_;
- const DomainNode* dname_node_;
- ConstRRsetPtr rrset_;
- const FindOptions options_;
- };
-
-
- static bool cutCallback(const DomainNode& node, FindState* state) {
-
-
-
-
- const Domain::const_iterator foundDNAME(node.getData()->find(
- RRType::DNAME()));
- if (foundDNAME != node.getData()->end()) {
- LOG_DEBUG(logger, DBG_TRACE_DETAILED,
- DATASRC_MEM_DNAME_ENCOUNTERED);
- state->dname_node_ = &node;
- state->rrset_ = foundDNAME->second;
-
-
-
-
-
-
- return (true);
- }
-
- const Domain::const_iterator foundNS(node.getData()->find(
- RRType::NS()));
- if (foundNS != node.getData()->end()) {
-
-
- if (state->zonecut_node_ != NULL) {
- return (false);
- }
- LOG_DEBUG(logger, DBG_TRACE_DETAILED, DATASRC_MEM_NS_ENCOUNTERED);
-
-
-
-
-
-
- state->zonecut_node_ = &node;
- state->rrset_ = foundNS->second;
-
-
- return ((state->options_ & FIND_GLUE_OK) == 0);
- }
-
-
- assert(0);
-
-
-
- return (false);
- }
-
- static ConstRRsetPtr prepareRRset(const Name& name, const ConstRRsetPtr&
- rrset, bool rename)
- {
- if (rename) {
- LOG_DEBUG(logger, DBG_TRACE_DETAILED, DATASRC_MEM_RENAME).
- arg(rrset->getName()).arg(name);
-
- RRsetPtr result(new RRset(name, rrset->getClass(),
- rrset->getType(), rrset->getTTL()));
- for (RdataIteratorPtr i(rrset->getRdataIterator()); !i->isLast();
- i->next()) {
- result->addRdata(i->getCurrent());
- }
- return (result);
- } else {
- return (rrset);
- }
- }
-
- FindResult find(const Name& name, RRType type, const FindOptions options)
- const
- {
- LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_FIND).arg(name).
- arg(type);
-
- DomainNode* node(NULL);
- FindState state(options);
- RBTreeNodeChain<Domain> node_path;
- bool rename(false);
- switch (domains_.find(name, &node, node_path, cutCallback, &state)) {
- case DomainTree::PARTIALMATCH:
-
- if (state.dname_node_ != NULL) {
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DNAME_FOUND).
- arg(state.rrset_->getName());
-
-
- return (FindResult(DNAME, prepareRRset(name, state.rrset_,
- rename)));
- }
- if (state.zonecut_node_ != NULL) {
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DELEG_FOUND).
- arg(state.rrset_->getName());
- return (FindResult(DELEGATION, prepareRRset(name,
- state.rrset_, rename)));
- }
-
-
-
- if (node_path.getLastComparisonResult().getRelation() ==
- NameComparisonResult::SUPERDOMAIN) {
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_SUPER_STOP).
- arg(node_path.getAbsoluteName()).arg(name);
- return (FindResult(NXRRSET, ConstRRsetPtr()));
- }
-
- if (node->getFlag(DOMAINFLAG_WILD)) {
-
- if (node_path.getLastComparisonResult().getRelation() ==
- NameComparisonResult::COMMONANCESTOR && node_path.
- getLastComparisonResult().getCommonLabels() > 1) {
- LOG_DEBUG(logger, DBG_TRACE_DATA,
- DATASRC_MEM_WILDCARD_CANCEL).arg(name);
- return (FindResult(NXDOMAIN, ConstRRsetPtr()));
- }
- Name wildcard(Name("*").concatenate(
- node_path.getAbsoluteName()));
- DomainTree::Result result(domains_.find(wildcard, &node));
-
- assert(result == DomainTree::EXACTMATCH);
-
- rename = true;
- break;
- }
-
- case DomainTree::NOTFOUND:
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_NOT_FOUND).
- arg(name);
- return (FindResult(NXDOMAIN, ConstRRsetPtr()));
- case DomainTree::EXACTMATCH:
- break;
- default:
- assert(0);
- }
- assert(node != NULL);
-
-
- if (node->isEmpty()) {
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_DOMAIN_EMPTY).
- arg(name);
- return (FindResult(NXRRSET, ConstRRsetPtr()));
- }
- Domain::const_iterator found;
-
-
- if (node->getFlag(DomainNode::FLAG_CALLBACK) && node != origin_data_) {
- found = node->getData()->find(RRType::NS());
- if (found != node->getData()->end()) {
- LOG_DEBUG(logger, DBG_TRACE_DATA,
- DATASRC_MEM_EXACT_DELEGATION).arg(name);
- return (FindResult(DELEGATION, prepareRRset(name,
- found->second, rename)));
- }
- }
- #if 0
- TODO: Move this to some other place, new method
-
- if (target != NULL && !node->getData()->empty()) {
-
- for (found = node->getData()->begin();
- found != node->getData()->end(); ++found)
- {
- target->addRRset(
- boost::const_pointer_cast<RRset>(prepareRRset(name,
- found->second, rename)));
- }
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_ANY_SUCCESS).
- arg(name);
- return (FindResult(SUCCESS, ConstRRsetPtr()));
- }
- #endif
- found = node->getData()->find(type);
- if (found != node->getData()->end()) {
-
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_SUCCESS).arg(name).
- arg(type);
- return (FindResult(SUCCESS, prepareRRset(name, found->second,
- rename)));
- } else {
-
- found = node->getData()->find(RRType::CNAME());
- if (found != node->getData()->end()) {
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_CNAME).arg(name);
- return (FindResult(CNAME, prepareRRset(name, found->second,
- rename)));
- }
- }
-
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_NXRRSET).arg(type).
- arg(name);
- return (FindResult(NXRRSET, ConstRRsetPtr()));
- }
- };
- InMemoryZoneFinder::InMemoryZoneFinder(const RRClass& zone_class, const Name& origin) :
- impl_(new InMemoryZoneFinderImpl(zone_class, origin))
- {
- LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_CREATE).arg(origin).
- arg(zone_class);
- }
- InMemoryZoneFinder::~InMemoryZoneFinder() {
- LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_DESTROY).arg(getOrigin()).
- arg(getClass());
- delete impl_;
- }
- Name
- InMemoryZoneFinder::getOrigin() const {
- return (impl_->origin_);
- }
- RRClass
- InMemoryZoneFinder::getClass() const {
- return (impl_->zone_class_);
- }
- ZoneFinder::FindResult
- InMemoryZoneFinder::find(const Name& name, const RRType& type,
- const FindOptions options)
- {
- return (impl_->find(name, type, options));
- }
- result::Result
- InMemoryZoneFinder::add(const ConstRRsetPtr& rrset) {
- return (impl_->add(rrset, &impl_->domains_));
- }
- void
- InMemoryZoneFinder::load(const string& filename) {
- LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_LOAD).arg(getOrigin()).
- arg(filename);
-
- DomainTree tmp;
- masterLoad(filename.c_str(), getOrigin(), getClass(),
- boost::bind(&InMemoryZoneFinderImpl::addFromLoad, impl_, _1, &tmp));
-
- impl_->file_name_ = filename;
- tmp.swap(impl_->domains_);
-
- }
- void
- InMemoryZoneFinder::swap(InMemoryZoneFinder& zone_finder) {
- LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_SWAP).arg(getOrigin()).
- arg(zone_finder.getOrigin());
- std::swap(impl_, zone_finder.impl_);
- }
- const string
- InMemoryZoneFinder::getFileName() const {
- return (impl_->file_name_);
- }
- isc::dns::Name
- InMemoryZoneFinder::findPreviousName(const isc::dns::Name&) const {
- isc_throw(NotImplemented, "InMemory data source doesn't support DNSSEC "
- "yet, can't find previous name");
- }
- class InMemoryClient::InMemoryClientImpl {
- public:
- InMemoryClientImpl() : zone_count(0) {}
- unsigned int zone_count;
- ZoneTable zone_table;
- };
- InMemoryClient::InMemoryClient() : impl_(new InMemoryClientImpl)
- {}
- InMemoryClient::~InMemoryClient() {
- delete impl_;
- }
- unsigned int
- InMemoryClient::getZoneCount() const {
- return (impl_->zone_count);
- }
- result::Result
- InMemoryClient::addZone(ZoneFinderPtr zone_finder) {
- if (!zone_finder) {
- isc_throw(InvalidParameter,
- "Null pointer is passed to InMemoryClient::addZone()");
- }
- LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_MEM_ADD_ZONE).
- arg(zone_finder->getOrigin()).arg(zone_finder->getClass().toText());
- const result::Result result = impl_->zone_table.addZone(zone_finder);
- if (result == result::SUCCESS) {
- ++impl_->zone_count;
- }
- return (result);
- }
- InMemoryClient::FindResult
- InMemoryClient::findZone(const isc::dns::Name& name) const {
- LOG_DEBUG(logger, DBG_TRACE_DATA, DATASRC_MEM_FIND_ZONE).arg(name);
- ZoneTable::FindResult result(impl_->zone_table.findZone(name));
- return (FindResult(result.code, result.zone));
- }
- namespace {
- class MemoryIterator : public ZoneIterator {
- private:
- RBTreeNodeChain<Domain> chain_;
- Domain::const_iterator dom_iterator_;
- const DomainTree& tree_;
- const DomainNode* node_;
-
- RdataIteratorPtr rdata_iterator_;
- bool separate_rrs_;
- bool ready_;
- public:
- MemoryIterator(const DomainTree& tree, const Name& origin, bool separate_rrs) :
- tree_(tree),
- separate_rrs_(separate_rrs),
- ready_(true)
- {
-
-
- DomainTree::Result result(tree_.find<void*>(origin, &node_, chain_,
- NULL, NULL));
-
- if (result != DomainTree::EXACTMATCH) {
- isc_throw(Unexpected,
- "In-memory zone corrupted, missing origin node");
- }
-
- if (node_ != NULL && node_->getData() != DomainPtr()) {
- dom_iterator_ = node_->getData()->begin();
- if (separate_rrs_ && dom_iterator_ != node_->getData()->end()) {
- rdata_iterator_ = dom_iterator_->second->getRdataIterator();
- }
- }
- }
- virtual ConstRRsetPtr getNextRRset() {
- if (!ready_) {
- isc_throw(Unexpected, "Iterating past the zone end");
- }
-
- while (node_ != NULL && (node_->getData() == DomainPtr() ||
- dom_iterator_ == node_->getData()->end())) {
- node_ = tree_.nextNode(chain_);
-
-
- if (node_ != NULL && node_->getData() != NULL) {
- dom_iterator_ = node_->getData()->begin();
-
- if (separate_rrs_) {
- rdata_iterator_ = dom_iterator_->second->getRdataIterator();
- }
- }
- }
- if (node_ == NULL) {
-
- ready_ = false;
- return (ConstRRsetPtr());
- }
- if (separate_rrs_) {
-
-
- RRsetPtr result(new RRset(dom_iterator_->second->getName(),
- dom_iterator_->second->getClass(),
- dom_iterator_->second->getType(),
- dom_iterator_->second->getTTL()));
- result->addRdata(rdata_iterator_->getCurrent());
- rdata_iterator_->next();
- if (rdata_iterator_->isLast()) {
-
- ++dom_iterator_;
-
-
- if (dom_iterator_ != node_->getData()->end()) {
- rdata_iterator_ = dom_iterator_->second->getRdataIterator();
- }
- }
- return (result);
- } else {
-
- ConstRRsetPtr result(dom_iterator_->second);
-
- ++dom_iterator_;
- return (result);
- }
- }
- virtual ConstRRsetPtr getSOA() const {
- isc_throw(NotImplemented, "Not imelemented");
- }
- };
- }
- ZoneIteratorPtr
- InMemoryClient::getIterator(const Name& name, bool separate_rrs) const {
- ZoneTable::FindResult result(impl_->zone_table.findZone(name));
- if (result.code != result::SUCCESS) {
- isc_throw(DataSourceError, "No such zone: " + name.toText());
- }
- const InMemoryZoneFinder*
- zone(dynamic_cast<const InMemoryZoneFinder*>(result.zone.get()));
- if (zone == NULL) {
-
- isc_throw(Unexpected, "The zone at " + name.toText() +
- " is not InMemoryZoneFinder");
- }
- return (ZoneIteratorPtr(new MemoryIterator(zone->impl_->domains_, name,
- separate_rrs)));
- }
- ZoneUpdaterPtr
- InMemoryClient::getUpdater(const isc::dns::Name&, bool, bool) const {
- isc_throw(isc::NotImplemented, "Update attempt on in memory data source");
- }
- pair<ZoneJournalReader::Result, ZoneJournalReaderPtr>
- InMemoryClient::getJournalReader(const isc::dns::Name&, uint32_t,
- uint32_t) const
- {
- isc_throw(isc::NotImplemented, "Journaling isn't supported for "
- "in memory data source");
- }
- namespace {
- void
- addError(ElementPtr errors, const std::string& error) {
- if (errors != ElementPtr() && errors->getType() == Element::list) {
- errors->add(Element::create(error));
- }
- }
- bool
- checkConfigElementString(ConstElementPtr config, const std::string& name,
- ElementPtr errors)
- {
- if (!config->contains(name)) {
- addError(errors,
- "Config for memory backend does not contain a '"
- +name+
- "' value");
- return false;
- } else if (!config->get(name) ||
- config->get(name)->getType() != Element::string) {
- addError(errors, "value of " + name +
- " in memory backend config is not a string");
- return false;
- } else {
- return true;
- }
- }
- bool
- checkZoneConfig(ConstElementPtr config, ElementPtr errors) {
- bool result = true;
- if (!config || config->getType() != Element::map) {
- addError(errors, "Elements in memory backend's zone list must be maps");
- result = false;
- } else {
- if (!checkConfigElementString(config, "origin", errors)) {
- result = false;
- }
- if (!checkConfigElementString(config, "file", errors)) {
- result = false;
- }
-
-
- }
- return result;
- }
- bool
- checkConfig(ConstElementPtr config, ElementPtr errors) {
-
- bool result = true;
- if (!config || config->getType() != Element::map) {
- addError(errors, "Base config for memory backend must be a map");
- result = false;
- } else {
- if (!checkConfigElementString(config, "type", errors)) {
- result = false;
- } else {
- if (config->get("type")->stringValue() != "memory") {
- addError(errors,
- "Config for memory backend is not of type \"memory\"");
- result = false;
- }
- }
- if (!checkConfigElementString(config, "class", errors)) {
- result = false;
- } else {
- try {
- RRClass rrc(config->get("class")->stringValue());
- } catch (const isc::Exception& rrce) {
- addError(errors,
- "Error parsing class config for memory backend: " +
- std::string(rrce.what()));
- result = false;
- }
- }
- if (!config->contains("zones")) {
- addError(errors, "No 'zones' element in memory backend config");
- result = false;
- } else if (!config->get("zones") ||
- config->get("zones")->getType() != Element::list) {
- addError(errors, "'zones' element in memory backend config is not a list");
- result = false;
- } else {
- BOOST_FOREACH(ConstElementPtr zone_config,
- config->get("zones")->listValue()) {
- if (!checkZoneConfig(zone_config, errors)) {
- result = false;
- }
- }
- }
- }
- return (result);
- return true;
- }
- }
- DataSourceClient *
- createInstance(isc::data::ConstElementPtr config, std::string& error) {
- ElementPtr errors(Element::createList());
- if (!checkConfig(config, errors)) {
- error = "Configuration error: " + errors->str();
- return (NULL);
- }
- try {
- return (new InMemoryClient());
- } catch (const std::exception& exc) {
- error = std::string("Error creating memory datasource: ") + exc.what();
- return (NULL);
- } catch (...) {
- error = std::string("Error creating memory datasource, "
- "unknown exception");
- return (NULL);
- }
- }
- void destroyInstance(DataSourceClient* instance) {
- delete instance;
- }
- }
- }
|