]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5351] Fixed syntax
authorFrancis Dupont <fdupont@isc.org>
Sun, 17 Dec 2017 15:39:28 +0000 (16:39 +0100)
committerFrancis Dupont <fdupont@isc.org>
Sun, 17 Dec 2017 15:39:28 +0000 (16:39 +0100)
src/bin/dhcp4/dhcp4_parser.cc
src/bin/dhcp4/dhcp4_parser.yy
src/bin/dhcp6/dhcp6_parser.cc
src/bin/dhcp6/dhcp6_parser.yy

index 2872929d8407497aecf0382ad6d8ffb20426f425..c6d3d3cd447a0ab70a65de8a55210a2e6ae0029f 100644 (file)
@@ -2340,13 +2340,15 @@ namespace isc { namespace dhcp {
 #line 1381 "dhcp4_parser.yy" // lalr1.cc:859
     {
     ElementPtr parent = ctx.stack_.back();
+    ElementPtr s(new StringElement(yystack_[0].value.as< std::string > ()));
     ConstElementPtr old = parent->get("user-context");
     if (old) {
-        old->set("comment", yystack_[0].value.as< std::string > ());
+      ElementPtr mutable_old = boost::const_pointer_cast<Element>(old);
+      mutable_old->set("comment", s);
     } else {
         ElementPtr e(new MapElement(ctx.loc2pos(yystack_[3].location)));
-        e->set("comment", yystack_[0].value.as< std::string > ());
-        top->set("user-context", e);
+        e->set("comment", s);
+        parent->set("user-context", e);
     }
     ctx.leave();
 }
index 2d05b23eecf95e80ac7f17958c5ffae072da1469..3556dcb9f212032db1616facbccd7c4cc72d37b2 100644 (file)
@@ -1363,13 +1363,17 @@ user_context: USER_CONTEXT {
     ElementPtr parent = ctx.stack_.back();
     ElementPtr user_context = $4;
     ConstElementPtr old = parent->get("user-context");
+
+    // Handle already existing user context
     if (old) {
+        // Check if it was a comment or a duplicate
         if ((old->size() != 1) || !old->contains("comment")) {
             std::stringstream msg;
             msg << "duplicate user-context entries (previous at "
                 << old->getPosition().str() << ")";
             error(@1, msg.str());
         }
+        // Merge the comment
         user_context->set("comment", old->get("comment"));
     }
     parent->set("user-context", user_context);
@@ -1380,13 +1384,22 @@ comment: COMMENT {
     ctx.enter(ctx.NO_KEYWORD);
 } COLON STRING {
     ElementPtr parent = ctx.stack_.back();
+    ElementPtr e(new MapElement(ctx.loc2pos(@1)));
+    ElementPtr s(new StringElement($4, ctx.loc2pos(@4)));
+    e->set("comment", s);
+
+    // Handle already existing user context
     ConstElementPtr old = parent->get("user-context");
     if (old) {
-        old->set("comment", $4);
-    } else {
-        ElementPtr e(new MapElement(ctx.loc2pos(@1)));
-        e->set("comment", $4);
-        top->set("user-context", e);
+        // Check for duplicate comment
+        if (old->contains("comment") {
+            std::stringstream msg;
+            msg << "duplicate user-context/comment entries (previous at "
+                << old->getPosition().str() << ")";
+            error(@1, msg.str());
+        }
+        // Merge the user context in the comment
+        merge(e, old);
     }
     ctx.leave();
 };
index ae3bf2472ce5505a493b40ba249d722739aaac43..87498397a2acbfa59fbb6654524a16e7b7aca665 100644 (file)
@@ -2241,13 +2241,15 @@ namespace isc { namespace dhcp {
 #line 1344 "dhcp6_parser.yy" // lalr1.cc:859
     {
     ElementPtr parent = ctx.stack_.back();
+    ElementPtr s(new StringElement(yystack_[0].value.as< std::string > ()));
     ConstElementPtr old = parent->get("user-context");
     if (old) {
-        old->set("comment", yystack_[0].value.as< std::string > ());
+      ElementPtr mutable_old = boost::const_pointer_cast<Element>(old);
+      mutable_old->set("comment", s);
     } else {
         ElementPtr e(new MapElement(ctx.loc2pos(yystack_[3].location)));
-        e->set("comment", yystack_[0].value.as< std::string > ());
-        top->set("user-context", e);
+       e->set("comment", s);
+        parent->set("user-context", e);
     }
     ctx.leave();
 }
index ca9f3f4dabe9b4317466efc490b0769dbb07a918..126dab45019e3fff59461e287899c3bda1500f17 100644 (file)
@@ -1326,13 +1326,17 @@ user_context: USER_CONTEXT {
     ElementPtr parent = ctx.stack_.back();
     ElementPtr user_context = $4;
     ConstElementPtr old = parent->get("user-context");
+
+    // Handle already existing user context
     if (old) {
+        // Check if it was a comment or a duplicate
         if ((old->size() != 1) || !old->contains("comment")) {
             std::stringstream msg;
             msg << "duplicate user-context entries (previous at "
                 << old->getPosition().str() << ")";
             error(@1, msg.str());
         }
+        // Merge the comment
         user_context->set("comment", old->get("comment"));
     }
     parent->set("user-context", user_context);
@@ -1343,13 +1347,22 @@ comment: COMMENT {
     ctx.enter(ctx.NO_KEYWORD);
 } COLON STRING {
     ElementPtr parent = ctx.stack_.back();
+    ElementPtr e(new MapElement(ctx.loc2pos(@1)));
+    ElementPtr s(new StringElement($4, ctx.loc2pos(@4)));
+    e->set("comment", s);
+
+    // Handle already existing user context
     ConstElementPtr old = parent->get("user-context");
     if (old) {
-        old->set("comment", $4);
-    } else {
-        ElementPtr e(new MapElement(ctx.loc2pos(@1)));
-        e->set("comment", $4);
-        top->set("user-context", e);
+        // Check for duplicate comment
+        if (old->contains("comment") {
+            std::stringstream msg;
+            msg << "duplicate user-context/comment entries (previous at "
+                << old->getPosition().str() << ")";
+            error(@1, msg.str());
+        }
+        // Merge the user context in the comment
+        merge(e, old);
     }
     ctx.leave();
 };