]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared getGlobalParameters
authorFrancis Dupont <fdupont@isc.org>
Mon, 11 Feb 2019 10:27:56 +0000 (11:27 +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 c9106e616fa0bba0852f2ea3d105a4bdbb919de1..ec16f6f971e2186039def143187d4d70b7f2d244 100644 (file)
@@ -131,51 +131,6 @@ public:
     explicit MySqlConfigBackendDHCPv4Impl(const DatabaseConnection::ParameterMap&
                                           parameters);
 
-    /// @brief Sends query to retrieve multiple global parameters.
-    ///
-    /// @param index Index of the query to be used.
-    /// @param in_bindings Input bindings specifying selection criteria. The
-    /// size of the bindings collection must match the number of placeholders
-    /// in the prepared statement. The input bindings collection must be empty
-    /// if the query contains no WHERE clause.
-    /// @param [out] subnets Reference to the container where fetched parameters
-    /// will be inserted.
-    void getGlobalParameters4(const StatementIndex& index,
-                              const MySqlBindingCollection& in_bindings,
-                              StampedValueCollection& parameters) {
-        // The following parameters from the dhcp4_global_parameter table are
-        // returned:
-        // - id
-        // - name - parameter name
-        // - value - parameter value
-        // - modification_ts - modification timestamp.
-        MySqlBindingCollection out_bindings = {
-            MySqlBinding::createInteger<uint64_t>(), // id
-            MySqlBinding::createString(GLOBAL_PARAMETER_NAME_BUF_LENGTH), // name
-            MySqlBinding::createString(GLOBAL_PARAMETER_VALUE_BUF_LENGTH), // value
-            MySqlBinding::createInteger<uint8_t>(), // parameter_type
-            MySqlBinding::createTimestamp() // modification_ts
-        };
-
-        conn_.selectQuery(index, in_bindings, out_bindings,
-                          [&parameters]
-                          (MySqlBindingCollection& out_bindings) {
-            if (!out_bindings[1]->getString().empty()) {
-
-                // Convert value read as string from the database to the actual
-                // data type known from the database as binding #3.
-                StampedValuePtr stamped_value =
-                    StampedValue::create(out_bindings[1]->getString(),
-                                         out_bindings[2]->getString(),
-                                         static_cast<Element::types>
-                                         (out_bindings[3]->getInteger<uint8_t>()));
-
-                stamped_value->setModificationTime(out_bindings[4]->getTimestamp());
-                parameters.insert(stamped_value);
-            }
-        });
-    }
-
     /// @brief Sends query to retrieve global parameter.
     ///
     /// @param server_selector Server selector.
@@ -194,7 +149,7 @@ public:
                 MySqlBinding::createString(name)
             };
 
-            getGlobalParameters4(GET_GLOBAL_PARAMETER4, in_bindings, parameters);
+            getGlobalParameters(GET_GLOBAL_PARAMETER4, in_bindings, parameters);
         }
 
         return (parameters.empty() ? StampedValuePtr() : *parameters.begin());
@@ -2611,8 +2566,8 @@ MySqlConfigBackendDHCPv4::getAllGlobalParameters4(const ServerSelector& server_s
     auto tags = impl_->getServerTags(server_selector);
     for (auto tag : tags) {
         MySqlBindingCollection in_bindings = { MySqlBinding::createString(tag) };
-        impl_->getGlobalParameters4(MySqlConfigBackendDHCPv4Impl::GET_ALL_GLOBAL_PARAMETERS4,
-                                    in_bindings, parameters);
+        impl_->getGlobalParameters(MySqlConfigBackendDHCPv4Impl::GET_ALL_GLOBAL_PARAMETERS4,
+                                   in_bindings, parameters);
     }
     return (parameters);
 }
@@ -2629,8 +2584,8 @@ getModifiedGlobalParameters4(const db::ServerSelector& server_selector,
             MySqlBinding::createString(tag),
             MySqlBinding::createTimestamp(modification_time)
         };
-        impl_->getGlobalParameters4(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_GLOBAL_PARAMETERS4,
-                                    in_bindings, parameters);
+        impl_->getGlobalParameters(MySqlConfigBackendDHCPv4Impl::GET_MODIFIED_GLOBAL_PARAMETERS4,
+                                   in_bindings, parameters);
     }
 
     return (parameters);
index 1ddd5e211a9f7adf239403f4d93dd73fe6eb8870..8017f5a31fa80ef00e8e252616f187ed01a921ad 100644 (file)
@@ -189,6 +189,42 @@ MySqlConfigBackendImpl::deleteFromTable(const int index,
     return (deleteFromTable(index, server_selector, operation, in_bindings));
 }
 
+void
+MySqlConfigBackendImpl::getGlobalParameters(const int index,
+                                            const MySqlBindingCollection& in_bindings,
+                                            StampedValueCollection& parameters) {
+    // The following parameters from the dhcp[46]_global_parameter table are
+    // returned:
+    // - id
+    // - name - parameter name
+    // - value - parameter value
+    // - modification_ts - modification timestamp.
+    MySqlBindingCollection out_bindings = {
+        MySqlBinding::createInteger<uint64_t>(), // id
+        MySqlBinding::createString(GLOBAL_PARAMETER_NAME_BUF_LENGTH), // name
+        MySqlBinding::createString(GLOBAL_PARAMETER_VALUE_BUF_LENGTH), // value
+        MySqlBinding::createInteger<uint8_t>(), // parameter_type
+        MySqlBinding::createTimestamp() // modification_ts
+    };
+
+    conn_.selectQuery(index, in_bindings, out_bindings,
+                      [&parameters] (MySqlBindingCollection& out_bindings) {
+        if (!out_bindings[1]->getString().empty()) {
+
+            // Convert value read as string from the database to the actual
+            // data type known from the database as binding #3.
+            StampedValuePtr stamped_value =
+                StampedValue::create(out_bindings[1]->getString(),
+                                     out_bindings[2]->getString(),
+                                     static_cast<Element::types>
+                                     (out_bindings[3]->getInteger<uint8_t>()));
+
+            stamped_value->setModificationTime(out_bindings[4]->getTimestamp());
+            parameters.insert(stamped_value);
+        }
+    });
+}
+
 void
 MySqlConfigBackendImpl::getOptionDefs(const int index,
                                       const MySqlBindingCollection& in_bindings,
index 4650d69039455570bdb7094552fa2a7ade488fd1..9e081426cfd5179dcadcb19bcf7ab0186443ab89 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef MYSQL_CONFIG_BACKEND_IMPL_H
 #define MYSQL_CONFIG_BACKEND_IMPL_H
 
+#include <cc/stamped_value.h>
 #include <database/audit_entry.h>
 #include <database/database_connection.h>
 #include <database/server_selector.h>
@@ -296,6 +297,19 @@ public:
         return (deleteFromTable(index, server_selector, operation, in_bindings));
     }
 
+    /// @brief Sends query to retrieve multiple global parameters.
+    ///
+    /// @param index Index of the query to be used.
+    /// @param in_bindings Input bindings specifying selection criteria. The
+    /// size of the bindings collection must match the number of placeholders
+    /// in the prepared statement. The input bindings collection must be empty
+    /// if the query contains no WHERE clause.
+    /// @param [out] subnets Reference to the container where fetched parameters
+    /// will be inserted.
+    void getGlobalParameters(const int index,
+                             const db::MySqlBindingCollection& in_bindings,
+                             data::StampedValueCollection& parameters);
+
     /// @brief Sends query to the database to retrieve multiple option
     /// definitions.
     ///