Browse Source

[2435] Introduce an abstract datasrc::RRsetCollectionBase class

Mukund Sivaraman 12 years ago
parent
commit
f2f653c6f2

+ 1 - 0
src/lib/datasrc/Makefile.am

@@ -38,6 +38,7 @@ libb10_datasrc_la_SOURCES += client_list.h client_list.cc
 libb10_datasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc
 libb10_datasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc
 libb10_datasrc_la_SOURCES += master_loader_callbacks.h
 libb10_datasrc_la_SOURCES += master_loader_callbacks.h
 libb10_datasrc_la_SOURCES += master_loader_callbacks.cc
 libb10_datasrc_la_SOURCES += master_loader_callbacks.cc
+libb10_datasrc_la_SOURCES += rrset_collection_base.h rrset_collection_base.cc
 libb10_datasrc_la_SOURCES += zone_loader.h zone_loader.cc
 libb10_datasrc_la_SOURCES += zone_loader.h zone_loader.cc
 nodist_libb10_datasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc
 nodist_libb10_datasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc
 libb10_datasrc_la_LDFLAGS = -no-undefined -version-info 1:0:1
 libb10_datasrc_la_LDFLAGS = -no-undefined -version-info 1:0:1

+ 4 - 66
src/lib/datasrc/database.cc

@@ -19,6 +19,7 @@
 #include <datasrc/database.h>
 #include <datasrc/database.h>
 #include <datasrc/data_source.h>
 #include <datasrc/data_source.h>
 #include <datasrc/iterator.h>
 #include <datasrc/iterator.h>
+#include <datasrc/rrset_collection_base.h>
 
 
 #include <exceptions/exceptions.h>
 #include <exceptions/exceptions.h>
 #include <dns/name.h>
 #include <dns/name.h>
@@ -1373,79 +1374,16 @@ DatabaseClient::getIterator(const isc::dns::Name& name,
 }
 }
 
 
 /// \brief datasrc implementation of RRsetCollectionBase.
 /// \brief datasrc implementation of RRsetCollectionBase.
