 |
Kea
1.5.0
|
Go to the documentation of this file.
12 #include <boost/foreach.hpp>
21 ClientClassDef::ClientClassDef(
const std::string& name,
24 :
name_(name), match_expr_(match_expr), required_(false),
25 depend_on_known_(false), cfg_option_(cfg_option),
44 depend_on_known_(false), cfg_option_(new
CfgOption()),
47 if (rhs.match_expr_) {
49 *match_expr_ = *(rhs.match_expr_);
52 if (rhs.cfg_option_def_) {
53 rhs.cfg_option_def_->copyTo(*cfg_option_def_);
56 if (rhs.cfg_option_) {
57 rhs.cfg_option_->copyTo(*cfg_option_);
60 required_ = rhs.required_;
61 depend_on_known_ = rhs.depend_on_known_;
62 next_server_ = rhs.next_server_;
64 filename_ = rhs.filename_;
87 match_expr_ = match_expr;
107 required_ = required;
112 return (depend_on_known_);
117 depend_on_known_ = depend_on_known;
122 return (cfg_option_def_);
127 cfg_option_def_ = cfg_option_def;
132 return (cfg_option_);
137 cfg_option_ = cfg_option;
147 return ((name_ == other.name_) &&
148 ((!match_expr_ && !other.match_expr_) ||
149 (match_expr_ && other.match_expr_ &&
150 (*match_expr_ == *(other.match_expr_)))) &&
151 ((!cfg_option_ && !other.cfg_option_) ||
152 (cfg_option_ && other.cfg_option_ &&
153 (*cfg_option_ == *other.cfg_option_))) &&
154 ((!cfg_option_def_ && !other.cfg_option_def_) ||
155 (cfg_option_def_ && other.cfg_option_def_ &&
156 (*cfg_option_def_ == *other.cfg_option_def_))) &&
157 (required_ == other.required_) &&
158 (depend_on_known_ == other.depend_on_known_) &&
159 (next_server_ == other.next_server_) &&
160 (sname_ == other.sname_) &&
161 (filename_ == other.filename_));
171 result->set(
"name", Element::create(name_));
173 if (!test_.empty()) {
174 result->set(
"test", Element::create(test_));
178 result->set(
"only-if-required", Element::create(required_));
181 if (cfg_option_def_ && (family == AF_INET)) {
182 result->set(
"option-def", cfg_option_def_->toElement());
185 result->set(
"option-data", cfg_option_->toElement());
186 if (family != AF_INET) {
191 result->set(
"next-server", Element::create(next_server_.
toText()));
193 result->set(
"server-hostname", Element::create(sname_));
195 result->set(
"boot-file-name", Element::create(filename_));
200 os <<
"ClientClassDef:" << x.
getName();
224 const std::string& test,
226 bool depend_on_known,
231 const std::string& sname,
232 const std::string& filename) {
234 cclass->setTest(test);
235 cclass->setRequired(required);
236 cclass->setDependOnKnown(depend_on_known);
237 cclass->setCfgOptionDef(cfg_option_def);
238 cclass->setContext(user_context),
239 cclass->setNextServer(next_server);
240 cclass->setSname(sname);
241 cclass->setFilename(filename);
249 " - class definition cannot be null");
254 << class_def->getName() <<
" has already been defined");
257 list_->push_back(class_def);
258 (*map_)[class_def->getName()] = class_def;
263 ClientClassDefMap::iterator it = map_->find(name);
264 if (it != map_->end()) {
273 for (ClientClassDefList::iterator this_class = list_->begin();
274 this_class != list_->end(); ++this_class) {
275 if ((*this_class)->getName() == name) {
276 list_->erase(this_class);
290 std::string& dependent_class)
const {
293 for (ClientClassDefList::iterator this_class = list_->begin();
294 this_class != list_->end(); ++this_class) {
296 if ((*this_class)->dependOnClass(name)) {
297 dependent_class = (*this_class)->getName();
301 if ((*this_class)->getName() == name) {
311 if (list_->size() != other.list_->size()) {
315 ClientClassDefList::const_iterator this_class = list_->cbegin();
316 ClientClassDefList::const_iterator other_class = other.list_->cbegin();
317 while (this_class != list_->cend() &&
318 other_class != other.list_->cend()) {
319 if (!*this_class || !*other_class ||
320 **this_class != **other_class) {
335 for (ClientClassDefList::const_iterator this_class = list_->begin();
336 this_class != list_->cend(); ++this_class) {
337 result->add((*this_class)->toElement());
342 std::list<std::string>
344 "ALL",
"KNOWN",
"UNKNOWN"
347 std::list<std::string>
349 "VENDOR_CLASS_",
"HA_",
"AFTER_",
"EXTERNAL_"
354 for (std::list<std::string>::const_iterator bn =
builtinNames.cbegin();
356 if (client_class == *bn) {
361 for (std::list<std::string>::const_iterator bt =
builtinPrefixes.cbegin();
363 if (client_class.size() <= bt->size()) {
366 auto mis = std::mismatch(bt->cbegin(), bt->cend(), client_class.cbegin());
367 if (mis.first == bt->cend()) {
377 bool& depend_on_known,
382 if ((client_class ==
"KNOWN") || (client_class ==
"UNKNOWN")) {
383 depend_on_known =
true;
392 if (def->getDependOnKnown()) {
393 depend_on_known =
true;
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< ClientClassDictionary > ClientClassDictionaryPtr
Defines a pointer to a ClientClassDictionary.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< Expression > ExpressionPtr
void setCfgOption(const CfgOptionPtr &cfg_option)
Sets the class's option collection.
static CfgMgr & instance()
returns a single instance of Configuration Manager
std::vector< ClientClassDefPtr > ClientClassDefList
Defines a list of ClientClassDefPtr's, using insert order.
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
~ClientClassDictionary()
Destructor.
bool isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
Maintains a list of ClientClassDef's.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
void setCfgOptionDef(const CfgOptionDefPtr &cfg_option_def)
Sets the class's option definition collection.
The IOAddress class represents an IP addresses (version agnostic)
bool equals(const ClientClassDef &other) const
Compares two ClientClassDef objects for equality.
virtual ~ClientClassDef()
Destructor.
std::string getTest() const
Fetches the class's original match expression.
void setRequired(bool required)
Sets the only if required flag.
void setTest(const std::string &test)
Sets the class's original match expression.
const ExpressionPtr & getMatchExpr() const
Fetches the class's match expression.
bool dependOnClass(const TokenPtr &token, const std::string &name)
Checks dependency on a token.
bool getRequired() const
Fetches the only if required flag.
ClientClassDictionary()
Constructor.
bool dependOnClass(const std::string &name) const
Checks direct dependency.
Error that occurs when an attempt is made to add a duplicate class to a class dictionary.
Represents option data configuration for the DHCP server.
void setDependOnKnown(bool depend_on_known)
Sets the depend on known flag aka use host flag.
void setMatchExpr(const ExpressionPtr &match_expr)
Sets the class's match expression.
const CfgOptionDefPtr & getCfgOptionDef() const
Fetches the class's option definitions.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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
std::string getName() const
Fetches the class's name.
void setName(const std::string &name)
Sets the class's name.
uint16_t getFamily() const
Returns address family.
bool equals(const ClientClassDictionary &other) const
Compares two ClientClassDictionary objects for equality.
ClientClassDef(const std::string &name, const ExpressionPtr &match_expr, const CfgOptionPtr &options=CfgOptionPtr())
Constructor.
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.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
bool dependOnClass(const std::string &name, std::string &dependent_class) const
Checks direct dependency.
std::string toText() const
Convert the address to a string.
A wrapper interface for the ASIO library.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
const ClientClassDefListPtr & getClasses() const
Fetches the dictionary's list of classes.
std::string ClientClass
Defines a single class name.
bool getDependOnKnown() const
Fetches the depend on known flag aka use host flag.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
boost::shared_ptr< Element > ElementPtr
boost::shared_ptr< const Element > ConstElementPtr
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
Defines classes for storing client class definitions.
void removeClass(const std::string &name)
Removes a given class definition from the dictionary.
std::unordered_map< std::string, ClientClassDefPtr > ClientClassDefMap
Defines a map of ClientClassDef's, keyed by the class name.
ClientClassDefPtr findClass(const std::string &name) const
Fetches the class definition for a given class name.
const CfgOptionPtr & getCfgOption() const
Fetches the class's option collection.
boost::shared_ptr< ClientClassDefList > ClientClassDefListPtr
Defines a pointer to a ClientClassDefList.
Embodies a single client class definition.