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
isc::dhcp::CfgOptionDefPtr
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
Definition: cfg_option_def.h:139
isc::dhcp::ClientClassDefMapPtr
boost::shared_ptr< ClientClassDefMap > ClientClassDefMapPtr
Defines a pointer to a ClientClassDefMap.
Definition: client_class_def.h:258
isc::dhcp::ClientClassDef::getNextServer
const asiolink::IOAddress & getNextServer() const
returns next-server value
Definition: client_class_def.h:156
isc::dhcp::ClientClassDictionaryPtr
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
Definition: client_class_def.h:382
isc::dhcp::ExpressionPtr
boost::shared_ptr< Expression > ExpressionPtr
Definition: token.h:30
isc::dhcp::ClientClassDef::setCfgOption
void setCfgOption(const CfgOptionPtr &cfg_option)
Sets the class's option collection.
Definition: client_class_def.cc:136
isc::dhcp::ClientClassDef::setNextServer
void setNextServer(const asiolink::IOAddress &addr)
sets the next-server value
Definition: client_class_def.h:163
isc::dhcp::ClientClassDefList
std::vector< ClientClassDefPtr > ClientClassDefList
Defines a list of ClientClassDefPtr's, using insert order.
Definition: client_class_def.h:261
isc::dhcp::isClientClassDefined
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
Definition: client_class_def.cc:376
user_context.h
isc::dhcp::ClientClassDictionary::~ClientClassDictionary
~ClientClassDictionary()
Destructor.
Definition: client_class_def.cc:218
isc::dhcp::isClientClassBuiltIn
bool isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
Definition: client_class_def.cc:353
isc::dhcp::ClientClassDictionary
Maintains a list of ClientClassDef's.
Definition: client_class_def.h:267
isc::dhcp::ClientClassDef::setCfgOptionDef
void setCfgOptionDef(const CfgOptionDefPtr &cfg_option_def)
Sets the class's option definition collection.
Definition: client_class_def.cc:126
isc::dhcp::ClientClassDef::equals
bool equals(const ClientClassDef &other) const
Compares two ClientClassDef objects for equality.
Definition: client_class_def.cc:146
isc::dhcp::ClientClassDef::~ClientClassDef
virtual ~ClientClassDef()
Destructor.
Definition: client_class_def.cc:67
isc::data::CfgToElement
Abstract class for configuration Cfg_* classes.
Definition: cfg_to_element.h:29
isc::dhcp::DuplicateClientClassDef::DuplicateClientClassDef
DuplicateClientClassDef(const char *file, size_t line, const char *what)
Definition: client_class_def.h:41
isc::dhcp::ClientClassDef::getTest
std::string getTest() const
Fetches the class's original match expression.
Definition: client_class_def.cc:91
isc::dhcp::ClientClassDef::operator<<
friend std::ostream & operator<<(std::ostream &os, const ClientClassDef &x)
Provides a convenient text representation of the class.
Definition: client_class_def.cc:199
isc::dhcp::ClientClassDef::setRequired
void setRequired(bool required)
Sets the only if required flag.
Definition: client_class_def.cc:106
isc::dhcp::ClientClassDef::setTest
void setTest(const std::string &test)
Sets the class's original match expression.
Definition: client_class_def.cc:96
isc::dhcp::ClientClassDef::getMatchExpr
const ExpressionPtr & getMatchExpr() const
Fetches the class's match expression.
Definition: client_class_def.cc:81
isc::data::UserContext
Base class for user context.
Definition: user_context.h:22
isc::dhcp::ClientClassDef::getRequired
bool getRequired() const
Fetches the only if required flag.
Definition: client_class_def.cc:101
isc::dhcp::ClientClassDef::setSname
void setSname(const std::string &sname)
sets the server-name value
Definition: client_class_def.h:170
isc::dhcp::ClientClassDictionary::ClientClassDictionary
ClientClassDictionary()
Constructor.
Definition: client_class_def.cc:206
isc::dhcp::ClientClassDef::dependOnClass
bool dependOnClass(const std::string &name) const
Checks direct dependency.
Definition: client_class_def.cc:141
isc::dhcp::DuplicateClientClassDef
Error that occurs when an attempt is made to add a duplicate class to a class dictionary.
Definition: client_class_def.h:39
isc::dhcp::ClientClassDef::getSname
const std::string & getSname() const
returns server-hostname value
Definition: client_class_def.h:176
isc::dhcp::ClientClassDef::operator==
bool operator==(const ClientClassDef &other) const
Equality operator.
Definition: client_class_def.h:138
isc::dhcp::ClientClassDef::setDependOnKnown
void setDependOnKnown(bool depend_on_known)
Sets the depend on known flag aka use host flag.
Definition: client_class_def.cc:116
isc::dhcp::ClientClassDef::setMatchExpr
void setMatchExpr(const ExpressionPtr &match_expr)
Sets the class's match expression.
Definition: client_class_def.cc:86
isc::dhcp::ClientClassDef::getCfgOptionDef
const CfgOptionDefPtr & getCfgOptionDef() const
Fetches the class's option definitions.
Definition: client_class_def.cc:121
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::dhcp::ClientClassDef::toElement
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: client_class_def.cc:165
isc::dhcp::ClientClassDictionary::operator!=
bool operator!=(const ClientClassDictionary &other) const
Inequality operator.
Definition: client_class_def.h:363
isc::dhcp::builtinNames
std::list< std::string > builtinNames
List of built-in client class names.
Definition: client_class_def.cc:343
isc::dhcp::builtinPrefixes
std::list< std::string > builtinPrefixes
List of built-in client class prefixes i.e.
Definition: client_class_def.cc:348
isc::dhcp::ClientClassDef::getFilename
const std::string & getFilename() const
returns boot-file-name value
Definition: client_class_def.h:189
isc::dhcp::ClientClassDefPtr
boost::shared_ptr< ClientClassDef > ClientClassDefPtr
a pointer to an ClientClassDef
Definition: client_class_def.h:252
isc::dhcp::ClientClassDef::getName
std::string getName() const
Fetches the class's name.
Definition: client_class_def.cc:71
cfg_option.h
isc::dhcp::ClientClassDef::setName
void setName(const std::string &name)
Sets the class's name.
Definition: client_class_def.cc:76
isc::dhcp::ClientClassDictionary::operator==
bool operator==(const ClientClassDictionary &other) const
Equality operator.
Definition: client_class_def.h:354
isc::dhcp::ClientClassDef::operator!=
bool operator!=(const ClientClassDef &other) const
Inequality operator.
Definition: client_class_def.h:147
isc::dhcp::ClientClassDictionary::equals
bool equals(const ClientClassDictionary &other) const
Compares two ClientClassDictionary objects for equality.
Definition: client_class_def.cc:310
isc::dhcp::ClientClassDef::ClientClassDef
ClientClassDef(const std::string &name, const ExpressionPtr &match_expr, const CfgOptionPtr &options=CfgOptionPtr())
Constructor.
Definition: client_class_def.cc:21
isc::dhcp::ClientClassDictionary::addClass
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.
Definition: client_class_def.cc:222
isc::dhcp::ClientClassDictionary::toElement
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: client_class_def.cc:332
isc::dhcp::ClientClassDictionary::dependOnClass
bool dependOnClass(const std::string &name, std::string &dependent_class) const
Checks direct dependency.
Definition: client_class_def.cc:289
cfg_to_element.h
isc::dhcp::ClientClassDictionary::getClasses
const ClientClassDefListPtr & getClasses() const
Fetches the dictionary's list of classes.
Definition: client_class_def.cc:284
isc::dhcp::ClientClass
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
cfg_option_def.h
exceptions.h
isc::dhcp::ClientClassDef::getDependOnKnown
bool getDependOnKnown() const
Fetches the depend on known flag aka use host flag.
Definition: client_class_def.cc:111
isc::dhcp::CfgOptionPtr
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
Definition: cfg_option.h:497
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
isc::dhcp::ClientClassDictionary::removeClass
void removeClass(const std::string &name)
Removes a given class definition from the dictionary.
Definition: client_class_def.cc:272
isc::dhcp::ClientClassDefMap
std::unordered_map< std::string, ClientClassDefPtr > ClientClassDefMap
Defines a map of ClientClassDef's, keyed by the class name.
Definition: client_class_def.h:255
token.h
isc::dhcp::ClientClassDictionary::findClass
ClientClassDefPtr findClass(const std::string &name) const
Fetches the class definition for a given class name.
Definition: client_class_def.cc:262
isc::dhcp::ClientClassDef::setFilename
void setFilename(const std::string &filename)
sets the boot-file-name value
Definition: client_class_def.h:183
isc::dhcp::ClientClassDef::getCfgOption
const CfgOptionPtr & getCfgOption() const
Fetches the class's option collection.
Definition: client_class_def.cc:131
isc::dhcp::ClientClassDefListPtr
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
Definition: client_class_def.h:264
isc::dhcp::ClientClassDef
Embodies a single client class definition.
Definition: client_class_def.h:46