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>
13 #include <dhcpsrv/cfg_option_def.h>
14 #include <eval/token.h>
15 #include <exceptions/exceptions.h>
16 
17 #include <string>
18 #include <unordered_map>
19 #include <list>
20 #include <vector>
21 
34 namespace isc {
35 namespace dhcp {
36 
40 public:
41  DuplicateClientClassDef(const char* file, size_t line, const char* what)
42  : isc::Exception(file, line, what) {}
43 };
44 
47 public:
53  ClientClassDef(const std::string& name, const ExpressionPtr& match_expr,
54  const CfgOptionPtr& options = CfgOptionPtr());
55 
56 
58  ClientClassDef(const ClientClassDef& rhs);
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 
163  void setNextServer(const asiolink::IOAddress& addr) {
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 
198 private:
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 
252 typedef boost::shared_ptr<ClientClassDef> ClientClassDefPtr;
253 
255 typedef std::unordered_map<std::string, ClientClassDefPtr> ClientClassDefMap;
256 
258 typedef boost::shared_ptr<ClientClassDefMap> ClientClassDefMapPtr;
259 
261 typedef std::vector<ClientClassDefPtr> ClientClassDefList;
262 
264 typedef boost::shared_ptr<ClientClassDefList> ClientClassDefListPtr;
265 
268 
269 public:
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 
372 private:
373 
376 
378  ClientClassDefListPtr list_;
379 };
380 
382 typedef boost::shared_ptr<ClientClassDictionary> ClientClassDictionaryPtr;
383 
386 extern std::list<std::string> builtinNames;
387 
390 extern std::list<std::string> builtinPrefixes;
391 
396 bool isClientClassBuiltIn(const ClientClass& client_class);
397 
398 
410 bool isClientClassDefined(ClientClassDictionaryPtr& class_dictionary,
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
void setMatchExpr(const ExpressionPtr &match_expr)
Sets the class's match expression.
bool dependOnClass(const std::string &name, std::string &dependent_class) const
Checks direct dependency.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:497
const CfgOptionDefPtr & getCfgOptionDef() const
Fetches the class's option definitions.
void setDependOnKnown(bool depend_on_known)
Sets the depend on known flag aka use host flag.
bool dependOnClass(const std::string &name) const
Checks direct dependency.
ClientClassDefPtr findClass(const std::string &name) const
Fetches the class definition for a given class name.
bool operator==(const ClientClassDictionary &other) const
Equality operator.
Base class for user context.
Definition: user_context.h:22
void setRequired(bool required)
Sets the only if required flag.
const ClientClassDefListPtr & getClasses() const
Fetches the dictionary's list of classes.
std::unordered_map< std::string, ClientClassDefPtr > ClientClassDefMap
Defines a map of ClientClassDef's, keyed by the class name.
void setFilename(const std::string &filename)
sets the boot-file-name value
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
const asiolink::IOAddress & getNextServer() const
returns next-server value
std::string getName() const
Fetches the class's name.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClassDefMap > ClientClassDefMapPtr
Defines a pointer to a ClientClassDefMap.
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.
void setTest(const std::string &test)
Sets the class's original match expression.
bool equals(const ClientClassDef &other) const
Compares two ClientClassDef objects for equality.
Maintains a list of ClientClassDef's.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
const CfgOptionPtr & getCfgOption() const
Fetches the class's option collection.
bool operator==(const ClientClassDef &other) const
Equality operator.
DuplicateClientClassDef(const char *file, size_t line, const char *what)
Error that occurs when an attempt is made to add a duplicate class to a class dictionary.
const std::string & getFilename() const
returns boot-file-name value
Abstract class for configuration Cfg_* classes.
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
Embodies a single client class definition.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
std::string getTest() const
Fetches the class's original match expression.
std::list< std::string > builtinNames
List of built-in client class names.
std::list< std::string > builtinPrefixes
List of built-in client class prefixes i.e.
boost::shared_ptr< ClientClassDef > ClientClassDefPtr
a pointer to an ClientClassDef
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
std::vector< ClientClassDefPtr > ClientClassDefList
Defines a list of ClientClassDefPtr's, using insert order.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual ~ClientClassDef()
Destructor.
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
void setSname(const std::string &sname)
sets the server-name value
void removeClass(const std::string &name)
Removes a given class definition from the dictionary.
const ExpressionPtr & getMatchExpr() const
Fetches the class's match expression.
bool getRequired() const
Fetches the only if required flag.
bool operator!=(const ClientClassDictionary &other) const
Inequality operator.
bool operator!=(const ClientClassDef &other) const
Inequality operator.
void setName(const std::string &name)
Sets the class's name.
void setNextServer(const asiolink::IOAddress &addr)
sets the next-server value
void setCfgOption(const CfgOptionPtr &cfg_option)
Sets the class's option collection.
ClientClassDef(const std::string &name, const ExpressionPtr &match_expr, const CfgOptionPtr &options=CfgOptionPtr())
Constructor.
bool isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
friend std::ostream & operator<<(std::ostream &os, const ClientClassDef &x)
Provides a convenient text representation of the class.
bool getDependOnKnown() const
Fetches the depend on known flag aka use host flag.
boost::shared_ptr< Expression > ExpressionPtr
Definition: token.h:30
bool equals(const ClientClassDictionary &other) const
Compares two ClientClassDictionary objects for equality.
const std::string & getSname() const
returns server-hostname value
void setCfgOptionDef(const CfgOptionDefPtr &cfg_option_def)
Sets the class's option definition collection.