Kea 1.5.0
client_class_def.h
Go to the documentation of this file.
1// Copyright (C) 2015-2018 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 CLIENT_CLASS_DEF_H
8#define CLIENT_CLASS_DEF_H
9
10#include <cc/cfg_to_element.h>
11#include <cc/user_context.h>
12#include <dhcpsrv/cfg_option.h>
14#include <eval/token.h>
16
17#include <string>
18#include <unordered_map>
19#include <list>
20#include <vector>
21
34namespace isc {
35namespace dhcp {
36
40public:
41 DuplicateClientClassDef(const char* file, size_t line, const char* what)
42 : isc::Exception(file, line, what) {}
43};
44
47public:
53 ClientClassDef(const std::string& name, const ExpressionPtr& match_expr,
54 const CfgOptionPtr& options = CfgOptionPtr());
55
56
59
61 virtual ~ClientClassDef();
62
64 std::string getName() const;
65
69 void setName(const std::string& name);
70
72 const ExpressionPtr& getMatchExpr() const;
73
77 void setMatchExpr(const ExpressionPtr& match_expr);
78
80 std::string getTest() const;
81
85 void setTest(const std::string& test);
86
88 bool getRequired() const;
89
93 void setRequired(bool required);
94
96 bool getDependOnKnown() const;
97
101 void setDependOnKnown(bool depend_on_known);
102
104 const CfgOptionDefPtr& getCfgOptionDef() const;
105
109 void setCfgOptionDef(const CfgOptionDefPtr& cfg_option_def);
110
112 const CfgOptionPtr& getCfgOption() const;
113
117 void setCfgOption(const CfgOptionPtr& cfg_option);
118
124 bool dependOnClass(const std::string& name) const;
125
131 bool equals(const ClientClassDef& other) const;
132
138 bool operator==(const ClientClassDef& other) const {
139 return (equals(other));
140 }
141
147 bool operator!=(const ClientClassDef& other) const {
148 return (!(equals(other)));
149 }
150
152 friend std::ostream& operator<<(std::ostream& os, const ClientClassDef& x);
153
157 return (next_server_);
158 }
159
164 next_server_ = addr;
165 }
166
170 void setSname(const std::string& sname) {
171 sname_ = sname;
172 }
173
176 const std::string& getSname() const {
177 return (sname_);
178 }
179
183 void setFilename(const std::string& filename) {
184 filename_ = filename;
185 }
186
189 const std::string& getFilename() const {
190 return (filename_);
191 }
192
196 virtual isc::data::ElementPtr toElement() const;
197
198private:
200 std::string name_;
201
204 ExpressionPtr match_expr_;
205
208 std::string test_;
209
214 bool required_;
215
224 bool depend_on_known_;
225
227 CfgOptionDefPtr cfg_option_def_;
228
230 CfgOptionPtr cfg_option_;
231
235 asiolink::IOAddress next_server_;
236
241 std::string sname_;
242
247 std::string filename_;
248
249};
250
252typedef boost::shared_ptr<ClientClassDef> ClientClassDefPtr;
253
255typedef std::unordered_map<std::string, ClientClassDefPtr> ClientClassDefMap;
256
258typedef boost::shared_ptr<ClientClassDefMap> ClientClassDefMapPtr;
259
261typedef std::vector<ClientClassDefPtr> ClientClassDefList;
262
264typedef boost::shared_ptr<ClientClassDefList> ClientClassDefListPtr;
265
268
269public:
272
274
277
295 void addClass(const std::string& name, const ExpressionPtr& match_expr,
296 const std::string& test, bool required, bool depend_on_known,
297 const CfgOptionPtr& options,
300 asiolink::IOAddress next_server = asiolink::IOAddress("0.0.0.0"),
301 const std::string& sname = std::string(),
302 const std::string& filename = std::string());
303
310 void addClass(ClientClassDefPtr& class_def);
311
318 ClientClassDefPtr findClass(const std::string& name) const;
319
326 void removeClass(const std::string& name);
327
331 const ClientClassDefListPtr& getClasses() const;
332
340 bool dependOnClass(const std::string& name, std::string& dependent_class) const;
341
347 bool equals(const ClientClassDictionary& other) const;
348
354 bool operator==(const ClientClassDictionary& other) const {
355 return (equals(other));
356 }
357
363 bool operator!=(const ClientClassDictionary& other) const {
364 return (!equals(other));
365 }
366
370 virtual isc::data::ElementPtr toElement() const;
371
372private:
373
376
379};
380
382typedef boost::shared_ptr<ClientClassDictionary> ClientClassDictionaryPtr;
383
386extern std::list<std::string> builtinNames;
387
390extern std::list<std::string> builtinPrefixes;
391
396bool isClientClassBuiltIn(const ClientClass& client_class);
397
398
411 bool& depend_on_known,
412 const ClientClass& client_class);
413
414} // namespace isc::dhcp
415} // namespace isc
416
417#endif // CLIENT_CLASS_DEF_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Embodies a single client class definition.
bool equals(const ClientClassDef &other) const
Compares two ClientClassDef objects for equality.
bool getRequired() const
Fetches the only if required flag.
void setCfgOption(const CfgOptionPtr &cfg_option)
Sets the class's option collection.
void setName(const std::string &name)
Sets the class's name.
bool dependOnClass(const std::string &name) const
Checks direct dependency.
bool getDependOnKnown() const
Fetches the depend on known flag aka use host flag.
void setFilename(const std::string &filename)
sets the boot-file-name value
void setRequired(bool required)
Sets the only if required flag.
void setNextServer(const asiolink::IOAddress &addr)
sets the next-server value
const CfgOptionDefPtr & getCfgOptionDef() const
Fetches the class's option definitions.
const ExpressionPtr & getMatchExpr() const
Fetches the class's match expression.
void setCfgOptionDef(const CfgOptionDefPtr &cfg_option_def)
Sets the class's option definition collection.
virtual ~ClientClassDef()
Destructor.
const std::string & getSname() const
returns server-hostname value
const asiolink::IOAddress & getNextServer() const
returns next-server value
void setSname(const std::string &sname)
sets the server-name value
bool operator==(const ClientClassDef &other) const
Equality operator.
std::string getName() const
Fetches the class's name.
friend std::ostream & operator<<(std::ostream &os, const ClientClassDef &x)
Provides a convenient text representation of the class.
bool operator!=(const ClientClassDef &other) const
Inequality operator.
const CfgOptionPtr & getCfgOption() const
Fetches the class's option collection.
void setMatchExpr(const ExpressionPtr &match_expr)
Sets the class's match expression.
void setTest(const std::string &test)
Sets the class's original match expression.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
std::string getTest() const
Fetches the class's original match expression.
void setDependOnKnown(bool depend_on_known)
Sets the depend on known flag aka use host flag.
const std::string & getFilename() const
returns boot-file-name value
Maintains a list of ClientClassDef's.
ClientClassDefPtr findClass(const std::string &name) const
Fetches the class definition for a given class name.
void addClass(const std::string &name, const ExpressionPtr &match_expr, const std::string &test, bool required, bool depend_on_known, const CfgOptionPtr &options, CfgOptionDefPtr defs=CfgOptionDefPtr(), isc::data::ConstElementPtr user_context=isc::data::ConstElementPtr(), asiolink::IOAddress next_server=asiolink::IOAddress("0.0.0.0"), const std::string &sname=std::string(), const std::string &filename=std::string())
Adds a new class to the list.
bool equals(const ClientClassDictionary &other) const
Compares two ClientClassDictionary objects for equality.
void removeClass(const std::string &name)
Removes a given class definition from the dictionary.
bool operator!=(const ClientClassDictionary &other) const
Inequality operator.
bool dependOnClass(const std::string &name, std::string &dependent_class) const
Checks direct dependency.
const ClientClassDefListPtr & getClasses() const
Fetches the dictionary's list of classes.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
bool operator==(const ClientClassDictionary &other) const
Equality operator.
Error that occurs when an attempt is made to add a duplicate class to a class dictionary.
DuplicateClientClassDef(const char *file, size_t line, const char *what)
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
boost::shared_ptr< Element > ElementPtr
Definition: data.h:22
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
std::vector< ClientClassDefPtr > ClientClassDefList
Defines a list of ClientClassDefPtr's, using insert order.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:497
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClassDef > ClientClassDefPtr
a pointer to an ClientClassDef
std::list< std::string > builtinPrefixes
List of built-in client class prefixes i.e.
boost::shared_ptr< ClientClassDefMap > ClientClassDefMapPtr
Defines a pointer to a ClientClassDefMap.
boost::shared_ptr< Expression > ExpressionPtr
Definition: token.h:30
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
bool isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
std::list< std::string > builtinNames
List of built-in client class names.
std::unordered_map< std::string, ClientClassDefPtr > ClientClassDefMap
Defines a map of ClientClassDef's, keyed by the class name.
Defines the logger used by the top-level component of kea-dhcp-ddns.
Abstract class for configuration Cfg_* classes.
Base class for user context.
Definition: user_context.h:22