13#include <boost/foreach.hpp>
28 match_expr_(match_expr), required_(false), depend_on_known_(false),
30 valid_(), preferred_() {
47 match_expr_(
ExpressionPtr()), test_(rhs.test_), required_(rhs.required_),
48 depend_on_known_(rhs.depend_on_known_), cfg_option_(new
CfgOption()),
49 next_server_(rhs.next_server_), sname_(rhs.sname_),
50 filename_(rhs.filename_), valid_(rhs.valid_), preferred_(rhs.preferred_) {
52 if (rhs.match_expr_) {
54 *match_expr_ = *(rhs.match_expr_);
57 if (rhs.cfg_option_def_) {
59 rhs.cfg_option_def_->copyTo(*cfg_option_def_);
62 if (rhs.cfg_option_) {
63 rhs.cfg_option_->copyTo(*cfg_option_);
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_));
173 if (!test_.empty()) {
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());
187 if (family == AF_INET) {
199 result->set(
"preferred-lifetime",
203 if (preferred_.
getMin() < preferred_.
get()) {
204 result->set(
"min-preferred-lifetime",
208 if (preferred_.
getMax() > preferred_.
get()) {
209 result->set(
"max-preferred-lifetime",
216 result->set(
"valid-lifetime",
220 result->set(
"min-valid-lifetime",
225 result->set(
"max-valid-lifetime",
234 os <<
"ClientClassDef:" << x.
getName();
258 const std::string& test,
260 bool depend_on_known,
265 const std::string& sname,
266 const std::string& filename,
270 cclass->setTest(test);
271 cclass->setRequired(required);
272 cclass->setDependOnKnown(depend_on_known);
273 cclass->setCfgOptionDef(cfg_option_def);
274 cclass->setContext(user_context),
275 cclass->setNextServer(next_server);
276 cclass->setSname(sname);
277 cclass->setFilename(filename);
278 cclass->setValid(valid);
279 cclass->setPreferred(preferred);
287 " - class definition cannot be null");
292 << class_def->getName() <<
" has already been defined");
295 list_->push_back(class_def);
296 (*map_)[class_def->getName()] = class_def;
301 ClientClassDefMap::iterator it = map_->find(name);
302 if (it != map_->end()) {
311 for (ClientClassDefList::iterator this_class = list_->begin();
312 this_class != list_->end(); ++this_class) {
313 if ((*this_class)->getName() == name) {
314 list_->erase(this_class);
327 for (ClientClassDefList::iterator this_class = list_->begin();
328 this_class != list_->end(); ++this_class) {
329 if ((*this_class)->getId() ==
id) {
330 map_->erase((*this_class)->getName());
331 list_->erase(this_class);
344 return (list_->empty());
349 std::string& dependent_class)
const {
352 for (ClientClassDefList::iterator this_class = list_->begin();
353 this_class != list_->end(); ++this_class) {
355 if ((*this_class)->dependOnClass(name)) {
356 dependent_class = (*this_class)->getName();
360 if ((*this_class)->getName() == name) {
370 if (list_->size() != other.list_->size()) {
374 ClientClassDefList::const_iterator this_class = list_->cbegin();
375 ClientClassDefList::const_iterator other_class = other.list_->cbegin();
376 while (this_class != list_->cend() &&
377 other_class != other.list_->cend()) {
378 if (!*this_class || !*other_class ||
379 **this_class != **other_class) {
392 std::queue<ExpressionPtr> expressions;
393 for (
auto c : *list_) {
394 if (!c->getTest().empty()) {
398 expressions.push(match_expr);
403 for (
auto c : *list_) {
404 if (!c->getTest().empty()) {
405 c->setMatchExpr(expressions.front());
413 for (
auto c : *list_) {
416 if (!class_options || class_options->empty()) {
423 if (!c->getCfgOptionDef()) {
424 class_options->createOptions(external_defs);
434 c->getCfgOptionDef()->copyTo(*composite_defs);
441 external_defs->copyTo(*external_defs_copy);
442 composite_defs->merge(*external_defs_copy);
446 class_options->createOptions(composite_defs);
455 for (ClientClassDefList::const_iterator this_class = list_->begin();
456 this_class != list_->cend(); ++this_class) {
457 result->add((*this_class)->toElement());
467 for (
auto cclass : *(rhs.list_)) {
476std::list<std::string>
484 "ALL",
"KNOWN",
"UNKNOWN",
"BOOTP"
487std::list<std::string>
489 "VENDOR_CLASS_",
"HA_",
"AFTER_",
"EXTERNAL_"
494 for (std::list<std::string>::const_iterator bn =
builtinNames.cbegin();
496 if (client_class == *bn) {
501 for (std::list<std::string>::const_iterator bt =
builtinPrefixes.cbegin();
503 if (client_class.size() <= bt->size()) {
506 auto mis = std::mismatch(bt->cbegin(), bt->cend(), client_class.cbegin());
507 if (mis.first == bt->cend()) {
517 bool& depend_on_known,
522 if ((client_class ==
"KNOWN") || (client_class ==
"UNKNOWN")) {
523 depend_on_known =
true;
532 if (def->getDependOnKnown()) {
533 depend_on_known =
true;
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
static ElementPtr create(const Position &pos=ZERO_POSITION())
static ElementPtr createMap(const Position &pos=ZERO_POSITION())
Creates an empty MapElement type ElementPtr.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
This class represents configuration element which is associated with database identifier,...
uint16_t getFamily() const
Returns address family.
static CfgMgr & instance()
returns a single instance of Configuration Manager
Represents option definitions used by the DHCP server.
Represents option data configuration for the DHCP server.
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 setRequired(bool required)
Sets the only if required flag.
const CfgOptionDefPtr & getCfgOptionDef() const
Fetches the class's option definitions.
ClientClassDef(const std::string &name, const ExpressionPtr &match_expr, const CfgOptionPtr &options=CfgOptionPtr())
Constructor.
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.
std::string getName() const
Fetches the class's name.
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.
Maintains a list of ClientClassDef's.
ClientClassDefPtr findClass(const std::string &name) const
Fetches the class definition for a given class name.
bool equals(const ClientClassDictionary &other) const
Compares two ClientClassDictionary objects for equality.
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 util::Triplet< uint32_t > &valid=util::Triplet< uint32_t >(), const util::Triplet< uint32_t > &preferred=util::Triplet< uint32_t >())
Adds a new class to the list.
void removeClass(const std::string &name)
Removes a given class definition from the dictionary.
bool empty() const
Checks if the class dictionary is empty.
bool dependOnClass(const std::string &name, std::string &dependent_class) const
Checks direct dependency.
ClientClassDictionary()
Constructor.
const ClientClassDefListPtr & getClasses() const
Fetches the dictionary's list of classes.
ClientClassDictionary & operator=(const ClientClassDictionary &rhs)
Copy assignment operator.
~ClientClassDictionary()
Destructor.
void createOptions(const CfgOptionDefPtr &cfg_option_def)
Iterates over the classes in the dictionary and recreates the options.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void initMatchExpr(uint16_t family)
Iterates over the classes in the dictionary and ensures that that match expressions are initialized.
Error that occurs when an attempt is made to add a duplicate class to a class dictionary.
Parser for a logical expression.
void parse(ExpressionPtr &expression, isc::data::ConstElementPtr expression_cfg, uint16_t family, isc::eval::EvalContext::CheckDefined check_defined=isc::eval::EvalContext::acceptAll)
Parses an expression configuration element into an Expression.
void unspecified(bool unspecified)
Modifies the flag that indicates whether the value is specified or unspecified.
T get(T hint) const
Returns value with a hint.
T getMax() const
Returns a maximum allowed value.
T getMin() const
Returns a minimum allowed value.
Defines classes for storing client class definitions.
Parsers for client class definitions.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A wrapper interface for the ASIO library.
ElementPtr copy(ConstElementPtr from, int level)
Copy the data up to a nesting level.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
std::string ClientClass
Defines a single class name.
std::vector< ClientClassDefPtr > ClientClassDefList
Defines a list of ClientClassDefPtr's, using insert order.
boost::shared_ptr< CfgOption > CfgOptionPtr
Non-const pointer.
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.
std::ostream & operator<<(std::ostream &os, const OpaqueDataTuple &tuple)
Inserts the OpaqueDataTuple as a string into stream.
boost::shared_ptr< Expression > ExpressionPtr
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.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
bool isClientClassBuiltIn(const ClientClass &client_class)
Check if a client class name is builtin.
bool dependOnClass(const TokenPtr &token, const std::string &name)
Checks dependency on a token.
std::list< std::string > builtinNames
List of classes for which test expressions cannot be defined.
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-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.