-class RRsetCollection : public isc::dns::RRsetCollectionBase {
+class RRsetCollection : public isc::datasrc::RRsetCollectionBase {
 public:
 public:
     /// \brief Constructor.
     /// \brief Constructor.
-    ///
-    /// No reference (count via \c shared_ptr) to the \c ZoneUpdater is
-    /// acquired. The RRsetCollection must not be used after its
-    /// \c ZoneUpdater has been destroyed.
-    ///
-    /// \param updater The ZoneUpdater to wrap around.
-    /// \param rrclass The RRClass of the records in the zone.
     RRsetCollection(ZoneUpdater& updater, const isc::dns::RRClass& rrclass) :
     RRsetCollection(ZoneUpdater& updater, const isc::dns::RRClass& rrclass) :
-        updater_(updater),
-        rrclass_(rrclass)
+        isc::datasrc::RRsetCollectionBase(updater, rrclass)
     {}
     {}
 
 
     /// \brief Destructor
     /// \brief Destructor
     virtual ~RRsetCollection() {}
     virtual ~RRsetCollection() {}
 
 
-    /// \brief Find a matching RRset in the collection.
-    ///
-    /// Returns the RRset in the collection that exactly matches the
-    /// given \c name, \c rrclass and \c rrtype.  If no matching RRset
-    /// is found, \c NULL is returned.
-    ///
-    /// \throw isc::dns::RRsetCollectionError if find() results in some
-    /// underlying datasrc error.
-    /// \param name The name of the RRset to search for.
-    /// \param rrclass The class of the RRset to search for.
-    /// \param rrtype The type of the RRset to search for.
-    /// \returns The RRset if found, \c NULL otherwise.
-    virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name& name,
-                                         const isc::dns::RRClass& rrclass,
-                                         const isc::dns::RRType& rrtype) const {
-        if (rrclass != rrclass_) {
-            // We could throw an exception here, but RRsetCollection is
-            // expected to support an arbitrary collection of RRsets,
-            // and it can be queried just as arbitrarily. So we just
-            // return nothing here.
-            return (ConstRRsetPtr());
-        }
-
-        ZoneFinder& finder = updater_.getFinder();
-        try {
-            ZoneFinderContextPtr result =
-                finder.find(name, rrtype,
-                            ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
-            // We return the result rrset only if the result code is
-            // SUCCESS. We return empty if CNAME, DNAME, DELEGATION,
-            // etc. are returned by the ZoneFinder.
-            //
-            // Note that in the case that the queried type itself is
-            // CNAME or DNAME, then the finder will return SUCCESS.
-            if (result->code == ZoneFinder::SUCCESS) {
-                return (result->rrset);
-            } else {
-                return (ConstRRsetPtr());
-            }
-        } catch (const OutOfZone&) {
-            // As RRsetCollection is an arbitrary set of RRsets, in case
-            // the searched name is out of zone, we return nothing
-            // instead of propagating the exception.
-            return (ConstRRsetPtr());
-        } catch (const DataSourceError& e) {
-            isc_throw(RRsetCollectionError,
-                      "ZoneFinder threw a DataSourceError: "
-                          << e.getMessage().c_str());
-        }
-    }
-
-private:
-    ZoneUpdater& updater_;
-    isc::dns::RRClass rrclass_;
-
 protected:
 protected:
     // TODO: RRsetCollectionBase::Iter is not implemented and the
     // TODO: RRsetCollectionBase::Iter is not implemented and the
     // following two methods just throw.
     // following two methods just throw.
@@ -1498,7 +1436,7 @@ public:
 
 
     virtual ZoneFinder& getFinder() { return (*finder_); }
     virtual ZoneFinder& getFinder() { return (*finder_); }
 
 
-    virtual RRsetCollectionBase& getRRsetCollection() {
+    virtual isc::dns::RRsetCollectionBase& getRRsetCollection() {
         if (!rrset_collection_) {
         if (!rrset_collection_) {
             // This is only assigned the first time and remains for the
             // This is only assigned the first time and remains for the
             // lifetime of the DatabaseUpdater.
             // lifetime of the DatabaseUpdater.

+ 67 - 0
src/lib/datasrc/rrset_collection_base.cc

@@ -0,0 +1,67 @@
+// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <datasrc/rrset_collection_base.h>
+#include <datasrc/zone_loader.h>
+#include <exceptions/exceptions.h>
+
+using namespace isc;
+using namespace isc::dns;
+
+namespace isc {
+namespace datasrc {
+
+ConstRRsetPtr
+isc::datasrc::RRsetCollectionBase::find(const isc::dns::Name& name,
+                                        const isc::dns::RRClass& rrclass,
+                                        const isc::dns::RRType& rrtype) const
+{
+    if (rrclass != rrclass_) {
+        // We could throw an exception here, but RRsetCollection is
+        // expected to support an arbitrary collection of RRsets, and it
+        // can be queried just as arbitrarily. So we just return nothing
+        // here.
+        return (ConstRRsetPtr());
+    }
+
+    ZoneFinder& finder = updater_.getFinder();
+    try {
+        ZoneFinderContextPtr result =
+            finder.find(name, rrtype,
+                        ZoneFinder::NO_WILDCARD | ZoneFinder::FIND_GLUE_OK);
+        // We return the result rrset only if the result code is
+        // SUCCESS. We return empty if CNAME, DNAME, DELEGATION,
+        // etc. are returned by the ZoneFinder.
+        //
+        // Note that in the case that the queried type itself is CNAME
+        // or DNAME, then the finder will return SUCCESS.
+        if (result->code == ZoneFinder::SUCCESS) {
+            return (result->rrset);
+        } else {
+            return (ConstRRsetPtr());
+        }
+    } catch (const OutOfZone&) {
+        // As RRsetCollection is an arbitrary set of RRsets, in case the
+        // searched name is out of zone, we return nothing instead of
+        // propagating the exception.
+        return (ConstRRsetPtr());
+    } catch (const DataSourceError& e) {
+        isc_throw(RRsetCollectionError,
+                  "ZoneFinder threw a DataSourceError: "
+                      << e.getMessage().c_str());
+    }
+}
+
+} // end of namespace datasrc
+} // end of namespace isc

+ 77 - 0
src/lib/datasrc/rrset_collection_base.h

@@ -0,0 +1,77 @@
+// Copyright (C) 2013  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef RRSET_COLLECTION_DATASRC_H
+#define RRSET_COLLECTION_DATASRC_H 1
+
+#include <dns/rrset_collection_base.h>
+#include <dns/rrclass.h>
+#include <datasrc/zone.h>
+
+namespace isc {
+namespace datasrc {
+
+/// \brief datasrc derivation of \c isc::dns::RRsetCollectionBase.
+///
+/// This is an abstract class that adds datasrc related detail to
+/// \c isc::dns::RRsetCollectionBase. Derived classes need to complete
+/// the implementation (add iterator support, etc.) before using it.
+class RRsetCollectionBase : public isc::dns::RRsetCollectionBase {
+public:
+    /// \brief Constructor.
+    ///
+    /// No reference (count via \c shared_ptr) to the \c ZoneUpdater is
+    /// acquired. The RRsetCollection must not be used after its
+    /// \c ZoneUpdater has been destroyed.
+    ///
+    /// \param updater The ZoneUpdater to wrap around.
+    /// \param rrclass The RRClass of the records in the zone.
+    RRsetCollectionBase(ZoneUpdater& updater,
+                        const isc::dns::RRClass& rrclass) :
+        updater_(updater),
+        rrclass_(rrclass)
+    {}
+
+    /// \brief Destructor
+    virtual ~RRsetCollectionBase() {}
+
+    /// \brief Find a matching RRset in the collection.
+    ///
+    /// Returns the RRset in the collection that exactly matches the
+    /// given \c name, \c rrclass and \c rrtype.  If no matching RRset
+    /// is found, \c NULL is returned.
+    ///
+    /// \throw isc::dns::RRsetCollectionError if find() results in some
+    /// underlying datasrc error.
+    /// \param name The name of the RRset to search for.
+    /// \param rrclass The class of the RRset to search for.
+    /// \param rrtype The type of the RRset to search for.
+    /// \returns The RRset if found, \c NULL otherwise.
+    virtual isc::dns::ConstRRsetPtr find(const isc::dns::Name& name,
+                                         const isc::dns::RRClass& rrclass,
+                                         const isc::dns::RRType& rrtype) const;
+
+private:
+    ZoneUpdater& updater_;
+    isc::dns::RRClass rrclass_;
+};
+
+} // end of namespace datasrc
+} // end of namespace isc
+
+#endif  // RRSET_COLLECTION_DATASRC_H
+
+// Local Variables:
+// mode: c++
+// End: