Browse Source

[2421] Add zone exceptions hierarchy

Mukund Sivaraman 12 years ago
parent
commit
6c30834cb7

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

@@ -26,6 +26,7 @@ lib_LTLIBRARIES = libb10-datasrc.la
 libb10_datasrc_la_SOURCES = data_source.h
 libb10_datasrc_la_SOURCES += rbnode_rrset.h
 libb10_datasrc_la_SOURCES += rbtree.h
+libb10_datasrc_la_SOURCES += exceptions.h
 libb10_datasrc_la_SOURCES += zonetable.h zonetable.cc
 libb10_datasrc_la_SOURCES += zone.h zone_finder.cc zone_finder_context.cc
 libb10_datasrc_la_SOURCES += result.h

+ 47 - 0
src/lib/datasrc/exceptions.h

@@ -0,0 +1,47 @@
+// Copyright (C) 2012  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 DATASRC_EXCEPTIONS_H
+#define DATASRC_EXCEPTIONS_H 1
+
+#include <exceptions/exceptions.h>
+
+namespace isc {
+namespace datasrc {
+
+/// Base class for a number of exceptions that are thrown while working
+/// with zones.
+struct ZoneException : public Exception {
+    ZoneException(const char* file, size_t line, const char* what) :
+        Exception(file, line, what)
+    {}
+};
+
+/// Base class for a number of exceptions that are thrown when zones are
+/// being loaded. This is a recoverable exception. It should be possible
+/// to skip the bad zone and continue loading/serving other zones.
+struct ZoneValidationException : public ZoneException {
+    ZoneValidationException(const char* file, size_t line, const char* what) :
+        ZoneException(file, line, what)
+    {}
+};
+
+} // namespace datasrc
+} // namespace isc
+
+#endif // DATASRC_EXCEPTIONS
+
+// Local Variables:
+// mode: c++
+// End:

+ 3 - 2
src/lib/datasrc/memory/zone_data_loader.h

@@ -15,6 +15,7 @@
 #ifndef DATASRC_ZONE_DATA_LOADER_H
 #define DATASRC_ZONE_DATA_LOADER_H 1
 
+#include <datasrc/exceptions.h>
 #include <datasrc/memory/zone_data.h>
 #include <datasrc/iterator.h>
 #include <dns/name.h>
@@ -29,9 +30,9 @@ namespace memory {
 ///
 /// This is thrown if an empty zone would be created during
 /// \c loadZoneData().
-struct EmptyZone : public InvalidParameter {
+struct EmptyZone : public ZoneValidationException {
     EmptyZone(const char* file, size_t line, const char* what) :
-        InvalidParameter(file, line, what)
+        ZoneValidationException(file, line, what)
     {}
 };
 

+ 3 - 7
src/lib/datasrc/memory/zone_data_updater.h

@@ -15,6 +15,7 @@
 #ifndef DATASRC_ZONE_DATA_UPDATER_H
 #define DATASRC_ZONE_DATA_UPDATER_H 1
 
+#include <datasrc/exceptions.h>
 #include <datasrc/memory/zone_data.h>
 #include <datasrc/memory/rdata_serialization.h>
 #include <dns/name.h>
@@ -94,14 +95,9 @@ public:
     ///
     /// This is thrown against general error cases in adding an RRset
     /// to the zone.
-    ///
-    /// Note: this exception would cover cases for \c OutOfZone or
-    /// \c NullRRset.  We'll need to clarify and unify the granularity
-    /// of exceptions eventually.  For now, exceptions are added as
-    /// developers see the need for it.
-    struct AddError : public InvalidParameter {
+    struct AddError : public ZoneValidationException {
         AddError(const char* file, size_t line, const char* what) :
-            InvalidParameter(file, line, what)
+            ZoneValidationException(file, line, what)
         {}
     };
 

+ 3 - 2
src/lib/datasrc/zone.h

@@ -19,6 +19,7 @@
 #include <dns/rrset.h>
 #include <dns/rrtype.h>
 
+#include <datasrc/exceptions.h>
 #include <datasrc/result.h>
 
 #include <utility>
@@ -31,10 +32,10 @@ namespace datasrc {
 ///
 /// This is thrown when a method is called for a name or RRset which
 /// is not in or below the zone.
-class OutOfZone : public Exception {
+class OutOfZone : public ZoneException {
 public:
     OutOfZone(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
+        ZoneException(file, line, what) {}
 };
 
 /// \brief The base class to search a zone for RRsets