Kea 2.5.7
shared_networks_list_parser.h
Go to the documentation of this file.
1// Copyright (C) 2017-2024 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 const& network_element : networks_list) {
61 SharedNetworkParserType parser(check_iface_);
62 auto network = parser.parse(network_element);
63 cfg->add(network);
64 }
65 } catch (const DhcpConfigError&) {
66 // Such exceptions are emitted by the lower level parsers and
67 // errors should already include element's positions. So, we
68 // simply rethrow.
69 throw;
70
71 } catch (const std::exception& ex) {
72 // Other exceptions don't include positions of the elements, so
73 // we should append one.
74 isc_throw(DhcpConfigError, ex.what() << " ("
75 << shared_networks_list_data->getPosition() << ")");
76 }
77 }
78
79protected:
82};
83
86
89
90
91} // end of namespace isc::dhcp
92} // end of namespace isc
93
94#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:29
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.