123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- using namespace std;
- using namespace isc::dns;
- namespace isc {
- namespace datasrc {
- // Private data and hidden methods of MemoryZone
- struct MemoryZone::MemoryZoneImpl {
- // Constructor
- MemoryZoneImpl(const RRClass& zone_class, const Name& origin) :
- zone_class_(zone_class), origin_(origin)
- {}
- // Information about the zone
- RRClass zone_class_;
- Name origin_;
-
-
- typedef map<RRType, ConstRRsetPtr> Domain;
- typedef Domain::value_type DomainPair;
- typedef boost::shared_ptr<Domain> DomainPtr;
-
- typedef RBTree<Domain> DomainTree;
- typedef RBNode<Domain> DomainNode;
-
- DomainTree domains_;
-
-
- result::Result add(const ConstRRsetPtr& rrset) {
-
- if (!rrset) {
- isc_throw(NullRRset, "The rrset provided is NULL");
- }
- Name name(rrset->getName());
- NameComparisonResult compare(origin_.compare(name));
- if (compare.getRelation() != NameComparisonResult::SUPERDOMAIN &&
- compare.getRelation() != NameComparisonResult::EQUAL)
- {
- isc_throw(OutOfZone, "The name " << name <<
- " is not contained in zone " << origin_);
- }
-
- DomainNode* node;
- switch (domains_.insert(name, &node)) {
-
- case DomainTree::SUCCEED:
- case DomainTree::ALREADYEXIST:
- break;
-
- default:
- assert(0);
- }
- assert(node);
-
- DomainPtr domain;
-
- if (node->isEmpty()) {
- domain.reset(new Domain);
- node->setData(domain);
- } else {
- domain = node->getData();
- }
-
- if (domain->insert(DomainPair(rrset->getType(), rrset)).second) {
-
- return (result::SUCCESS);
- } else {
-
- return (result::EXIST);
- }
- }
-
- FindResult find(const Name& name, RRType type) const {
-
- DomainNode* node;
- switch (domains_.find(name, &node)) {
- case DomainTree::PARTIALMATCH:
-
-
-
-
- case DomainTree::NOTFOUND:
- return (FindResult(NXDOMAIN, ConstRRsetPtr()));
- case DomainTree::EXACTMATCH:
- break;
- default:
- assert(0);
- }
- assert(node);
- assert(!node->isEmpty());
- Domain::const_iterator found(node->getData()->find(type));
- if (found != node->getData()->end()) {
-
- return (FindResult(SUCCESS, found->second));
- } else {
-
- return (FindResult(NXRRSET, ConstRRsetPtr()));
- }
- }
- };
- MemoryZone::MemoryZone(const RRClass& zone_class, const Name& origin) :
- impl_(new MemoryZoneImpl(zone_class, origin))
- {
- }
- MemoryZone::~MemoryZone() {
- delete impl_;
- }
- const Name&
- MemoryZone::getOrigin() const {
- return (impl_->origin_);
- }
- const RRClass&
- MemoryZone::getClass() const {
- return (impl_->zone_class_);
- }
- Zone::FindResult
- MemoryZone::find(const Name& name, const RRType& type) const {
- return (impl_->find(name, type));
- }
- result::Result
- MemoryZone::add(const ConstRRsetPtr& rrset) {
- return (impl_->add(rrset));
- }
- struct MemoryDataSrc::MemoryDataSrcImpl {
- ZoneTable zone_table;
- };
- MemoryDataSrc::MemoryDataSrc() : impl_(new MemoryDataSrcImpl)
- {}
- MemoryDataSrc::~MemoryDataSrc() {
- delete impl_;
- }
- result::Result
- MemoryDataSrc::addZone(ZonePtr zone) {
- if (!zone) {
- isc_throw(InvalidParameter,
- "Null pointer is passed to MemoryDataSrc::addZone()");
- }
- return (impl_->zone_table.addZone(zone));
- }
- MemoryDataSrc::FindResult
- MemoryDataSrc::findZone(const isc::dns::Name& name) const {
- return (FindResult(impl_->zone_table.findZone(name).code,
- impl_->zone_table.findZone(name).zone));
- }
- }
- }
|