From: Marcin Siodelski Date: Fri, 26 Oct 2018 09:28:10 +0000 (+0200) Subject: [64-client-class-cmds-hook] Control whether class def parser appends position. X-Git-Tag: 66-authoritative-flag-in-kea_base~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08d650e439cd1cee43cc2d0e1ac4ca8a1cb9ad82;p=thirdparty%2Fkea.git [64-client-class-cmds-hook] Control whether class def parser appends position. --- diff --git a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc index 3ac010b3de..00b0d2becd 100644 --- a/src/lib/dhcpsrv/parsers/client_class_def_parser.cc +++ b/src/lib/dhcpsrv/parsers/client_class_def_parser.cc @@ -19,6 +19,7 @@ #include #include +#include using namespace isc::data; using namespace isc::asiolink; @@ -68,7 +69,8 @@ ExpressionParser::parse(ExpressionPtr& expression, void ClientClassDefParser::parse(ClientClassDictionaryPtr& class_dictionary, ConstElementPtr class_def_cfg, - uint16_t family) { + uint16_t family, + bool append_error_position) { // name is now mandatory std::string name = getString(class_def_cfg, "name"); if (name.empty()) { @@ -207,8 +209,13 @@ ClientClassDefParser::parse(ClientClassDictionaryPtr& class_dictionary, depend_on_known, options, defs, user_context, next_server, sname, filename); } catch (const std::exception& ex) { - isc_throw(DhcpConfigError, "Can't add class: " << ex.what() - << " (" << class_def_cfg->getPosition() << ")"); + std::ostringstream s; + s << "Can't add class: " << ex.what(); + // Append position of the error in JSON string if required. + if (append_error_position) { + s << " (" << class_def_cfg->getPosition() << ")"; + } + isc_throw(DhcpConfigError, s.str()); } } diff --git a/src/lib/dhcpsrv/parsers/client_class_def_parser.h b/src/lib/dhcpsrv/parsers/client_class_def_parser.h index f490f08f6c..02c6e0613d 100644 --- a/src/lib/dhcpsrv/parsers/client_class_def_parser.h +++ b/src/lib/dhcpsrv/parsers/client_class_def_parser.h @@ -90,10 +90,16 @@ public: /// @param class_dictionary dictionary into which the class should be added /// @param client_class_def a configuration entry to be parsed. /// @param family the address family of the client class. + /// @param append_error_position Boolean flag indicating if position + /// of the parsed string within parsed JSON should be appended. The + /// default setting is to append it, but it is typically set to false + /// when this parser is used by hooks libraries. /// /// @throw DhcpConfigError if parsing was unsuccessful. void parse(ClientClassDictionaryPtr& class_dictionary, - isc::data::ConstElementPtr client_class_def, uint16_t family); + isc::data::ConstElementPtr client_class_def, + uint16_t family, + bool append_error_position = true); }; /// @brief Defines a pointer to a ClientClassDefParser