Kea  1.9.9-git
client_class_def.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2021 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 <dhcpsrv/triplet.h>
15 #include <eval/token.h>
16 #include <exceptions/exceptions.h>
17 
18 #include <string>
19 #include <unordered_map>
20 #include <list>
21 #include <vector>
22 
35 namespace isc {
36 namespace dhcp {
37 
41 public:
42  DuplicateClientClassDef(const char* file, size_t line, const char* what)
43  : isc::Exception(file, line, what) {}
44 };
45 
48 public:
54  ClientClassDef(const std::string& name, const ExpressionPtr& match_expr,
55  const CfgOptionPtr& options = CfgOptionPtr());
56 
57 
59  ClientClassDef(const ClientClassDef& rhs);
60 
62  virtual ~ClientClassDef();
63 
65  std::string getName() const;
66 
70  void setName(const std::string& name);
71 
73  const ExpressionPtr& getMatchExpr() const;
74 
78  void setMatchExpr(const ExpressionPtr& match_expr);
79 
81  std::string getTest() const;
82 
86  void setTest(const std::string& test);
87 
89  bool getRequired() const;
90 
94  void setRequired(bool required);
95 
97  bool getDependOnKnown() const;
98 
102  void setDependOnKnown(bool depend_on_known);
103 
105  const CfgOptionDefPtr& getCfgOptionDef() const;
106 
110  void setCfgOptionDef(const CfgOptionDefPtr& cfg_option_def);
111 
113  const CfgOptionPtr& getCfgOption() const;
114 
118  void setCfgOption(const CfgOptionPtr& cfg_option);
119 
125  bool dependOnClass(const std::string& name) const;
126 
132  bool equals(const ClientClassDef& other) const;
133 
139  bool operator==(const ClientClassDef& other) const {
140  return (equals(other));
141  }
142 
148  bool operator!=(const ClientClassDef& other) const {
149  return (!(equals(other)));
150  }
151 
153  friend std::ostream& operator<<(std::ostream& os, const ClientClassDef& x);
154 
158  return (next_server_);
159  }
160 
164  void setNextServer(const asiolink::IOAddress& addr) {
165  next_server_ = addr;
166  }
167 
171  void setSname(const std::string& sname) {
172  sname_ = sname;
173  }
174 
177  const std::string& getSname() const {
178  return (sname_);
179  }
180 
184  void setFilename(const std::string& filename) {
185  filename_ = filename;
186  }
187 
190  const std::string& getFilename() const {
191  return (filename_);
192  }
193 
198  return (valid_);
199  }
200 
204  void setValid(const Triplet<uint32_t>& valid) {
205  valid_ = valid;
206  }
207 
211  virtual isc::data::ElementPtr toElement() const;
212 
213 private:
215  std::string name_;
216 
219  ExpressionPtr match_expr_;
220 
223  std::string test_;
224 
229  bool required_;
230 
239  bool depend_on_known_;
240 
242  CfgOptionDefPtr cfg_option_def_;
243 
245  CfgOptionPtr cfg_option_;
246 
250  asiolink::IOAddress next_server_;
251 
256  std::string sname_;
257 
262  std::string filename_;
263 
265  Triplet<uint32_t> valid_;
266 };
267 
269 typedef boost::shared_ptr<ClientClassDef> ClientClassDefPtr;
270 
272 typedef std::unordered_map<std::string, ClientClassDefPtr> ClientClassDefMap;
273 
275 typedef boost::shared_ptr<ClientClassDefMap> ClientClassDefMapPtr;
276 
278 typedef std::vector<ClientClassDefPtr> ClientClassDefList;
279 
281 typedef boost::shared_ptr<ClientClassDefList> ClientClassDefListPtr;
282 
285 
286 public:
289 
291 
294 
313  void addClass(const std::string& name, const ExpressionPtr& match_expr,
314  const std::string& test, bool required, bool depend_on_known,
315  const CfgOptionPtr& options,
318  asiolink::IOAddress next_server = asiolink::IOAddress("0.0.0.0"),
319  const std::string& sname = std::string(),
320  const std::string& filename = std::string(),
321  const Triplet<uint32_t>&valid = Triplet<uint32_t>());
322 
329  void addClass(ClientClassDefPtr& class_def);
330 
337  ClientClassDefPtr findClass(const std::string& name) const;
338 
345  void removeClass(const std::string& name);
346 
350  const ClientClassDefListPtr& getClasses() const;
351 
359  bool dependOnClass(const std::string& name, std::string& dependent_class) const;
360 
366  bool equals(const ClientClassDictionary& other) const;
367 
373  bool operator==(const ClientClassDictionary& other) const {
374  return (equals(other));
375  }
376 
382  bool operator!=(const ClientClassDictionary& other) const {
383  return (!equals(other));
384  }
385 
389  virtual isc::data::ElementPtr toElement() const;
390 
391 private:
392 
394  ClientClassDefMapPtr map_;
395 
397  ClientClassDefListPtr list_;
398 };
399 
401 typedef boost::shared_ptr<ClientClassDictionary> ClientClassDictionaryPtr;
402 
405 extern std::list<std::string> builtinNames;
406 
409 extern std::list<std::string> builtinPrefixes;
410 
415 bool isClientClassBuiltIn(const ClientClass& client_class);
416 
417 
429 bool isClientClassDefined(ClientClassDictionaryPtr& class_dictionary,
430  bool& depend_on_known,
431  const ClientClass& client_class);
432 
433 } // namespace isc::dhcp
434 } // namespace isc
435 
436 #endif // CLIENT_CLASS_DEF_H
void setMatchExpr(const ExpressionPtr &match_expr)
Sets the class's match expression.
const ExpressionPtr & getMatchExpr() const
Fetches the class's match expression.
ClientClassDefPtr findClass(const std::string &name) const
Fetches the class definition for a given class name.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:706
void setDependOnKnown(bool depend_on_known)
Sets the depend on known flag aka use host flag.
const std::string & getSname() const
returns server-hostname value
Triplet< uint32_t > getValid() const
Return valid-lifetime value.
bool operator!=(const ClientClassDictionary &other) const
Inequality operator.
Base class for user context.
Definition: user_context.h:22
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void setRequired(bool required)
Sets the only if required flag.
std::string getTest() const
Fetches the class's original match expression.
std::unordered_map< std::string, ClientClassDefPtr > ClientClassDefMap
Defines a map of ClientClassDef's, keyed by the class name.
void setValid(const Triplet< uint32_t > &valid)
Sets new valid lifetime.
void setFilename(const std::string &filename)
sets the boot-file-name value
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
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(), const Triplet< uint32_t > &valid=Triplet< uint32_t >())
Adds a new class to the list.
bool equals(const ClientClassDictionary &other) const
Compares two ClientClassDictionary objects for equality.
bool getDependOnKnown() const
Fetches the depend on known flag aka use host flag.
const CfgOptionDefPtr & getCfgOptionDef() const
Fetches the class's option definitions.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClassDefMap > ClientClassDefMapPtr
Defines a pointer to a ClientClassDefMap.
bool equals(const ClientClassDef &other) const
Compares two ClientClassDef objects for equality.
void setTest(const std::string &test)
Sets the class's original match expression.
Maintains a list of ClientClassDef's.
bool getRequired() const
Fetches the only if required flag.
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
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 CfgOptionPtr & getCfgOption() const
Fetches the class's option collection.
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
bool dependOnClass(const std::string &name, std::string &dependent_class) const
Checks direct dependency.
bool operator==(const ClientClassDef &other) const
Equality operator.
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.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
boost::shared_ptr< ClientClassDef > ClientClassDefPtr
a pointer to an ClientClassDef
const std::string & getFilename() const
returns boot-file-name value
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.
bool operator==(const ClientClassDictionary &other) const
Equality operator.
const asiolink::IOAddress & getNextServer() const
returns next-server value
virtual ~ClientClassDef()
Destructor.
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
bool operator!=(const ClientClassDef &other) const
Inequality operator.
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 ClientClassDefListPtr & getClasses() const
Fetches the dictionary's list of classes.
bool dependOnClass(const std::string &name) const
Checks direct dependency.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
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.
std::string getName() const
Fetches the class's name.
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.
boost::shared_ptr< Expression > ExpressionPtr
Definition: token.h:30
void setCfgOptionDef(const CfgOptionDefPtr &cfg_option_def)
Sets the class's option definition collection.