Kea 3.1.1
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>
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
21namespace isc {
22namespace radius {
23
35public:
36
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
138
142 data::ElementPtr toElement() const override;
143
144protected:
147 public:
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
176
179
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(!(yy_init))
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Base class for classes representing DHCP messages.
Definition pkt.h:161
Collection of attributes.
AttrDefPtr def_
Pointer to the attribute definition (required).
ConstAttributePtr attr_
Pointer to the attribute.
std::string test_
Original expression.
dhcp::ExpressionPtr expr_
Expression to compute the value.
AttributeValue(const AttrDefPtr &def, const ConstAttributePtr &attr, const dhcp::ExpressionPtr &expr, const std::string &test)
Constructor.
Attributes getAll() const
Get all attributes in the configuration.
void add(const AttrDefPtr &def, const ConstAttributePtr &attr, const dhcp::ExpressionPtr &expr, const std::string &test)
Adds instance of the attribute to the configuration.
AttrDefPtr getDef(const uint8_t type) const
Returns the definition of an attribute.
size_t size() const
Returns the number of elements.
size_t count(const uint8_t type) const
Counts instance of the attribute in the configuration.
bool empty() const
Checks if the object is empty.
void add(const AttrDefPtr &def, const ConstAttributePtr &attr)
Adds instance of the attribute to the configuration.
ConstAttributePtr get(const uint8_t type) const
Get instance of the attribute in the configuration.
std::multimap< uint8_t, AttributeValue > container_
The container.
void clear()
Clear the container.
dhcp::ExpressionPtr getExpr(const uint8_t type) const
Returns the expression of an attribute.
std::string getTest(const uint8_t type) const
Returns the text expression of an attribute.
bool del(const uint8_t type)
Deletes an attribute from the configuration.
Attributes getEvalAll(dhcp::Pkt &pkt)
Get all evaluated attributes in the configuration.
data::ElementPtr toElement() const override
Unparse configuration.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< Expression > ExpressionPtr
Definition token.h:31
boost::shared_ptr< const Attribute > ConstAttributePtr
boost::shared_ptr< AttrDef > AttrDefPtr
Shared pointers to Attribute definition.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.