: family_(family) {
};
+// Can't use a constructor as a function
+namespace {
+IOAddress buildIOAddress(const std::string& str) { return (IOAddress(str)); }
+};
+
+IOAddress
+RelayInfoParser::getIOAddress(ConstElementPtr scope,
+ const std::string& name) {
+ return (getAndConvert<IOAddress,
+ buildIOAddress>(scope, name, "address"));
+}
+
void
RelayInfoParser::parse(const isc::dhcp::Subnet::RelayInfoPtr& cfg,
ConstElementPtr relay_info) {
- // Let's start with some sanity checks.
- if (!relay_info || !cfg) {
- isc_throw(DhcpConfigError, "Logic error: RelayInfoParser::parse() called "
- "with at least one NULL parameter.");
- }
-
- if (relay_info->getType() != Element::map) {
- isc_throw(DhcpConfigError, "Configuration error: RelayInfoParser::parse() "
- "called with non-map parameter");
- }
-
- // Now create the default value.
- isc::asiolink::IOAddress ip(family_ == Option::V4 ? IOAddress::IPV4_ZERO_ADDRESS()
- : IOAddress::IPV6_ZERO_ADDRESS());
-
- // Now iterate over all parameters. Currently there's only one supported
- // parameter, so it should be an easy thing to check.
- bool ip_address_specified = false;
- BOOST_FOREACH(ConfigPair param, relay_info->mapValue()) {
- if (param.first == "ip-address") {
- ip_address_specified = true;
-
- try {
- ip = asiolink::IOAddress(param.second->stringValue());
- } catch (...) {
- isc_throw(DhcpConfigError, "Failed to parse ip-address "
- "value: " << param.second
- << " (" << param.second->getPosition() << ")");
- }
-
- // Check if the address family matches.
- if ( (ip.isV4() && family_ != Option::V4) ||
- (ip.isV6() && family_ != Option::V6) ) {
- isc_throw(DhcpConfigError, "ip-address field " << ip.toText()
- << " does not have IP address of expected family type: "
- << (family_ == Option::V4 ? "IPv4" : "IPv6")
- << " (" << param.second->getPosition() << ")");
- }
- } else {
- isc_throw(NotImplemented,
- "parser error: RelayInfoParser parameter not supported: "
- << param.second);
- }
- }
-
- if (!ip_address_specified) {
- isc_throw(DhcpConfigError, "'relay' specified, but mandatory 'ip-address' "
- "paramter in it is missing");
+ // There is only one parameter which is mandatory
+ IOAddress ip = getIOAddress(relay_info, "ip-address");
+
+ // Check if the address family matches.
+ if ((ip.isV4() && family_ != Option::V4) ||
+ (ip.isV6() && family_ != Option::V6) ) {
+ isc_throw(DhcpConfigError, "ip-address field " << ip.toText()
+ << " does not have IP address of expected family type: "
+ << (family_ == Option::V4 ? "IPv4" : "IPv6")
+ << " (" << getPosition("ip-address", relay_info) << ")");
}
// Ok, we're done with parsing. Let's store the result in the structure
//**************************** D2ClientConfigParser **********************
-// Can't use a constructor as a function
-namespace {
-IOAddress buildIOAddress(const std::string& str) { return (IOAddress(str)); }
-};
-
IOAddress
D2ClientConfigParser::getIOAddress(ConstElementPtr scope,
const std::string& name) {
/// @brief Constructor.
///
/// @param address_family Address family: @c AF_INET or @c AF_INET6.
- OptionDataParser(const uint16_t address_family);
+ explicit OptionDataParser(const uint16_t address_family);
/// @brief Parses ElementPtr containing option definition
///
/// @brief Constructor.
///
/// @param address_family Address family: @c AF_INET or AF_INET6
- OptionDataListParser(const uint16_t address_family);
+ explicit OptionDataListParser(const uint16_t address_family);
/// @brief Parses a list of options, instantiates them and stores in cfg
///
/// @brief constructor
/// @param family specifies protocol family (IPv4 or IPv6)
- RelayInfoParser(const isc::dhcp::Option::Universe& family);
+ explicit RelayInfoParser(const isc::dhcp::Option::Universe& family);
/// @brief parses the actual relay parameters
///
void parse(const isc::dhcp::Subnet::RelayInfoPtr& cfg,
isc::data::ConstElementPtr relay_info);
-protected:
+private:
+
+ /// @brief Returns a value converted to IOAddress
+ ///
+ /// Instantiation of getAndConvert() to IOAddress
+ ///
+ /// @param scope specified parameter will be extracted from this scope
+ /// @param name name of the parameter
+ /// @return an IOAddress value
+ isc::asiolink::IOAddress
+ getIOAddress(isc::data::ConstElementPtr scope, const std::string& name);
+
/// Protocol family (IPv4 or IPv6)
Option::Universe family_;
};
/// @brief constructor
///
/// @param family address family: @c AF_INET or @c AF_INET6
- SubnetConfigParser(uint16_t family);
+ explicit SubnetConfigParser(uint16_t family);
/// @brief virtual destructor (does nothing)
virtual ~SubnetConfigParser() { }