Kea  2.1.7-git
shared_networks_list_parser.h
Go to the documentation of this file.
1 // Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef SHARED_NETWORKS_LIST_PARSER_H
8 #define SHARED_NETWORKS_LIST_PARSER_H
9 
10 #include <cc/data.h>
11 #include <cc/dhcp_config_error.h>
12 #include <cc/simple_parser.h>
13 #include <exceptions/exceptions.h>
14 #include <dhcpsrv/subnet.h>
16 #include <vector>
17 
18 namespace isc {
19 namespace dhcp {
20 
28 template<typename SharedNetworkParserType>
30 public:
31 
36  SharedNetworksListParser(bool check_iface = true)
37  : check_iface_(check_iface) {
38  }
39 
52  template<typename CfgSharedNetworksTypePtr>
53  void parse(CfgSharedNetworksTypePtr& cfg,
54  const data::ConstElementPtr& shared_networks_list_data) {
55  try {
56  // Get the C++ vector holding networks.
57  const std::vector<data::ElementPtr>& networks_list =
58  shared_networks_list_data->listValue();
59  // Iterate over all networks and do the parsing.
60  for (auto network_element = networks_list.cbegin();
61  network_element != networks_list.cend(); ++network_element) {
62  SharedNetworkParserType parser(check_iface_);
63  auto network = parser.parse(*network_element);
64  cfg->add(network);
65  }
66  } catch (const DhcpConfigError&) {
67  // Such exceptions are emitted by the lower level parsers and
68  // errors should already include element's positions. So, we
69  // simply rethrow.
70  throw;
71 
72  } catch (const std::exception& ex) {
73  // Other exceptions don't include positions of the elements, so
74  // we should append one.
75  isc_throw(DhcpConfigError, ex.what() << " ("
76  << shared_networks_list_data->getPosition() << ")");
77  }
78  }
79 
80 protected:
83 };
84 
87 
90 
91 
92 } // end of namespace isc::dhcp
93 } // end of namespace isc
94 
95 #endif // SHARED_NETWORKS_LIST_PARSER_H
SharedNetworksListParser< SharedNetwork6Parser > SharedNetworks6ListParser
Type of the shared networks list parser for IPv6.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
To be removed. Please use ConfigError instead.
Parser for a list of shared networks.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
Defines the logger used by the top-level component of kea-lfc.
void parse(CfgSharedNetworksTypePtr &cfg, const data::ConstElementPtr &shared_networks_list_data)
Parses a list of shared networks.
SharedNetworksListParser(bool check_iface=true)
Constructor.
SharedNetworksListParser< SharedNetwork4Parser > SharedNetworks4ListParser
Type of the shared networks list parser for IPv4.
bool check_iface_
Check if the specified interface exists in the system.