summaryrefslogtreecommitdiffstats
path: root/src/bin/agent
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2020-09-05 15:56:18 +0200
committerFrancis Dupont <fdupont@isc.org>2020-09-21 12:36:02 +0200
commit5baf5f091c7cbd87b58b41fd084cda9aab715a0f (patch)
tree2adf2c1ee66ebe7cd13df1bb552e4ad747ff3720 /src/bin/agent
parent[1102] regen bison (diff)
downloadkea-5baf5f091c7cbd87b58b41fd084cda9aab715a0f.tar.xz
kea-5baf5f091c7cbd87b58b41fd084cda9aab715a0f.zip
[#1102] Checkpoint: updated DHCPv4
Diffstat (limited to 'src/bin/agent')
-rw-r--r--src/bin/agent/parser_context.cc17
-rw-r--r--src/bin/agent/parser_context.h11
-rw-r--r--src/bin/agent/tests/parser_unittests.cc8
3 files changed, 36 insertions, 0 deletions
diff --git a/src/bin/agent/parser_context.cc b/src/bin/agent/parser_context.cc
index ff517b56d4..5c61271c39 100644
--- a/src/bin/agent/parser_context.cc
+++ b/src/bin/agent/parser_context.cc
@@ -111,6 +111,23 @@ ParserContext::require(const std::string& name,
}
}
+ParserContext::unique(const std::string& name,
+ isc::data::Element::Position loc)
+{
+ ConstElementPtr value = stack_.back()->get(name);
+ if (value) {
+ if (ctx_ != NO_KEYWORDS) {
+ isc_throw(ParseError, loc << ": duplicate " << name
+ << " entries in " << contextName()
+ << " map (previous at " << value->getPosition() << ")");
+ } else {
+ isc_throw(ParseError, loc << ": duplicate " << name
+ << " entries in JSON"
+ << " map (previous at " << value->getPosition() << ")");
+ }
+ }
+}
+
void
ParserContext::enter(const LexerContext& ctx)
{
diff --git a/src/bin/agent/parser_context.h b/src/bin/agent/parser_context.h
index a8fdea861e..493799103b 100644
--- a/src/bin/agent/parser_context.h
+++ b/src/bin/agent/parser_context.h
@@ -160,6 +160,17 @@ public:
isc::data::Element::Position open_loc,
isc::data::Element::Position close_loc);
+ /// @brief Check if a parameter is already present
+ ///
+ /// Check if a parameter is already present in the map at the top
+ /// of the stack and raise an error when it is.
+ ///
+ /// @param name name of the parameter to check
+ /// @param loc location of the current parameter
+ /// @throw Dhcp4ParseError
+ void unique(const std::string& name,
+ isc::data::Element::Position loc);
+
/// @brief Defines syntactic contexts for lexical tie-ins
typedef enum {
///< This one is used in pure JSON mode.
diff --git a/src/bin/agent/tests/parser_unittests.cc b/src/bin/agent/tests/parser_unittests.cc
index 7153849fa6..6369a898c6 100644
--- a/src/bin/agent/tests/parser_unittests.cc
+++ b/src/bin/agent/tests/parser_unittests.cc
@@ -611,6 +611,14 @@ TEST(ParserTest, errors) {
ParserContext::PARSER_AGENT,
"<string>:3.3-11: duplicate user-context/comment entries "
"(previous at <string>:2:19)");
+
+ // duplicate Control-agent entries
+ testError("{ \"Control-agent\":{\n"
+ " \"comment\": \"first\" },\n"
+ " \"Control-agent\":{\n"
+ " \"comment\": \"second\" }}\n",
+ ParserContext::PARSER_AGENT,
+ "<string>:2.23: syntax error, unexpected \",\", expecting }");
}
// Check unicode escapes