Kea 2.5.8
option_space.cc
Go to the documentation of this file.
1// Copyright (C) 2012-2015 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#include <config.h>
8
9#include <dhcp/option_space.h>
10#include <boost/algorithm/string/classification.hpp>
11#include <boost/algorithm/string/predicate.hpp>
12
13namespace isc {
14namespace dhcp {
15
16OptionSpace::OptionSpace(const std::string& name, const bool vendor_space)
17 : name_(name), vendor_space_(vendor_space) {
18 // Check that provided option space name is valid.
19 if (!validateName(name_)) {
20 isc_throw(InvalidOptionSpace, "Invalid option space name "
21 << name_);
22 }
23}
24
25bool
26OptionSpace::validateName(const std::string& name) {
27
28 using namespace boost::algorithm;
29
30 // Allowed characters are: lower or upper case letters, digits,
31 // underscores and hyphens. Empty option spaces are not allowed.
32 if (all(name, boost::is_from_range('a', 'z') ||
33 boost::is_from_range('A', 'Z') ||
34 boost::is_digit() ||
35 boost::is_any_of(std::string("-_"))) &&
36 !name.empty() &&
37 // Hyphens and underscores are not allowed at the beginning
38 // and at the end of the option space name.
39 !all(find_head(name, 1), boost::is_any_of(std::string("-_"))) &&
40 !all(find_tail(name, 1), boost::is_any_of(std::string("-_")))) {
41 return (true);
42
43 }
44 return (false);
45}
46
47OptionSpace6::OptionSpace6(const std::string& name)
48 : OptionSpace(name),
49 enterprise_number_(0) {
50}
51
52OptionSpace6::OptionSpace6(const std::string& name,
53 const uint32_t enterprise_number)
54 : OptionSpace(name, true),
55 enterprise_number_(enterprise_number) {
56}
57
58void
59OptionSpace6::setVendorSpace(const uint32_t enterprise_number) {
60 enterprise_number_ = enterprise_number;
62}
63
64} // end of isc::dhcp namespace
65} // end of isc namespace
Exception to be thrown when invalid option space is specified.
Definition: option_space.h:23
OptionSpace6(const std::string &name)
Constructor for non-vendor-specific options.
Definition: option_space.cc:47
DHCP option space.
Definition: option_space.h:66
void setVendorSpace()
Mark option space as vendor specific.
Definition: option_space.h:98
static bool validateName(const std::string &name)
Checks that the provided option space name is valid.
Definition: option_space.cc:26
OptionSpace(const std::string &name, const bool vendor_space=false)
Constructor.
Definition: option_space.cc:16
const Name & name_
Definition: dns/message.cc:696
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.