Kea 3.3.3
client_dictionary.h
Go to the documentation of this file.
1// Copyright (C) 2023-2026 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 <radius/client.h>
12
13#include <cstdint>
14#include <istream>
15#include <list>
16#include <string>
17
18#include <boost/multi_index/composite_key.hpp>
19#include <boost/multi_index/hashed_index.hpp>
20#include <boost/multi_index/member.hpp>
21#include <boost/multi_index_container.hpp>
22#include <boost/noncopyable.hpp>
23#include <boost/shared_ptr.hpp>
24
25namespace isc {
26namespace radius {
27
39
44std::string attrValueTypeToText(const AttrValueType value);
45
52AttrValueType textToAttrValueType(const std::string& name);
53
55class AttrDef {
56public:
57
64 AttrDef(const uint8_t type, const std::string& name,
65 const AttrValueType value_type, const uint32_t vendor = 0)
66 : type_(type), name_(name), value_type_(value_type), vendor_(vendor) {
67 }
68
70 const uint8_t type_;
71
73 const std::string name_;
74
77
79 const uint32_t vendor_;
80};
81
83typedef boost::shared_ptr<AttrDef> AttrDefPtr;
84
86typedef std::list<AttrDef> AttrDefList;
87
90public:
91
97 AttrDefAlias(const std::string& alias, const std::string& name,
98 const uint32_t vendor = 0)
99 : alias_(alias), name_(name), vendor_(vendor) {
100 }
101
103 const std::string alias_;
104
106 const std::string name_;
107
109 const uint32_t vendor_;
110};
111
116public:
117
124 IntCstDef(const uint8_t type, const std::string& name,
125 const uint32_t value, const uint32_t vendor = 0)
126 : type_(type), name_(name), value_(value), vendor_(vendor) {
127 }
128
130 const uint8_t type_;
131
133 const std::string name_;
134
136 const uint32_t value_;
137
139 const uint32_t vendor_;
140};
141
143typedef boost::shared_ptr<IntCstDef> IntCstDefPtr;
144
146class AttrDefs : public boost::noncopyable {
147public:
148
150 typedef boost::multi_index_container<
151 // This container stores pointers to attribute definitions.
153 // Start specification of indexes here.
154 boost::multi_index::indexed_by<
155 // Hash index for by vendor and type.
156 boost::multi_index::hashed_unique<
157 boost::multi_index::composite_key<
158 AttrDef,
159 boost::multi_index::member<
160 AttrDef, const uint32_t, &AttrDef::vendor_
161 >,
162 boost::multi_index::member<
163 AttrDef, const uint8_t, &AttrDef::type_
164 >
165 >
166 >,
167 // Hash index for by vendor and name.
168 boost::multi_index::hashed_unique<
169 boost::multi_index::composite_key<
170 AttrDef,
171 boost::multi_index::member<
172 AttrDef, const uint32_t, &AttrDef::vendor_
173 >,
174 boost::multi_index::member<
175 AttrDef, const std::string, &AttrDef::name_
176 >
177 >
178 >
179 >
181
183 typedef boost::multi_index_container<
184 // This container stores aliases.
186 // Start specification of indexes here.
187 boost::multi_index::indexed_by<
188 // Hash index for by vendor and alias.
189 boost::multi_index::hashed_unique<
190 boost::multi_index::composite_key<
192 boost::multi_index::member<
193 AttrDefAlias, const uint32_t, &AttrDefAlias::vendor_
194 >,
195 boost::multi_index::member<
196 AttrDefAlias, const std::string, &AttrDefAlias::alias_
197 >
198 >
199 >
200 >
202
204 typedef boost::multi_index_container<
205 // This container stores pointers to integer constant definitions.
207 // Start specification of indexes here.
208 boost::multi_index::indexed_by<
209 // Hash index for by vendor, type and name.
210 boost::multi_index::hashed_unique<
211 boost::multi_index::composite_key<
212 IntCstDef,
213 boost::multi_index::member<
214 IntCstDef, const uint32_t, &IntCstDef::vendor_
215 >,
216 boost::multi_index::member<
217 IntCstDef, const uint8_t, &IntCstDef::type_
218 >,
219 boost::multi_index::member<
220 IntCstDef, const std::string, &IntCstDef::name_
221 >
222 >
223 >,
224 // Hash index for by vendor, type and value.
225 boost::multi_index::hashed_unique<
226 boost::multi_index::composite_key<
227 IntCstDef,
228 boost::multi_index::member<
229 IntCstDef, const uint32_t, &IntCstDef::vendor_
230 >,
231 boost::multi_index::member<
232 IntCstDef, const uint8_t, &IntCstDef::type_
233 >,
234 boost::multi_index::member<
235 IntCstDef, const uint32_t, &IntCstDef::value_
236 >
237 >
238 >
239 >
241
247 static AttrDefs& instance();
248
254 AttrDefPtr getByType(const uint8_t type, const uint32_t vendor = 0) const;
255
261 AttrDefPtr getByName(const std::string& name,
262 const uint32_t vendor = 0) const;
263
267 void add(AttrDefPtr def);
268
270 void clear() {
271 container_.clear();
272 aliases_.clear();
273 ic_container_.clear();
274 }
275
280 std::string getName(const uint8_t type, const uint32_t vendor = 0) const;
281
288 IntCstDefPtr getByName(const uint8_t type, const std::string& name,
289 const uint32_t vendor = 0) const;
290
297 IntCstDefPtr getByValue(const uint8_t type, const uint32_t value,
298 const uint32_t vendor = 0) const;
299
302 void add(IntCstDefPtr def);
303
313 void readDictionary(const std::string& path, uint32_t& vendor,
314 unsigned int depth = 0);
315
325 void readDictionary(std::istream& is, uint32_t& vendor,
326 unsigned int depth = 0);
327
332 void checkStandardDefs(const AttrDefList& defs) const;
333
334protected:
338
340 virtual ~AttrDefs() {
341 clear();
342 }
343
349 void parseLine(const std::string& line, uint32_t& vendor,
350 unsigned int depth);
351
354
357
360};
361
362} // end of namespace isc::radius
363} // end of namespace isc
364
365#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.
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.
AttrValueType
Attribute value types.
Defines the logger used by the top-level component of kea-lfc.