]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared get*OptionDef[s]
authorFrancis Dupont <fdupont@isc.org>
Mon, 11 Feb 2019 12:00:32 +0000 (13:00 +0100)
committerFrancis Dupont <fdupont@isc.org>
Fri, 22 Feb 2019 22:59:25 +0000 (17:59 -0500)
src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc
src/hooks/dhcp/mysql_cb/mysql_cb_impl.h

index ec16f6f971e2186039def143187d4d70b7f2d244..0a35a9d354f2d0c8578e01f3a834a37d6915784b 100644 (file)
@@ -1546,22 +1546,7 @@ public:
     OptionDefinitionPtr getOptionDef4(const ServerSelector& server_selector,
                                       const uint16_t code,
                                       const std::string& space) {
-
-        if (server_selector.amUnassigned()) {
-            isc_throw(NotImplemented, "managing configuration for no particular server"
-                      " (unassigned) is unsupported at the moment");
-        }
-
-        auto tag = getServerTag(server_selector, "fetching option definition");
-
-        OptionDefContainer option_defs;
-        MySqlBindingCollection in_bindings = {
-            MySqlBinding::createString(tag),
-            MySqlBinding::createInteger<uint8_t>(static_cast<uint8_t>(code)),
-            MySqlBinding::createString(space)
-        };
-        getOptionDefs(GET_OPTION_DEF4_CODE_SPACE, in_bindings, option_defs);
-        return (option_defs.empty() ? OptionDefinitionPtr() : *option_defs.begin());
+        return (getOptionDef(GET_OPTION_DEF4_CODE_SPACE, server_selector, code, space));
     }
 
     /// @brief Sends query to retrieve all option definitions.
@@ -1572,14 +1557,8 @@ public:
     void
     getAllOptionDefs4(const ServerSelector& server_selector,
                       OptionDefContainer& option_defs) {
-        auto tags = getServerTags(server_selector);
-        for (auto tag : tags) {
-            MySqlBindingCollection in_bindings = {
-                MySqlBinding::createString(tag)
-            };
-            getOptionDefs(MySqlConfigBackendDHCPv4Impl::GET_ALL_OPTION_DEFS4,
-                          in_bindings, option_defs);
-        }
+        getAllOptionDefs(MySqlConfigBackendDHCPv4Impl::GET_ALL_OPTION_DEFS4,
+                         server_selector, option_defs);
     }
 
     /// @brief Sends query to retrieve option definitions with modification
@@ -1593,15 +1572,8 @@ public:
     getModifiedOptionDefs4(const ServerSelector& server_selector,
                            const boost::posix_time::ptime& modification_time,
                            OptionDefContainer& option_defs) {
-        auto tags = getServerTags(server_selector);
-        for (auto tag : tags) {
-            MySqlBindingCollection in_bindings = {
-                MySqlBinding::createString(tag),
-                MySqlBinding::createTimestamp(modification_time)
-            };
-            getOptionDefs(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_OPTION_DEFS4,
-                          in_bindings, option_defs);
-        }
+        getModifiedOptionDefs(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_OPTION_DEFS4,
+                              server_selector, modification_time, option_defs);
     }
 
     /// @brief Sends query to retrieve single global option by code and
index 8017f5a31fa80ef00e8e252616f187ed01a921ad..9f3b4aa23cd5bd5509c39d6233531d417b95b0d4 100644 (file)
@@ -225,6 +225,57 @@ MySqlConfigBackendImpl::getGlobalParameters(const int index,
     });
 }
 
+OptionDefinitionPtr
+MySqlConfigBackendImpl::getOptionDef(const int index,
+                                     const ServerSelector& server_selector,
+                                     const uint16_t code,
+                                     const std::string& space) {
+
+    if (server_selector.amUnassigned()) {
+        isc_throw(NotImplemented, "managing configuration for no particular server"
+                  " (unassigned) is unsupported at the moment");
+    }
+
+    auto tag = getServerTag(server_selector, "fetching option definition");
+
+    OptionDefContainer option_defs;
+    MySqlBindingCollection in_bindings = {
+        MySqlBinding::createString(tag),
+        MySqlBinding::createInteger<uint16_t>(code),
+        MySqlBinding::createString(space)
+    };
+    getOptionDefs(index, in_bindings, option_defs);
+    return (option_defs.empty() ? OptionDefinitionPtr() : *option_defs.begin());
+}
+
+void
+MySqlConfigBackendImpl::getAllOptionDefs(const int index,
+                     const ServerSelector& server_selector,
+                     OptionDefContainer& option_defs) {
+    auto tags = getServerTags(server_selector);
+    for (auto tag : tags) {
+        MySqlBindingCollection in_bindings = {
+            MySqlBinding::createString(tag)
+        };
+        getOptionDefs(index, in_bindings, option_defs);
+    }
+}
+
+void
+MySqlConfigBackendImpl::getModifiedOptionDefs(const int index,
+                                              const ServerSelector& server_selector,
+                                              const boost::posix_time::ptime& modification_time,
+                                              OptionDefContainer& option_defs) {
+    auto tags = getServerTags(server_selector);
+    for (auto tag : tags) {
+        MySqlBindingCollection in_bindings = {
+            MySqlBinding::createString(tag),
+            MySqlBinding::createTimestamp(modification_time)
+        };
+        getOptionDefs(index, in_bindings, option_defs);
+    }
+}
+
 void
 MySqlConfigBackendImpl::getOptionDefs(const int index,
                                       const MySqlBindingCollection& in_bindings,
index 9e081426cfd5179dcadcb19bcf7ab0186443ab89..c97868dc7809cf68e9b79deb93c905f7a456ae63 100644 (file)
@@ -310,6 +310,44 @@ public:
                              const db::MySqlBindingCollection& in_bindings,
                              data::StampedValueCollection& parameters);
 
+    /// @brief Sends query to retrieve single option definition by code and
+    /// option space.
+    ///
+    /// @param index Index of the query to be used.
+    /// @param server_selector Server selector.
+    /// @param code Option code.
+    /// @param space Option space name.
+    ///
+    /// @return Pointer to the returned option definition or NULL if such
+    /// option definition doesn't exist.
+    OptionDefinitionPtr getOptionDef(const int index,
+                                     const db::ServerSelector& server_selector,
+                                     const uint16_t code,
+                                     const std::string& space);
+
+    /// @brief Sends query to retrieve all option definitions.
+    ///
+    /// @param index Index of the query to be used.
+    /// @param server_selector Server selector.
+    /// @param [out] option_defs Reference to the container where option
+    /// definitions are to be stored.
+    void getAllOptionDefs(const int index,
+                          const db::ServerSelector& server_selector,
+                          OptionDefContainer& option_defs);
+
+    /// @brief Sends query to retrieve option definitions with modification
+    /// time later than specified timestamp.
+    ///
+    /// @param index Index of the query to be used.
+    /// @param server_selector Server selector.
+    /// @param modification_time Lower bound subnet modification time.
+    /// @param [out] option_defs Reference to the container where option
+    /// definitions are to be stored.
+    void getModifiedOptionDefs(const int index,
+                               const db::ServerSelector& server_selector,
+                               const boost::posix_time::ptime& modification_time,
+                               OptionDefContainer& option_defs);
+
     /// @brief Sends query to the database to retrieve multiple option
     /// definitions.
     ///