Kea 3.1.3
client_dictionary.h
Go to the documentation of this file.
1// Copyright (C) 2023-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 RADIUS_CLIENT_DICTIONARY_H
8#define RADIUS_CLIENT_DICTIONARY_H
9
11#include <client.h>
12#include <boost/multi_index_container.hpp>
13#include <boost/multi_index/hashed_index.hpp>
14#include <boost/multi_index/member.hpp>
15#include <boost/multi_index/composite_key.hpp>
16#include <boost/noncopyable.hpp>
17#include <boost/shared_ptr.hpp>
18#include <istream>
19#include <list>
20#include <unordered_map>
21#include <string>
22
23namespace isc {
24namespace radius {
25
37
42std::string attrValueTypeToText(const AttrValueType value);
43
50AttrValueType textToAttrValueType(const std::string& name);
51
53class AttrDef {
54public:
55
62 AttrDef(const uint8_t type, const std::string& name,
63 const AttrValueType value_type, const uint32_t vendor = 0)
64 : type_(type), name_(name), value_type_(value_type), vendor_(vendor) {
65 }
66
68 const uint8_t type_;
69
71 const std::string name_;
72
75
77 const uint32_t vendor_;
78};
79
81typedef boost::shared_ptr<AttrDef> AttrDefPtr;
82
84typedef std::list<AttrDef> AttrDefList;
85
88public:
89
95 AttrDefAlias(const std::string& alias, const std::string& name,
96 const uint32_t vendor = 0)
97 : alias_(alias), name_(name), vendor_(vendor) {
98 }
99
101 const std::string alias_;
102
104 const std::string name_;
105
107 const uint32_t vendor_;
108};
109
114public:
115
122 IntCstDef(const uint8_t type, const std::string& name,
123 const uint32_t value, const uint32_t vendor = 0)
124 : type_(type), name_(name), value_(value), vendor_(vendor) {
125 }
126
128 const uint8_t type_;
129
131 const std::string name_;
132
134 const uint32_t value_;
135
137 const uint32_t vendor_;
138};
139
141typedef boost::shared_ptr<IntCstDef> IntCstDefPtr;
142
144class AttrDefs : public boost::noncopyable {
145public:
146
148 typedef boost::multi_index_container<
149 // This container stores pointers to attribute definitions.
151 // Start specification of indexes here.
152 boost::multi_index::indexed_by<
153 // Hash index for by vendor and type.
154 boost::multi_index::hashed_unique<
155 boost::multi_index::composite_key<
156 AttrDef,
157 boost::multi_index::member<
158 AttrDef, const uint32_t, &AttrDef::vendor_
159 >,
160 boost::multi_index::member<
161 AttrDef, const uint8_t, &AttrDef::type_
162 >
163 >
164 >,
165 // Hash index for by vendor and name.
166 boost::multi_index::hashed_unique<
167 boost::multi_index::composite_key<
168 AttrDef,
169 boost::multi_index::member<
170 AttrDef, const uint32_t, &AttrDef::vendor_
171 >,
172 boost::multi_index::member<
173 AttrDef, const std::string, &AttrDef::name_
174 >
175 >
176 >
177 >
179
181 typedef boost::multi_index_container<
182 // This container stores aliases.
184 // Start specification of indexes here.
185 boost::multi_index::indexed_by<
186 // Hash index for by vendor and alias.
187 boost::multi_index::hashed_unique<
188 boost::multi_index::composite_key<
190 boost::multi_index::member<
191 AttrDefAlias, const uint32_t, &AttrDefAlias::vendor_
192 >,
193 boost::multi_index::member<
194 AttrDefAlias, const std::string, &AttrDefAlias::alias_
195 >
196 >
197 >
198 >
200
202 typedef boost::multi_index_container<
203 // This container stores pointers to integer constant definitions.
205 // Start specification of indexes here.
206 boost::multi_index::indexed_by<
207 // Hash index for by vendor, type and name.
208 boost::multi_index::hashed_unique<
209 boost::multi_index::composite_key<
210 IntCstDef,
211 boost::multi_index::member<
212 IntCstDef, const uint32_t, &IntCstDef::vendor_
213 >,
214 boost::multi_index::member<
215 IntCstDef, const uint8_t, &IntCstDef::type_
216 >,
217 boost::multi_index::member<
218 IntCstDef, const std::string, &IntCstDef::name_
219 >
220 >
221 >,
222 // Hash index for by vendor, type and value.
223 boost::multi_index::hashed_unique<
224 boost::multi_index::composite_key<
225 IntCstDef,
226 boost::multi_index::member<
227 IntCstDef, const uint32_t, &IntCstDef::vendor_
228 >,
229 boost::multi_index::member<
230 IntCstDef, const uint8_t, &IntCstDef::type_
231 >,
232 boost::multi_index::member<
233 IntCstDef, const uint32_t, &IntCstDef::value_
234 >
235 >
236 >
237 >
239
245 static AttrDefs& instance();
246
252 AttrDefPtr getByType(const uint8_t type, const uint32_t vendor = 0) const;
253
259 AttrDefPtr getByName(const std::string& name,
260 const uint32_t vendor = 0) const;
261
265 void add(AttrDefPtr def);
266
268 void clear() {
269 container_.clear();
270 aliases_.clear();
271 ic_container_.clear();
272 }
273
278 std::string getName(const uint8_t type, const uint32_t vendor = 0) const;
279
286 IntCstDefPtr getByName(const uint8_t type, const std::string& name,
287 const uint32_t vendor = 0) const;
288
295 IntCstDefPtr getByValue(const uint8_t type, const uint32_t value,
296 const uint32_t vendor = 0) const;
297
300 void add(IntCstDefPtr def);
301
311 void readDictionary(const std::string& path, uint32_t& vendor,
312 unsigned int depth = 0);
313
323 void readDictionary(std::istream& is, uint32_t& vendor,
324 unsigned int depth = 0);
325
330 void checkStandardDefs(const AttrDefList& defs) const;
331
332protected:
336
338 virtual ~AttrDefs() {
339 clear();
340 }
341
347 void parseLine(const std::string& line, uint32_t& vendor,
348 unsigned int depth);
349
352
355
358};
359
360} // end of namespace isc::radius
361} // end of namespace isc
362
363#endif
RADIUS attribute aliases.
const uint32_t vendor_
vendor id (default 0).
const std::string alias_
alias.
const std::string name_
name.
AttrDefAlias(const std::string &alias, const std::string &name, const uint32_t vendor=0)
Constructor.
RADIUS attribute definition.
const std::string name_
name.
const uint8_t type_
type.
AttrDef(const uint8_t type, const std::string &name, const AttrValueType value_type, const uint32_t vendor=0)
Constructor.
const AttrValueType value_type_
value_type.
const uint32_t vendor_
vendor id (default 0).
void add(AttrDefPtr def)
Add (or replace) an attribute definition.
static AttrDefs & instance()
Returns a single instance.
AttrDefContainer container_
Attribute definition container.
IntCstDefContainer ic_container_
Integer constant definition container.
AttrDefAliases aliases_
Attribute aliases.
boost::multi_index_container< AttrDefPtr, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::composite_key< AttrDef, boost::multi_index::member< AttrDef, const uint32_t, &AttrDef::vendor_ >, boost::multi_index::member< AttrDef, const uint8_t, &AttrDef::type_ > > >, boost::multi_index::hashed_unique< boost::multi_index::composite_key< AttrDef, boost::multi_index::member< AttrDef, const uint32_t, &AttrDef::vendor_ >, boost::multi_index::member< AttrDef, const std::string, &AttrDef::name_ > > > > > AttrDefContainer
Type of the attribute definition container.
void readDictionary(const std::string &path, uint32_t &vendor, unsigned int depth=0)
Read a dictionary from a file.
IntCstDefPtr getByValue(const uint8_t type, const uint32_t value, const uint32_t vendor=0) const
Get integer constant definition by attribute type and value.
boost::multi_index_container< IntCstDefPtr, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::composite_key< IntCstDef, boost::multi_index::member< IntCstDef, const uint32_t, &IntCstDef::vendor_ >, boost::multi_index::member< IntCstDef, const uint8_t, &IntCstDef::type_ >, boost::multi_index::member< IntCstDef, const std::string, &IntCstDef::name_ > > >, boost::multi_index::hashed_unique< boost::multi_index::composite_key< IntCstDef, boost::multi_index::member< IntCstDef, const uint32_t, &IntCstDef::vendor_ >, boost::multi_index::member< IntCstDef, const uint8_t, &IntCstDef::type_ >, boost::multi_index::member< IntCstDef, const uint32_t, &IntCstDef::value_ > > > > > IntCstDefContainer
Type of the integer constant definition container.
virtual ~AttrDefs()
Destructor.
void parseLine(const std::string &line, uint32_t &vendor, unsigned int depth)
Parse a dictionary line.
boost::multi_index_container< AttrDefAlias, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::composite_key< AttrDefAlias, boost::multi_index::member< AttrDefAlias, const uint32_t, &AttrDefAlias::vendor_ >, boost::multi_index::member< AttrDefAlias, const std::string, &AttrDefAlias::alias_ > > > > > AttrDefAliases
Type of the alias table (alias -> standard name map).
void clear()
Clear definitions.
std::string getName(const uint8_t type, const uint32_t vendor=0) const
Get attribute name.
AttrDefPtr getByName(const std::string &name, const uint32_t vendor=0) const
Get attribute definition by name and vendor.
void checkStandardDefs(const AttrDefList &defs) const
Check if a list of standard attribute definitions are available and correct.
AttrDefPtr getByType(const uint8_t type, const uint32_t vendor=0) const
Get attribute definition by type and vendor.
RADIUS integer constant definitions.
const std::string name_
name.
const uint8_t type_
attribute type.
IntCstDef(const uint8_t type, const std::string &name, const uint32_t value, const uint32_t vendor=0)
Constructor.
const uint32_t value_
value.
const uint32_t vendor_
vendor id (default 0).
boost::shared_ptr< IntCstDef > IntCstDefPtr
Shared pointers to Integer constant definition.
std::list< AttrDef > AttrDefList
List of Attribute definitions.
AttrValueType
Attribute value types.
boost::shared_ptr< AttrDef > AttrDefPtr
Shared pointers to Attribute definition.
AttrValueType textToAttrValueType(const string &name)
AttrValueType name -> value function.
string attrValueTypeToText(const AttrValueType value)
AttrValueType value -> name function.
Defines the logger used by the top-level component of kea-lfc.