]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[64-client-class-cmds-hook] Control whether class def parser appends position.
authorMarcin Siodelski <marcin@isc.org>
Fri, 26 Oct 2018 09:28:10 +0000 (11:28 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 5 Nov 2018 16:38:48 +0000 (11:38 -0500)
src/lib/dhcpsrv/parsers/client_class_def_parser.cc
src/lib/dhcpsrv/parsers/client_class_def_parser.h

index 3ac010b3de4bbd17f8bc1d4e5d9cb94e772b93dd..00b0d2becd5c220ecf443d2800eb88608f304047 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <boost/foreach.hpp>
 #include <algorithm>
+#include <sstream>
 
 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());
     }
 }
 
index f490f08f6c47f724048a010c01ecca95ec2aea22..02c6e0613d800f8fe50009ca677010cb9b4230cc 100644 (file)
@@ -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