From: Francis Dupont Date: Mon, 11 Feb 2019 12:00:32 +0000 (+0100) Subject: [94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared get*OptionDef[s] X-Git-Tag: 397-cb-implement-mysqlconfigbackenddhcpv6_base~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b0443a790f03242f58970848a068cb714211c41;p=thirdparty%2Fkea.git [94-cb-implement-mysqlconfigbackenddhcpv6-prepare] Shared get*OptionDef[s] --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index ec16f6f971..0a35a9d354 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -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(static_cast(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 diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 8017f5a31f..9f3b4aa23c 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -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(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, diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h index 9e081426cf..c97868dc78 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.h @@ -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. ///