Kea 3.1.1
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
36
41std::string attrValueTypeToText(const AttrValueType value);
42
49AttrValueType textToAttrValueType(const std::string& name);
50
52class AttrDef {
53public:
54
60 AttrDef(const uint8_t type, const std::string& name,
61 const AttrValueType value_type)
62 : type_(type), name_(name), value_type_(value_type) {
63 }
64
66 const uint8_t type_;
67
69 const std::string name_;
70
73};
74
76typedef boost::shared_ptr<AttrDef> AttrDefPtr;
77
79typedef std::list<AttrDef> AttrDefList;
80
82class IntCstDef {
83public:
84
90 IntCstDef(const uint8_t type, const std::string& name,
91 const uint32_t value)
92 : type_(type), name_(name), value_(value) {
93 }
94
96 const uint8_t type_;
97
99 const std::string name_;
100
102 const uint32_t value_;
103};
104
106typedef boost::shared_ptr<IntCstDef> IntCstDefPtr;
107
109class AttrDefs : public boost::noncopyable {
110public:
111
113 typedef boost::multi_index_container<
114 // This container stores pointers to attribute definitions.
116 // Start specification of indexes here.
117 boost::multi_index::indexed_by<
118 // Hash index for by type.
119 boost::multi_index::hashed_unique<
120 boost::multi_index::member<
121 AttrDef, const uint8_t, &AttrDef::type_
122 >
123 >,
124 // Hash index for by name.
125 boost::multi_index::hashed_unique<
126 boost::multi_index::member<
127 AttrDef, const std::string, &AttrDef::name_
128 >
129 >
130 >
132
134 typedef std::unordered_map<std::string, std::string> AttrDefAliases;
135
137 typedef boost::multi_index_container<
138 // This container stores pointers to integer constant definitions.
140 // Start specification of indexes here.
141 boost::multi_index::indexed_by<
142 // Hash index for by type and name.
143 boost::multi_index::hashed_unique<
144 boost::multi_index::composite_key<
145 IntCstDef,
146 boost::multi_index::member<
147 IntCstDef, const uint8_t, &IntCstDef::type_
148 >,
149 boost::multi_index::member<
150 IntCstDef, const std::string, &IntCstDef::name_
151 >
152 >
153 >,
154 // Hash index for by type and value.
155 boost::multi_index::hashed_unique<
156 boost::multi_index::composite_key<
157 IntCstDef,
158 boost::multi_index::member<
159 IntCstDef, const uint8_t, &IntCstDef::type_
160 >,
161 boost::multi_index::member<
162 IntCstDef, const uint32_t, &IntCstDef::value_
163 >
164 >
165 >
166 >
168
174 static AttrDefs& instance();
175
180 AttrDefPtr getByType(const uint8_t type) const;
181
186 AttrDefPtr getByName(const std::string& name) const;
187
191 void add(AttrDefPtr def);
192
194 void clear() {
195 container_.clear();
196 aliases_.clear();
197 ic_container_.clear();
198 }
199
203 std::string getName(const uint8_t type) const;
204
210 IntCstDefPtr getByName(const uint8_t type, const std::string& name) const;
211
217 IntCstDefPtr getByValue(const uint8_t type, const uint32_t value) const;
218
221 void add(IntCstDefPtr def);
222
229 void readDictionary(const std::string& path);
230
237 void readDictionary(std::istream& is);
238
243 void checkStandardDefs(const AttrDefList& defs) const;
244
245protected:
249
251 virtual ~AttrDefs() {
252 clear();
253 }
254
258 void parseLine(const std::string& line);
259
262
265
268};
269
270} // end of namespace isc::radius
271} // end of namespace isc
272
273#endif
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)
Constructor.
const AttrValueType value_type_
value_type.
void add(AttrDefPtr def)
Add (or replace) an attribute definition.
static AttrDefs & instance()
Returns a single instance.
std::unordered_map< std::string, std::string > AttrDefAliases
Type of the alias table (alias -> standard name map).
void readDictionary(const std::string &path)
Read a dictionary from a file.
AttrDefContainer container_
Attribute definition container.
AttrDefPtr getByName(const std::string &name) const
Get attribute definition by name.
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::member< AttrDef, const uint8_t, &AttrDef::type_ > >, boost::multi_index::hashed_unique< boost::multi_index::member< AttrDef, const std::string, &AttrDef::name_ > > > > AttrDefContainer
Type of the attribute definition container.
std::string getName(const uint8_t type) const
Get attribute name.
AttrDefPtr getByType(const uint8_t type) const
Get attribute definition by type.
IntCstDefPtr getByValue(const uint8_t type, const uint32_t value) 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 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 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 clear()
Clear definitions.
void parseLine(const std::string &line)
Parse a dictionary line.
void checkStandardDefs(const AttrDefList &defs) const
Check if a list of standard attribute definitions are available and correct.
RADIUS integer constant definitions.
const std::string name_
name.
const uint8_t type_
attribute type.
const uint32_t value_
value.
IntCstDef(const uint8_t type, const std::string &name, const uint32_t value)
Constructor.
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.