]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2957] Made forward and reverse ddns elements optional, altered clone
authorThomas Markwalder <tmark@isc.org>
Mon, 1 Jul 2013 12:11:05 +0000 (08:11 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 1 Jul 2013 12:11:05 +0000 (08:11 -0400)
method to return smart pointer.

src/bin/d2/d2_cfg_mgr.h
src/bin/d2/d2_config.h
src/bin/d2/d_cfg_mgr.cc
src/bin/d2/d_cfg_mgr.h
src/bin/d2/dhcp-ddns.spec
src/bin/d2/tests/d_test_stubs.cc
src/bin/d2/tests/d_test_stubs.h

index 785c204b18bc1d0b86c8b644e1dc58cf80ddd792..dad1847e04906f72183590c51d65f73857d50c97 100644 (file)
 namespace isc {
 namespace d2 {
 
+class D2CfgContext;
+/// @brief Pointer to a configuration context.
+typedef boost::shared_ptr<D2CfgContext> D2CfgContextPtr;
+
 /// @brief  DHCP-DDNS Configuration Context
 ///
 /// Implements the storage container for configuration context.
@@ -44,9 +48,9 @@ public:
 
     /// @brief Creates a clone of this context object.
     ///
-    /// @return returns a raw pointer to the new clone.
-    virtual D2CfgContext* clone() {
-        return (new D2CfgContext(*this));
+    /// @return returns a pointer to the new clone.
+    virtual DCfgContextBasePtr clone() {
+        return (DCfgContextBasePtr(new D2CfgContext(*this)));
     }
 
     /// @brief Fetches the forward DNS domain list manager.
@@ -92,8 +96,6 @@ private:
 typedef boost::shared_ptr<DdnsDomainListMgr> DdnsDomainListMgrPtr;
 
 
-/// @brief Pointer to a configuration context.
-typedef boost::shared_ptr<D2CfgContext> D2CfgContextPtr;
 
 /// @brief DHCP-DDNS Configuration Manager
 ///
index f53d1e27a2862bd034cdc2ba7b3740c10163a427..6a00b5a619f2a15166aeda6bdc1d7e229af1ba21 100644 (file)
@@ -484,9 +484,9 @@ public:
 
     /// @brief Creates a clone of a DStubContext.
     ///
-    /// @return returns a raw pointer to the new clone.
-    virtual DScalarContext* clone() {
-        return (new DScalarContext(*this));
+    /// @return returns a pointer to the new clone.
+    virtual DCfgContextBasePtr clone() {
+        return (DCfgContextBasePtr(new DScalarContext(*this)));
     }
 
 protected:
@@ -499,6 +499,9 @@ private:
     DScalarContext& operator=(const DScalarContext& rhs);
 };
 
+/// @brief Defines a pointer for DScalarContext instances.
+typedef boost::shared_ptr<DScalarContext> DScalarContextPtr;
+
 /// @brief Parser for  TSIGKeyInfo
 ///
 /// This class parses the configuration element "tsig_key" defined in
index 6a3175dc725bb0b05d850fb7809e7c0ac4987952..a8394a98fe5bb701d40a1118d769df6993c87078 100644 (file)
@@ -122,7 +122,7 @@ DCfgMgrBase::parseConfig(isc::data::ConstElementPtr config_set) {
     // inconsistency if the parsing operation fails after the context has been
     // modified. We need to preserve the original context here
     // so as we can rollback changes when an error occurs.
-    DCfgContextBasePtr original_context(context_->clone());
+    DCfgContextBasePtr original_context = context_->clone();
 
     // Answer will hold the result returned to the caller.
     ConstElementPtr answer;
@@ -143,9 +143,11 @@ DCfgMgrBase::parseConfig(isc::data::ConstElementPtr config_set) {
         if (parse_order_.size() > 0) {
             // For each element_id in the parse order list, look for it in the
             // value map.  If the element exists in the map, pass it and it's
-            // associated data in for parsing.  
-            // If there is no matching entry in the value map an error is 
-            // thrown.  Optional elements may not be used with ordered parsing.
+            // associated data in for parsing.
+            // If there is no matching entry in the value map an error is
+            // thrown.  Note, that elements tagged as "optional" from the user
+            // perspective must still have default or empty entries in the
+            // configuration set to be parsed.
             int parsed_count = 0;
             std::map<std::string, ConstElementPtr>::const_iterator it;
             BOOST_FOREACH(element_id, parse_order_) {
@@ -157,7 +159,7 @@ DCfgMgrBase::parseConfig(isc::data::ConstElementPtr config_set) {
                 else {
                     LOG_ERROR(dctl_logger, DCTL_ORDER_NO_ELEMENT)
                               .arg(element_id);
-                    isc_throw(DCfgMgrBaseError, "Element:" << element_id <<  
+                    isc_throw(DCfgMgrBaseError, "Element:" << element_id <<
                               " is listed in the parse order but is not "
                               " present in the configuration");
                 }
@@ -172,10 +174,10 @@ DCfgMgrBase::parseConfig(isc::data::ConstElementPtr config_set) {
             // Better to hold the engineer accountable.  So, if we parsed none
             // or we parsed fewer than are in the map; then either the parse i
             // order is incomplete OR the map has unsupported values.
-            if (!parsed_count || 
+            if (!parsed_count ||
                 (parsed_count && ((parsed_count + 1) < values_map.size()))) {
                 LOG_ERROR(dctl_logger, DCTL_ORDER_ERROR);
-                isc_throw(DCfgMgrBaseError, 
+                isc_throw(DCfgMgrBaseError,
                         "Configuration contains elements not in parse order");
             }
         } else {
@@ -226,7 +228,7 @@ void DCfgMgrBase::buildAndCommit(std::string& element_id,
         // nothing something we are concerned with here.)
         parser->commit();
     } catch (const isc::Exception& ex) {
-        isc_throw(DCfgMgrBaseError, 
+        isc_throw(DCfgMgrBaseError,
                   "Could not build and commit: " << ex.what());
     } catch (...) {
         isc_throw(DCfgMgrBaseError, "Non-ISC exception occurred");
index a527fdbdd1d1124a4e9e73db5b8728248fdb70d3..a0bd9bb2675e41d75435aa3494fdfcff0e226f3e 100644 (file)
@@ -32,6 +32,10 @@ public:
         isc::Exception(file, line, what) { };
 };
 
+class DCfgContextBase;
+/// @brief Pointer to a configuration context.
+typedef boost::shared_ptr<DCfgContextBase> DCfgContextBasePtr;
+
 /// @brief Abstract class that implements a container for configuration context.
 /// It provides a single enclosure for the storage of configuration parameters
 /// and any other context specific information that needs to be accessible
@@ -141,8 +145,8 @@ public:
     /// public:
     ///  :
     ///     // Clone calls its own copy constructor
-    ///     virtual DStubContext* clone() {
-    ///         return (new DStubContext(*this));
+    ///     virtual DCfgContextBasePtr clone() {
+    ///         return (DCfgContextBasePtr(new DStubContext(*this)));
     ///     }
     ///
     ///     // Note that the copy constructor calls the base class copy ctor
@@ -156,8 +160,8 @@ public:
     ///  :
     /// @endcode
     ///
-    /// @return returns a raw pointer to the new clone.
-    virtual DCfgContextBase* clone() = 0;
+    /// @return returns a pointer to the new clone.
+    virtual DCfgContextBasePtr clone() = 0;
 
 protected:
     /// @brief Copy constructor for use by derivations in clone().
@@ -177,9 +181,6 @@ private:
     isc::dhcp::StringStoragePtr string_values_;
 };
 
-/// @brief Pointer to a configuration context.
-typedef boost::shared_ptr<DCfgContextBase> DCfgContextBasePtr;
-
 /// @brief Defines an unsorted, list of string Element IDs.
 typedef std::vector<std::string> ElementIdList;
 
index 8e75e05161eb97b4b1504dbcd3f1edacd2f7023f..e29bc88e76eb5debd3ec71b2b94e135da2d05248 100644 (file)
@@ -59,7 +59,7 @@
     {
         "item_name": "forward_ddns",
         "item_type": "map",
-        "item_optional": false,
+        "item_optional": true,
          "item_default": {},
          "map_item_spec": [ 
          {
     {
         "item_name": "reverse_ddns",
         "item_type": "map",
-        "item_optional": false,
+        "item_optional": true,
          "item_default": {},
          "map_item_spec": [ 
          { 
index 5d9077d3f2688312e94a985c12aa653e24005692..4e1cee688deb7b3fe792168ef381a5a926c5a218 100644 (file)
@@ -260,9 +260,9 @@ DStubContext::getExtraStorage() {
     return (extra_values_);
 }
 
-DStubContext*
+DCfgContextBasePtr
 DStubContext::clone() {
-    return (new DStubContext(*this));
+    return (DCfgContextBasePtr(new DStubContext(*this)));
 }
 
 DStubContext::DStubContext(const DStubContext& rhs): DCfgContextBase(rhs),
index ec23efea16d38bd5d92ddf549c39be6b3dea39b0..0f0084f9ed8bfecb0ad06a064f6362ba2cf8fca6 100644 (file)
@@ -521,8 +521,8 @@ public:
 
     /// @brief Creates a clone of a DStubContext.
     ///
-    /// @return returns a raw pointer to the new clone.
-    virtual DStubContext* clone();
+    /// @return returns a pointer to the new clone.
+    virtual DCfgContextBasePtr clone();
 
 protected:
     /// @brief Copy constructor
@@ -607,10 +607,11 @@ public:
         try  {
             config_set_ = isc::data::Element::fromJSON(json_text);
         } catch (...) {
-            // This is so we can diagnose parsing mistakes during test
-            // development.
-            std::cerr << "fromJSON failed to parse text" << json_text
+            #if 0
+            // Handy for diagnostics
+            std::cout << "fromJSON failed to parse text" << json_text
                       << std::endl;
+            #endif
             return (false);
         }
 
@@ -627,8 +628,8 @@ public:
         int rcode = 0;
         isc::data::ConstElementPtr comment;
         comment = isc::config::parseAnswer(rcode, answer_);
+        #if 0
         // Handy for diagnostics
-        #if 1
         if (rcode != 0) {
             std::cout << "checkAnswer rcode:" << rcode << " comment: "
                   << *comment << std::endl;