Kea 1.5.0
shared_networks_list_parser.h
Go to the documentation of this file.
1// Copyright (C) 2017 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
43 template<typename CfgSharedNetworksTypePtr>
44 void parse(CfgSharedNetworksTypePtr& cfg,
45 const data::ConstElementPtr& shared_networks_list_data) {
46 try {
47 // Get the C++ vector holding networks.
48 const std::vector<data::ElementPtr>& networks_list =
49 shared_networks_list_data->listValue();
50 // Iterate over all networks and do the parsing.
51 for (auto network_element = networks_list.cbegin();
52 network_element != networks_list.cend(); ++network_element) {
53 SharedNetworkParserType parser;
54 auto network = parser.parse(*network_element);
55 cfg->add(network);
56 }
57 } catch (const DhcpConfigError&) {
58 // Such exceptions are emitted by the lower level parsers and
59 // errors should already include element's positions. So, we
60 // simply rethrow.
61 throw;
62
63 } catch (const std::exception& ex) {
64 // Other exceptions don't include positions of the elements, so
65 // we should append one.
66 isc_throw(DhcpConfigError, ex.what() << " ("
67 << shared_networks_list_data->getPosition() << ")");
68 }
69 }
70};
71
74
77
78
79} // end of namespace isc::dhcp
80} // end of namespace isc
81
82#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.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
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-dhcp-ddns.