// Check the pool parameters. It will throw an exception if any
// of the required parameters are not present or invalid.
- require_("prefix", pd_pool_);
- require_("prefix-len", pd_pool_);
- require_("delegated-len", pd_pool_);
+ requireParam("prefix", pd_pool_);
+ requireParam("prefix-len", pd_pool_);
+ requireParam("delegated-len", pd_pool_);
try {
// Attempt to construct the local pool.
pool_.reset(new Pool6(IOAddress(addr_str),
/// @param name Entry name
/// @param config Pools configuration
/// @throw isc::dhcp::DhcpConfigError if not present
- void require_(const std::string& name, ConstElementPtr config) const {
+ void requireParam(const std::string& name, ConstElementPtr config) const {
if (!config->contains(name)) {
isc_throw(isc::dhcp::DhcpConfigError,
"Missing parameter '" << name << "' ("
//**************************** D2ClientConfigParser **********************
-namespace {
-
-template <typename int_type> int_type
-getInt(const std::string& name, ConstElementPtr value) {
- int64_t val_int = value->intValue();
- if ((val_int < std::numeric_limits<int_type>::min()) ||
- (val_int > std::numeric_limits<int_type>::max())) {
- isc_throw(DhcpConfigError, "out of range value (" << val_int
- << ") specified for parameter '" << name
- << "' (" << value->getPosition() << ")");
- }
- return (static_cast<int_type>(val_int));
-}
-
uint32_t
-getUint32(const std::string& name, ConstElementPtr value) {
- return (getInt<uint32_t>(name, value));
+D2ClientConfigParser::getUint32(const std::string& name,
+ ConstElementPtr value) const {
+ return (extractInt<uint32_t, DhcpConfigError>(name, value));
}
+namespace {
+IOAddress buildIOAddress(const std::string& str) { return (IOAddress(str)); }
+};
+
IOAddress
-getIOAddress(const std::string& name, ConstElementPtr value) {
- std::string str = value->stringValue();
- try {
- return (IOAddress(str));
- } catch (const std::exception& ex) {
- isc_throw(DhcpConfigError, "invalid address (" << str
- << ") specified for parameter '" << name
- << "' (" << value->getPosition() << ")");
- }
+D2ClientConfigParser::getIOAddress(const std::string& name,
+ ConstElementPtr value) const {
+ return (extractConvert<IOAddress,
+ buildIOAddress,
+ DhcpConfigError>(name, "address", value));
}
dhcp_ddns::NameChangeProtocol
-getProtocol(const std::string& name, ConstElementPtr value) {
- std::string str = value->stringValue();
- try {
- return (dhcp_ddns::stringToNcrProtocol(str));
- } catch (const std::exception& ex) {
- isc_throw(DhcpConfigError,
- "invalid NameChangeRequest protocol (" << str
- << ") specified for parameter '" << name
- << "' (" << value->getPosition() << ")");
- }
+D2ClientConfigParser::getProtocol(const std::string& name,
+ ConstElementPtr value) const {
+ return (extractConvert<dhcp_ddns::NameChangeProtocol,
+ dhcp_ddns::stringToNcrProtocol,
+ DhcpConfigError>(name,
+ "NameChangeRequest protocol",
+ value));
}
dhcp_ddns::NameChangeFormat
-getFormat(const std::string& name, ConstElementPtr value) {
- std::string str = value->stringValue();
- try {
- return (dhcp_ddns::stringToNcrFormat(str));
- } catch (const std::exception& ex) {
- isc_throw(DhcpConfigError,
- "invalid NameChangeRequest format (" << str
- << ") specified for parameter '" << name
- << "' (" << value->getPosition() << ")");
- }
+D2ClientConfigParser::getFormat(const std::string& name,
+ ConstElementPtr value) const {
+ return (extractConvert<dhcp_ddns::NameChangeFormat,
+ dhcp_ddns::stringToNcrFormat,
+ DhcpConfigError>(name,
+ "NameChangeRequest format",
+ value));
}
D2ClientConfig::ReplaceClientNameMode
-getMode(const std::string& name, ConstElementPtr value) {
- std::string str = value->stringValue();
- try {
- return (D2ClientConfig::stringToReplaceClientNameMode(str));
- } catch (const std::exception& ex) {
- isc_throw(DhcpConfigError,
- "invalid ReplaceClientName mode (" << str
- << ") specified for parameter '" << name
- << "' (" << value->getPosition() << ")");
- }
+D2ClientConfigParser::getMode(const std::string& name,
+ ConstElementPtr value) const {
+ return (extractConvert<D2ClientConfig::ReplaceClientNameMode,
+ D2ClientConfig::stringToReplaceClientNameMode,
+ DhcpConfigError>(name,
+ "ReplaceClientName mode",
+ value));
}
-};
-
D2ClientConfigPtr
D2ClientConfigParser::parse(isc::data::ConstElementPtr client_config) {
D2ClientConfigPtr new_config;
// to ElementPtr)
/// @return number of parameters inserted
static size_t setAllDefaults(isc::data::ConstElementPtr d2_config);
+
+private:
+
+ /// @brief Returns a value converted to uint32_t
+ ///
+ /// Instantiation of extractInt() to uint32_t
+ ///
+ /// @param value value of the parameter
+ /// @return an uint32_t value
+ uint32_t
+ getUint32(const std::string& name, isc::data::ConstElementPtr value) const;
+
+ /// @brief Returns a value converted to IOAddress
+ ///
+ /// Instantiation of extractConvert() to IOAddress
+ ///
+ /// @param value value of the parameter
+ /// @return an IOAddress value
+ isc::asiolink::IOAddress
+ getIOAddress(const std::string& name,
+ isc::data::ConstElementPtr value) const;
+
+ /// @brief Returns a value converted to NameChangeProtocol
+ ///
+ /// Instantiation of extractInt() to NameChangeProtocol
+ ///
+ /// @param value value of the parameter
+ /// @return a NameChangeProtocol value
+ dhcp_ddns::NameChangeProtocol
+ getProtocol(const std::string& name,
+ isc::data::ConstElementPtr value) const;
+
+ /// @brief Returns a value converted to NameChangeFormat
+ ///
+ /// Instantiation of extractConvert() to NameChangeFormat
+ ///
+ /// @param value value of the parameter
+ /// @return a NameChangeFormat value
+ dhcp_ddns::NameChangeFormat
+ getFormat(const std::string& name,
+ isc::data::ConstElementPtr value) const;
+
+ /// @brief Returns a value converted to ReplaceClientNameMode
+ ///
+ /// Instantiation of extractConvert() to ReplaceClientNameMode
+ ///
+ /// @param value value of the parameter
+ /// @return a NameChangeFormat value
+ D2ClientConfig::ReplaceClientNameMode
+ getMode(const std::string& name,
+ isc::data::ConstElementPtr value) const;
};
// Pointers to various parser objects.