Kea 2.2.0
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>
12#include <cc/simple_parser.h>
14#include <dhcpsrv/subnet.h>
16#include <vector>
17
18namespace isc {
19namespace dhcp {
20
28template<typename SharedNetworkParserType>
30public:
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
80protected:
83};
84
87
90
91
92} // end of namespace isc::dhcp
93} // end of namespace isc
94
95#endif // SHARED_NETWORKS_LIST_PARSER_H
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
To be removed. Please use ConfigError instead.
Parser for a list of shared networks.
void parse(CfgSharedNetworksTypePtr &cfg, const data::ConstElementPtr &shared_networks_list_data)
Parses a list of shared networks.
SharedNetworksListParser(bool check_iface=true)
Constructor.
bool check_iface_
Check if the specified interface exists in the system.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
SharedNetworksListParser< SharedNetwork4Parser > SharedNetworks4ListParser
Type of the shared networks list parser for IPv4.
SharedNetworksListParser< SharedNetwork6Parser > SharedNetworks6ListParser
Type of the shared networks list parser for IPv6.
Defines the logger used by the top-level component of kea-lfc.