| Kea 3.0.2-git

cfg_attribute.h
Go to the documentation of this file.
1// Copyright (C) 2020-2025 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 CFG_ATTRIBUTE_H
8#define CFG_ATTRIBUTE_H
9
10#include <client_attribute.h>
11#include <exceptions/exceptions.h>
12#include <cc/data.h>
13#include <cc/cfg_to_element.h>
14#include <dhcp/pkt.h>
15#include <eval/token.h>
16#include <util/buffer.h>
17#include <boost/shared_ptr.hpp>
18#include <vector>
19#include <map>
20
21 namespace isc {
22 namespace radius {
23
34 class CfgAttributes : public data::CfgToElement {
35 public:
36
38 CfgAttributes() : container_() {
39 }
40
41 // @brief Destructor.
42 virtual ~CfgAttributes() {
43 clear();
44 }
45
49 bool empty() const {
50 return (container_.empty());
51 }
52
56 size_t size() const {
57 return (container_.size());
58 }
59
66 void add(const AttrDefPtr& def,
67 const ConstAttributePtr& attr,
68 const dhcp::ExpressionPtr& expr,
69 const std::string& test);
70
75 void add(const AttrDefPtr& def, const ConstAttributePtr& attr) {
76 add(def, attr, dhcp::ExpressionPtr(), "");
77 }
78
85 bool del(const uint8_t type);
86
88 void clear() {
89 container_.clear();
90 }
91
96 size_t count(const uint8_t type) const {
97 return (container_.count(type));
98 }
99
104 AttrDefPtr getDef(const uint8_t type) const;
105
110 ConstAttributePtr get(const uint8_t type) const;
111
116 dhcp::ExpressionPtr getExpr(const uint8_t type) const;
117
122 std::string getTest(const uint8_t type) const;
123
127 Attributes getAll() const;
128
137 Attributes getEvalAll(dhcp::Pkt& pkt);
138
142 data::ElementPtr toElement() const override;
143
144 protected:
146 class AttributeValue {
147 public:
154 AttributeValue(const AttrDefPtr& def,
155 const ConstAttributePtr& attr,
156 const dhcp::ExpressionPtr& expr,
157 const std::string& test)
158 : def_(def), attr_(attr), expr_(expr), test_(test) {
159 if (!def) {
160 isc_throw(BadValue, "no attribute definition");
161 }
162 if (expr || !test.empty()) {
163 if (attr) {
164 isc_throw(BadValue, "once of attribute or test");
165 }
166 if (!expr || test.empty()) {
167 isc_throw(BadValue, "missing expression or test");
168 }
169 } else if (!attr) {
170 isc_throw(BadValue, "no attribute and test");
171 }
172 }
173
175 AttrDefPtr def_;
176
178 ConstAttributePtr attr_;
179
181 dhcp::ExpressionPtr expr_;
182
184 std::string test_;
185 };
186
188 std::multimap<uint8_t, AttributeValue> container_;
189};
190
191} // end of namespace isc::radius
192} // end of namespace isc
193
194#endif
if
if(!(yy_init))
Definition agent_lexer.cc:1900
buffer.h
cfg_to_element.h
isc::BadValue
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Definition exceptions/exceptions.h:132
isc::dhcp::Pkt
Base class for classes representing DHCP messages.
Definition pkt.h:161
isc::radius::Attributes
Collection of attributes.
Definition client_attribute.h:652
isc::radius::CfgAttributes::AttributeValue::def_
AttrDefPtr def_
Pointer to the attribute definition (required).
Definition cfg_attribute.h:175
isc::radius::CfgAttributes::AttributeValue::attr_
ConstAttributePtr attr_
Pointer to the attribute.
Definition cfg_attribute.h:178
isc::radius::CfgAttributes::AttributeValue::test_
std::string test_
Original expression.
Definition cfg_attribute.h:184
isc::radius::CfgAttributes::AttributeValue::expr_
dhcp::ExpressionPtr expr_
Expression to compute the value.
Definition cfg_attribute.h:181
isc::radius::CfgAttributes::AttributeValue::AttributeValue
AttributeValue(const AttrDefPtr &def, const ConstAttributePtr &attr, const dhcp::ExpressionPtr &expr, const std::string &test)
Constructor.
Definition cfg_attribute.h:154
isc::radius::CfgAttributes::getAll
Attributes getAll() const
Get all attributes in the configuration.
Definition cfg_attribute.cc:82
isc::radius::CfgAttributes::CfgAttributes
CfgAttributes()
Constructor.
Definition cfg_attribute.h:38
isc::radius::CfgAttributes::add
void add(const AttrDefPtr &def, const ConstAttributePtr &attr, const dhcp::ExpressionPtr &expr, const std::string &test)
Adds instance of the attribute to the configuration.
Definition cfg_attribute.cc:24
isc::radius::CfgAttributes::getDef
AttrDefPtr getDef(const uint8_t type) const
Returns the definition of an attribute.
Definition cfg_attribute.cc:46
isc::radius::CfgAttributes::size
size_t size() const
Returns the number of elements.
Definition cfg_attribute.h:56
isc::radius::CfgAttributes::count
size_t count(const uint8_t type) const
Counts instance of the attribute in the configuration.
Definition cfg_attribute.h:96
isc::radius::CfgAttributes::empty
bool empty() const
Checks if the object is empty.
Definition cfg_attribute.h:49
isc::radius::CfgAttributes::add
void add(const AttrDefPtr &def, const ConstAttributePtr &attr)
Adds instance of the attribute to the configuration.
Definition cfg_attribute.h:75
isc::radius::CfgAttributes::~CfgAttributes
virtual ~CfgAttributes()
Definition cfg_attribute.h:42
isc::radius::CfgAttributes::get
ConstAttributePtr get(const uint8_t type) const
Get instance of the attribute in the configuration.
Definition cfg_attribute.cc:55
isc::radius::CfgAttributes::container_
std::multimap< uint8_t, AttributeValue > container_
The container.
Definition cfg_attribute.h:188
isc::radius::CfgAttributes::clear
void clear()
Clear the container.
Definition cfg_attribute.h:88
isc::radius::CfgAttributes::getExpr
dhcp::ExpressionPtr getExpr(const uint8_t type) const
Returns the expression of an attribute.
Definition cfg_attribute.cc:64
isc::radius::CfgAttributes::getTest
std::string getTest(const uint8_t type) const
Returns the text expression of an attribute.
Definition cfg_attribute.cc:73
isc::radius::CfgAttributes::del
bool del(const uint8_t type)
Deletes an attribute from the configuration.
Definition cfg_attribute.cc:36
isc::radius::CfgAttributes::getEvalAll
Attributes getEvalAll(dhcp::Pkt &pkt)
Get all evaluated attributes in the configuration.
Definition cfg_attribute.cc:91
isc::radius::CfgAttributes::toElement
data::ElementPtr toElement() const override
Unparse configuration.
Definition cfg_attribute.cc:117
client_attribute.h
data.h
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
isc::dhcp::ExpressionPtr
boost::shared_ptr< Expression > ExpressionPtr
Definition token.h:31
isc::radius
Definition cfg_attribute.cc:21
isc::radius::ConstAttributePtr
boost::shared_ptr< const Attribute > ConstAttributePtr
Definition client_attribute.h:37
isc::radius::AttrDefPtr
boost::shared_ptr< AttrDef > AttrDefPtr
Shared pointers to Attribute definition.
Definition client_dictionary.h:76
isc::test
Definition env_var_wrapper.cc:12
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
pkt.h
isc::data::CfgToElement
Abstract class for configuration Cfg_* classes.
Definition cfg_to_element.h:29
token.h