]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1100] Got rid of comment extraction
authorFrancis Dupont <fdupont@isc.org>
Sat, 11 Apr 2020 18:21:13 +0000 (20:21 +0200)
committerFrancis Dupont <fdupont@isc.org>
Mon, 15 Jun 2020 14:13:38 +0000 (16:13 +0200)
28 files changed:
doc/sphinx/arm/config.rst
doc/sphinx/arm/hooks.rst
src/bin/agent/tests/testdata/get_config.json
src/bin/d2/tests/testdata/get_config.json
src/bin/dhcp4/tests/get_config_unittest.cc
src/bin/dhcp4/tests/get_config_unittest.cc.skel
src/bin/dhcp6/tests/get_config_unittest.cc
src/bin/dhcp6/tests/get_config_unittest.cc.skel
src/bin/netconf/tests/testdata/get_config.json
src/lib/cc/data.cc
src/lib/cc/tests/data_unittests.cc
src/lib/cc/tests/user_context_unittests.cc
src/lib/cc/user_context.cc
src/lib/cc/user_context.h
src/lib/dhcpsrv/tests/cfg_duid_unittest.cc
src/lib/dhcpsrv/tests/cfg_iface_unittest.cc
src/lib/dhcpsrv/tests/cfg_option_def_unittest.cc
src/lib/dhcpsrv/tests/cfg_option_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets4_unittest.cc
src/lib/dhcpsrv/tests/cfg_subnets6_unittest.cc
src/lib/dhcpsrv/tests/client_class_def_unittest.cc
src/lib/dhcpsrv/tests/d2_client_unittest.cc
src/lib/dhcpsrv/tests/host_unittest.cc
src/lib/dhcpsrv/tests/lease_unittest.cc
src/lib/dhcpsrv/tests/shared_network_unittest.cc
src/lib/process/tests/logging_info_unittests.cc
src/lib/testutils/user_context_utils.cc
src/lib/testutils/user_context_utils.h

index db869be014928eb7b601c4eb824527499ec92fe6..762e4f66c55c48e17789ba529462adcc26b90150 100644 (file)
@@ -176,9 +176,9 @@ In a sense the user context mechanism has superseeded the JSON comment
 capabilities. ISC would like to encourage people to use user-context in favor of
 the older mechanisms and we hope to deprecate JSON comments one day in the
 future. To promote this way of storing comments, Kea code is able to understand
-JSON comments, but converts them to user context on the fly. For the time being,
-the comments entries in user-context are converted back to JSON comments to keep
-backward compatibility, but that conversion is expected to go away soon.
+JSON comments, but converts them to user context on the fly. The
+comments entries in user-context were converted back to JSON comments to
+keep backward compatibility, but that conversion went away in version 1.7.x.
 
 The is one side effect, however. If your configuration uses the old JSON
 comment, the `config-get` command will return a slightly modified
index a555430cb23f753fff70d51f5cb2149a4d86c453..1ab531af58c0b1165e38d355c5f3dd51f4a12bb7 100644 (file)
@@ -2838,8 +2838,8 @@ operations, for example.
 
 If user context is supported in a given context, the parser translates
 "comment" entries into user context with a "comment" entry. The pretty
-print of a configuration does the opposite operation and puts "comment"
-entries at the beginning of maps, as that seems to be the common usage.
+print of a configuration did the opposite operation and put "comment"
+entries at the beginning of maps, but this was withdrawn in 1.7.x.
 
 As of Kea 1.3, the structures that allow user contexts are pools of all
 types (addresses and prefixes) and subnets. Kea 1.4 extended user
index 6f9b5b320934cd36c57040d3b8ed1b0d0b4f758b..e1de22731668f8c43a81f40fb398ff08de09ba66 100644 (file)
@@ -9,9 +9,11 @@
                 }
             },
             "dhcp4": {
-                "comment": "socket to DHCP4 server",
                 "socket-name": "/tmp/kea4-ctrl-socket",
-                "socket-type": "unix"
+                "socket-type": "unix",
+                "user-context": {
+                    "comment": "socket to DHCP4 server"
+                }
             },
             "dhcp6": {
                 "socket-name": "/tmp/kea6-ctrl-socket",
@@ -20,7 +22,7 @@
         },
         "hooks-libraries": [
             {
-                "library": "/opt/local/control-agent-commands.so",
+                "library": "/tmp/k1100/src/bin/agent/tests/.libs/libbasic.so",
                 "parameters": {
                     "param1": "foo"
                 }
index d49f359fd39c6a747e80b1c311d3cf0a4af9d949..5fc47d3f8e7dc463229131f46b74fd3650cffd56 100644 (file)
@@ -8,7 +8,6 @@
         "forward-ddns": {
             "ddns-domains": [
                 {
-                    "comment": "DdnsDomain example",
                     "dns-servers": [
                         {
                             "hostname": "",
                         }
                     ],
                     "key-name": "d2.md5.key",
-                    "name": "four.example.com."
+                    "name": "four.example.com.",
+                    "user-context": {
+                        "comment": "DdnsDomain example"
+                    }
                 },
                 {
                     "dns-servers": [
index 1604fb200caa577b0a190cdcba1f0b857e6d87d2..cac614e0f3759f0938c1acb5f5397b30298b85b7 100644 (file)
@@ -1937,88 +1937,112 @@ const char* EXTRACTED_CONFIGS[] = {
 "    }\n",
     // CONFIGURATION 67
 "{\n"
-"        \"comment\": \"A DHCPv4 server\",\n"
 "        \"client-classes\": [\n"
 "            {\n"
-"                \"comment\": \"match all\",\n"
 "                \"name\": \"all\",\n"
-"                \"test\": \"'' == ''\"\n"
+"                \"test\": \"'' == ''\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"match all\"\n"
+"                }\n"
 "            },\n"
 "            {\n"
 "                \"name\": \"none\"\n"
 "            },\n"
 "            {\n"
-"                \"comment\": \"a comment\",\n"
 "                \"name\": \"both\",\n"
 "                \"user-context\": {\n"
+"                    \"comment\": \"a comment\",\n"
 "                    \"version\": 1\n"
 "                }\n"
 "            }\n"
 "        ],\n"
 "        \"control-socket\": {\n"
-"            \"comment\": \"Indirect comment\",\n"
 "            \"socket-name\": \"/tmp/kea4-ctrl-socket\",\n"
-"            \"socket-type\": \"unix\"\n"
+"            \"socket-type\": \"unix\",\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Indirect comment\"\n"
+"            }\n"
 "        },\n"
 "        \"dhcp-ddns\": {\n"
-"            \"comment\": \"No dynamic DNS\",\n"
-"            \"enable-updates\": false\n"
+"            \"enable-updates\": false,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"No dynamic DNS\"\n"
+"            }\n"
 "        },\n"
 "        \"interfaces-config\": {\n"
-"            \"comment\": \"Use wildcard\",\n"
 "            \"interfaces\": [ \"*\" ],\n"
-"            \"re-detect\": false\n"
+"            \"re-detect\": false,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Use wildcard\"\n"
+"            }\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
-"                \"comment\": \"Set option value\",\n"
 "                \"csv-format\": false,\n"
 "                \"data\": \"ABCDEF0105\",\n"
-"                \"name\": \"dhcp-message\"\n"
+"                \"name\": \"dhcp-message\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"Set option value\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"option-def\": [\n"
 "            {\n"
-"                \"comment\": \"An option definition\",\n"
 "                \"code\": 100,\n"
 "                \"name\": \"foo\",\n"
 "                \"space\": \"isc\",\n"
-"                \"type\": \"ipv4-address\"\n"
+"                \"type\": \"ipv4-address\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"An option definition\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"shared-networks\": [\n"
 "            {\n"
-"                \"comment\": \"A shared network\",\n"
 "                \"name\": \"foo\",\n"
 "                \"subnet4\": [\n"
 "                    {\n"
-"                        \"comment\": \"A subnet\",\n"
 "                        \"id\": 100,\n"
 "                        \"pools\": [\n"
 "                            {\n"
-"                                \"comment\": \"A pool\",\n"
-"                                \"pool\": \"192.0.1.1-192.0.1.10\"\n"
+"                                \"pool\": \"192.0.1.1-192.0.1.10\",\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A pool\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"reservations\": [\n"
 "                            {\n"
-"                                \"comment\": \"A host reservation\",\n"
 "                                \"hostname\": \"foo.example.com\",\n"
 "                                \"hw-address\": \"AA:BB:CC:DD:EE:FF\",\n"
 "                                \"option-data\": [\n"
 "                                    {\n"
-"                                        \"comment\": \"An option in a reservation\",\n"
 "                                        \"data\": \"example.com\",\n"
-"                                        \"name\": \"domain-name\"\n"
+"                                        \"name\": \"domain-name\",\n"
+"                                        \"user-context\": {\n"
+"                                            \"comment\": \"An option in a reservation\"\n"
+"                                        }\n"
 "                                    }\n"
-"                                ]\n"
+"                                ],\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A host reservation\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
-"                        \"subnet\": \"192.0.1.0/24\"\n"
+"                        \"subnet\": \"192.0.1.0/24\",\n"
+"                        \"user-context\": {\n"
+"                            \"comment\": \"A subnet\"\n"
+"                        }\n"
 "                    }\n"
-"                ]\n"
+"                ],\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"A shared network\"\n"
+"                }\n"
 "            }\n"
-"        ]\n"
+"        ],\n"
+"        \"user-context\": {\n"
+"            \"comment\": \"A DHCPv4 server\"\n"
+"        }\n"
 "    }\n",
     // CONFIGURATION 68
 "{\n"
@@ -9665,20 +9689,21 @@ const char* UNPARSED_CONFIGS[] = {
 "    }\n",
     // CONFIGURATION 67
 "{\n"
-"        \"comment\": \"A DHCPv4 server\",\n"
 "        \"authoritative\": false,\n"
 "        \"boot-file-name\": \"\",\n"
 "        \"calculate-tee-times\": false,\n"
 "        \"client-classes\": [\n"
 "            {\n"
-"                \"comment\": \"match all\",\n"
 "                \"boot-file-name\": \"\",\n"
 "                \"name\": \"all\",\n"
 "                \"next-server\": \"0.0.0.0\",\n"
 "                \"option-data\": [ ],\n"
 "                \"option-def\": [ ],\n"
 "                \"server-hostname\": \"\",\n"
-"                \"test\": \"'' == ''\"\n"
+"                \"test\": \"'' == ''\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"match all\"\n"
+"                }\n"
 "            },\n"
 "            {\n"
 "                \"boot-file-name\": \"\",\n"
@@ -9689,7 +9714,6 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"server-hostname\": \"\"\n"
 "            },\n"
 "            {\n"
-"                \"comment\": \"a comment\",\n"
 "                \"boot-file-name\": \"\",\n"
 "                \"name\": \"both\",\n"
 "                \"next-server\": \"0.0.0.0\",\n"
@@ -9697,14 +9721,17 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"option-def\": [ ],\n"
 "                \"server-hostname\": \"\",\n"
 "                \"user-context\": {\n"
+"                    \"comment\": \"a comment\",\n"
 "                    \"version\": 1\n"
 "                }\n"
 "            }\n"
 "        ],\n"
 "        \"control-socket\": {\n"
-"            \"comment\": \"Indirect comment\",\n"
 "            \"socket-name\": \"/tmp/kea4-ctrl-socket\",\n"
-"            \"socket-type\": \"unix\"\n"
+"            \"socket-type\": \"unix\",\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Indirect comment\"\n"
+"            }\n"
 "        },\n"
 "        \"ddns-generated-prefix\": \"myhost\",\n"
 "        \"ddns-override-client-update\": false,\n"
@@ -9714,7 +9741,6 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"ddns-send-updates\": true,\n"
 "        \"decline-probation-period\": 86400,\n"
 "        \"dhcp-ddns\": {\n"
-"            \"comment\": \"No dynamic DNS\",\n"
 "            \"enable-updates\": false,\n"
 "            \"max-queue-size\": 1024,\n"
 "            \"ncr-format\": \"JSON\",\n"
@@ -9722,7 +9748,10 @@ const char* UNPARSED_CONFIGS[] = {
 "            \"sender-ip\": \"0.0.0.0\",\n"
 "            \"sender-port\": 0,\n"
 "            \"server-ip\": \"127.0.0.1\",\n"
-"            \"server-port\": 53001\n"
+"            \"server-port\": 53001,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"No dynamic DNS\"\n"
+"            }\n"
 "        },\n"
 "        \"dhcp-queue-control\": {\n"
 "            \"capacity\": 500,\n"
@@ -9744,9 +9773,11 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"hostname-char-replacement\": \"\",\n"
 "        \"hostname-char-set\": \"[^A-Za-z0-9.-]\",\n"
 "        \"interfaces-config\": {\n"
-"            \"comment\": \"Use wildcard\",\n"
 "            \"interfaces\": [ \"*\" ],\n"
-"            \"re-detect\": false\n"
+"            \"re-detect\": false,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Use wildcard\"\n"
+"            }\n"
 "        },\n"
 "        \"lease-database\": {\n"
 "            \"type\": \"memfile\"\n"
@@ -9760,25 +9791,29 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"next-server\": \"0.0.0.0\",\n"
 "        \"option-data\": [\n"
 "            {\n"
-"                \"comment\": \"Set option value\",\n"
 "                \"always-send\": false,\n"
 "                \"code\": 56,\n"
 "                \"csv-format\": false,\n"
 "                \"data\": \"ABCDEF0105\",\n"
 "                \"name\": \"dhcp-message\",\n"
-"                \"space\": \"dhcp4\"\n"
+"                \"space\": \"dhcp4\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"Set option value\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"option-def\": [\n"
 "            {\n"
-"                \"comment\": \"An option definition\",\n"
 "                \"array\": false,\n"
 "                \"code\": 100,\n"
 "                \"encapsulate\": \"\",\n"
 "                \"name\": \"foo\",\n"
 "                \"record-types\": \"\",\n"
 "                \"space\": \"isc\",\n"
-"                \"type\": \"ipv4-address\"\n"
+"                \"type\": \"ipv4-address\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"An option definition\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"reservation-mode\": \"all\",\n"
@@ -9789,7 +9824,6 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"server-tag\": \"\",\n"
 "        \"shared-networks\": [\n"
 "            {\n"
-"                \"comment\": \"A shared network\",\n"
 "                \"calculate-tee-times\": false,\n"
 "                \"name\": \"foo\",\n"
 "                \"option-data\": [ ],\n"
@@ -9799,7 +9833,6 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"store-extended-info\": false,\n"
 "                \"subnet4\": [\n"
 "                    {\n"
-"                        \"comment\": \"A subnet\",\n"
 "                        \"4o6-interface\": \"\",\n"
 "                        \"4o6-interface-id\": \"\",\n"
 "                        \"4o6-subnet\": \"\",\n"
@@ -9808,9 +9841,11 @@ const char* UNPARSED_CONFIGS[] = {
 "                        \"option-data\": [ ],\n"
 "                        \"pools\": [\n"
 "                            {\n"
-"                                \"comment\": \"A pool\",\n"
 "                                \"option-data\": [ ],\n"
-"                                \"pool\": \"192.0.1.1-192.0.1.10\"\n"
+"                                \"pool\": \"192.0.1.1-192.0.1.10\",\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A pool\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"relay\": {\n"
@@ -9818,7 +9853,6 @@ const char* UNPARSED_CONFIGS[] = {
 "                        },\n"
 "                        \"reservations\": [\n"
 "                            {\n"
-"                                \"comment\": \"A host reservation\",\n"
 "                                \"boot-file-name\": \"\",\n"
 "                                \"client-classes\": [ ],\n"
 "                                \"hostname\": \"foo.example.com\",\n"
@@ -9826,27 +9860,38 @@ const char* UNPARSED_CONFIGS[] = {
 "                                \"next-server\": \"0.0.0.0\",\n"
 "                                \"option-data\": [\n"
 "                                    {\n"
-"                                        \"comment\": \"An option in a reservation\",\n"
 "                                        \"always-send\": false,\n"
 "                                        \"code\": 15,\n"
 "                                        \"csv-format\": true,\n"
 "                                        \"data\": \"example.com\",\n"
 "                                        \"name\": \"domain-name\",\n"
-"                                        \"space\": \"dhcp4\"\n"
+"                                        \"space\": \"dhcp4\",\n"
+"                                        \"user-context\": {\n"
+"                                            \"comment\": \"An option in a reservation\"\n"
+"                                        }\n"
 "                                    }\n"
 "                                ],\n"
-"                                \"server-hostname\": \"\"\n"
+"                                \"server-hostname\": \"\",\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A host reservation\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"store-extended-info\": false,\n"
 "                        \"subnet\": \"192.0.1.0/24\",\n"
 "                        \"t1-percent\": 0.5,\n"
 "                        \"t2-percent\": 0.875,\n"
+"                        \"user-context\": {\n"
+"                            \"comment\": \"A subnet\"\n"
+"                        },\n"
 "                        \"valid-lifetime\": 7200\n"
 "                    }\n"
 "                ],\n"
 "                \"t1-percent\": 0.5,\n"
 "                \"t2-percent\": 0.875,\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"A shared network\"\n"
+"                },\n"
 "                \"valid-lifetime\": 7200\n"
 "            }\n"
 "        ],\n"
@@ -9856,6 +9901,9 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"subnet4\": [ ],\n"
 "        \"t1-percent\": 0.5,\n"
 "        \"t2-percent\": 0.875,\n"
+"        \"user-context\": {\n"
+"            \"comment\": \"A DHCPv4 server\"\n"
+"        },\n"
 "        \"valid-lifetime\": 7200\n"
 "    }\n",
     // CONFIGURATION 68
@@ -10693,7 +10741,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = extractComments(parseDHCP4(config));
+    ConstElementPtr json = parseDHCP4(config);
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
index ebfd146b829fba33f25c1e5dde3c78b782aec54b..4ffc908e41936bfee91c122df1fe1f1d788ea60b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -104,7 +104,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = extractComments(parseDHCP4(config));
+    ConstElementPtr json = parseDHCP4(config);
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
index c0ca287fefae25d7c25d0babd1081fcd9e15a328..f61123ad196b7e0ce9634074d04d7e5b32a30022 100644 (file)
@@ -1759,100 +1759,128 @@ const char* EXTRACTED_CONFIGS[] = {
 "    }\n",
     // CONFIGURATION 58
 "{\n"
-"        \"comment\": \"A DHCPv6 server\",\n"
 "        \"client-classes\": [\n"
 "            {\n"
-"                \"comment\": \"match all\",\n"
 "                \"name\": \"all\",\n"
-"                \"test\": \"'' == ''\"\n"
+"                \"test\": \"'' == ''\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"match all\"\n"
+"                }\n"
 "            },\n"
 "            {\n"
 "                \"name\": \"none\"\n"
 "            },\n"
 "            {\n"
-"                \"comment\": \"a comment\",\n"
 "                \"name\": \"both\",\n"
 "                \"user-context\": {\n"
+"                    \"comment\": \"a comment\",\n"
 "                    \"version\": 1\n"
 "                }\n"
 "            }\n"
 "        ],\n"
 "        \"control-socket\": {\n"
-"            \"comment\": \"Indirect comment\",\n"
 "            \"socket-name\": \"/tmp/kea6-ctrl-socket\",\n"
-"            \"socket-type\": \"unix\"\n"
+"            \"socket-type\": \"unix\",\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Indirect comment\"\n"
+"            }\n"
 "        },\n"
 "        \"dhcp-ddns\": {\n"
-"            \"comment\": \"No dynamic DNS\",\n"
-"            \"enable-updates\": false\n"
+"            \"enable-updates\": false,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"No dynamic DNS\"\n"
+"            }\n"
 "        },\n"
 "        \"interfaces-config\": {\n"
-"            \"comment\": \"Use wildcard\",\n"
 "            \"interfaces\": [ \"*\" ],\n"
-"            \"re-detect\": false\n"
+"            \"re-detect\": false,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Use wildcard\"\n"
+"            }\n"
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
-"                \"comment\": \"Set option value\",\n"
 "                \"csv-format\": false,\n"
 "                \"data\": \"ABCDEF0105\",\n"
-"                \"name\": \"subscriber-id\"\n"
+"                \"name\": \"subscriber-id\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"Set option value\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"option-def\": [\n"
 "            {\n"
-"                \"comment\": \"An option definition\",\n"
 "                \"code\": 100,\n"
 "                \"name\": \"foo\",\n"
 "                \"space\": \"isc\",\n"
-"                \"type\": \"ipv6-address\"\n"
+"                \"type\": \"ipv6-address\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"An option definition\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"server-id\": {\n"
-"            \"comment\": \"DHCPv6 specific\",\n"
-"            \"type\": \"LL\"\n"
+"            \"type\": \"LL\",\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"DHCPv6 specific\"\n"
+"            }\n"
 "        },\n"
 "        \"shared-networks\": [\n"
 "            {\n"
-"                \"comment\": \"A shared network\",\n"
 "                \"name\": \"foo\",\n"
 "                \"subnet6\": [\n"
 "                    {\n"
-"                        \"comment\": \"A subnet\",\n"
 "                        \"id\": 100,\n"
 "                        \"pd-pools\": [\n"
 "                            {\n"
-"                                \"comment\": \"A prefix pool\",\n"
 "                                \"delegated-len\": 64,\n"
 "                                \"prefix\": \"2001:db2::\",\n"
-"                                \"prefix-len\": 48\n"
+"                                \"prefix-len\": 48,\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A prefix pool\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"pools\": [\n"
 "                            {\n"
-"                                \"comment\": \"A pool\",\n"
-"                                \"pool\": \"2001:db1::/64\"\n"
+"                                \"pool\": \"2001:db1::/64\",\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A pool\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"reservations\": [\n"
 "                            {\n"
-"                                \"comment\": \"A host reservation\",\n"
 "                                \"hostname\": \"foo.example.com\",\n"
 "                                \"hw-address\": \"AA:BB:CC:DD:EE:FF\",\n"
 "                                \"option-data\": [\n"
 "                                    {\n"
-"                                        \"comment\": \"An option in a reservation\",\n"
 "                                        \"data\": \"example.com\",\n"
-"                                        \"name\": \"domain-search\"\n"
+"                                        \"name\": \"domain-search\",\n"
+"                                        \"user-context\": {\n"
+"                                            \"comment\": \"An option in a reservation\"\n"
+"                                        }\n"
 "                                    }\n"
-"                                ]\n"
+"                                ],\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A host reservation\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
-"                        \"subnet\": \"2001:db1::/48\"\n"
+"                        \"subnet\": \"2001:db1::/48\",\n"
+"                        \"user-context\": {\n"
+"                            \"comment\": \"A subnet\"\n"
+"                        }\n"
 "                    }\n"
-"                ]\n"
+"                ],\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"A shared network\"\n"
+"                }\n"
 "            }\n"
-"        ]\n"
+"        ],\n"
+"        \"user-context\": {\n"
+"            \"comment\": \"A DHCPv6 server\"\n"
+"        }\n"
 "    }\n",
     // CONFIGURATION 59
 "{\n"
@@ -8679,32 +8707,35 @@ const char* UNPARSED_CONFIGS[] = {
 "    }\n",
     // CONFIGURATION 58
 "{\n"
-"        \"comment\": \"A DHCPv6 server\",\n"
 "        \"calculate-tee-times\": true,\n"
 "        \"client-classes\": [\n"
 "            {\n"
-"                \"comment\": \"match all\",\n"
 "                \"name\": \"all\",\n"
 "                \"option-data\": [ ],\n"
-"                \"test\": \"'' == ''\"\n"
+"                \"test\": \"'' == ''\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"match all\"\n"
+"                }\n"
 "            },\n"
 "            {\n"
 "                \"name\": \"none\",\n"
 "                \"option-data\": [ ]\n"
 "            },\n"
 "            {\n"
-"                \"comment\": \"a comment\",\n"
 "                \"name\": \"both\",\n"
 "                \"option-data\": [ ],\n"
 "                \"user-context\": {\n"
+"                    \"comment\": \"a comment\",\n"
 "                    \"version\": 1\n"
 "                }\n"
 "            }\n"
 "        ],\n"
 "        \"control-socket\": {\n"
-"            \"comment\": \"Indirect comment\",\n"
 "            \"socket-name\": \"/tmp/kea6-ctrl-socket\",\n"
-"            \"socket-type\": \"unix\"\n"
+"            \"socket-type\": \"unix\",\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Indirect comment\"\n"
+"            }\n"
 "        },\n"
 "        \"ddns-generated-prefix\": \"myhost\",\n"
 "        \"ddns-override-client-update\": false,\n"
@@ -8714,7 +8745,6 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"ddns-send-updates\": true,\n"
 "        \"decline-probation-period\": 86400,\n"
 "        \"dhcp-ddns\": {\n"
-"            \"comment\": \"No dynamic DNS\",\n"
 "            \"enable-updates\": false,\n"
 "            \"max-queue-size\": 1024,\n"
 "            \"ncr-format\": \"JSON\",\n"
@@ -8722,7 +8752,10 @@ const char* UNPARSED_CONFIGS[] = {
 "            \"sender-ip\": \"0.0.0.0\",\n"
 "            \"sender-port\": 0,\n"
 "            \"server-ip\": \"127.0.0.1\",\n"
-"            \"server-port\": 53001\n"
+"            \"server-port\": 53001,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"No dynamic DNS\"\n"
+"            }\n"
 "        },\n"
 "        \"dhcp-queue-control\": {\n"
 "            \"capacity\": 500,\n"
@@ -8743,9 +8776,11 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"hostname-char-replacement\": \"\",\n"
 "        \"hostname-char-set\": \"[^A-Za-z0-9.-]\",\n"
 "        \"interfaces-config\": {\n"
-"            \"comment\": \"Use wildcard\",\n"
 "            \"interfaces\": [ \"*\" ],\n"
-"            \"re-detect\": false\n"
+"            \"re-detect\": false,\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"Use wildcard\"\n"
+"            }\n"
 "        },\n"
 "        \"lease-database\": {\n"
 "            \"type\": \"memfile\"\n"
@@ -8758,25 +8793,29 @@ const char* UNPARSED_CONFIGS[] = {
 "        },\n"
 "        \"option-data\": [\n"
 "            {\n"
-"                \"comment\": \"Set option value\",\n"
 "                \"always-send\": false,\n"
 "                \"code\": 38,\n"
 "                \"csv-format\": false,\n"
 "                \"data\": \"ABCDEF0105\",\n"
 "                \"name\": \"subscriber-id\",\n"
-"                \"space\": \"dhcp6\"\n"
+"                \"space\": \"dhcp6\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"Set option value\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"option-def\": [\n"
 "            {\n"
-"                \"comment\": \"An option definition\",\n"
 "                \"array\": false,\n"
 "                \"code\": 100,\n"
 "                \"encapsulate\": \"\",\n"
 "                \"name\": \"foo\",\n"
 "                \"record-types\": \"\",\n"
 "                \"space\": \"isc\",\n"
-"                \"type\": \"ipv6-address\"\n"
+"                \"type\": \"ipv6-address\",\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"An option definition\"\n"
+"                }\n"
 "            }\n"
 "        ],\n"
 "        \"preferred-lifetime\": 3600,\n"
@@ -8786,18 +8825,19 @@ const char* UNPARSED_CONFIGS[] = {
 "            \"lease-checks\": \"warn\"\n"
 "        },\n"
 "        \"server-id\": {\n"
-"            \"comment\": \"DHCPv6 specific\",\n"
 "            \"enterprise-id\": 0,\n"
 "            \"htype\": 0,\n"
 "            \"identifier\": \"\",\n"
 "            \"persist\": true,\n"
 "            \"time\": 0,\n"
-"            \"type\": \"LL\"\n"
+"            \"type\": \"LL\",\n"
+"            \"user-context\": {\n"
+"                \"comment\": \"DHCPv6 specific\"\n"
+"            }\n"
 "        },\n"
 "        \"server-tag\": \"\",\n"
 "        \"shared-networks\": [\n"
 "            {\n"
-"                \"comment\": \"A shared network\",\n"
 "                \"calculate-tee-times\": true,\n"
 "                \"name\": \"foo\",\n"
 "                \"option-data\": [ ],\n"
@@ -8809,24 +8849,27 @@ const char* UNPARSED_CONFIGS[] = {
 "                \"store-extended-info\": false,\n"
 "                \"subnet6\": [\n"
 "                    {\n"
-"                        \"comment\": \"A subnet\",\n"
 "                        \"calculate-tee-times\": true,\n"
 "                        \"id\": 100,\n"
 "                        \"option-data\": [ ],\n"
 "                        \"pd-pools\": [\n"
 "                            {\n"
-"                                \"comment\": \"A prefix pool\",\n"
 "                                \"delegated-len\": 64,\n"
 "                                \"option-data\": [ ],\n"
 "                                \"prefix\": \"2001:db2::\",\n"
-"                                \"prefix-len\": 48\n"
+"                                \"prefix-len\": 48,\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A prefix pool\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"pools\": [\n"
 "                            {\n"
-"                                \"comment\": \"A pool\",\n"
 "                                \"option-data\": [ ],\n"
-"                                \"pool\": \"2001:db1::/64\"\n"
+"                                \"pool\": \"2001:db1::/64\",\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A pool\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"preferred-lifetime\": 3600,\n"
@@ -8835,34 +8878,44 @@ const char* UNPARSED_CONFIGS[] = {
 "                        },\n"
 "                        \"reservations\": [\n"
 "                            {\n"
-"                                \"comment\": \"A host reservation\",\n"
 "                                \"client-classes\": [ ],\n"
 "                                \"hostname\": \"foo.example.com\",\n"
 "                                \"hw-address\": \"aa:bb:cc:dd:ee:ff\",\n"
 "                                \"ip-addresses\": [ ],\n"
 "                                \"option-data\": [\n"
 "                                    {\n"
-"                                        \"comment\": \"An option in a reservation\",\n"
 "                                        \"always-send\": false,\n"
 "                                        \"code\": 24,\n"
 "                                        \"csv-format\": true,\n"
 "                                        \"data\": \"example.com\",\n"
 "                                        \"name\": \"domain-search\",\n"
-"                                        \"space\": \"dhcp6\"\n"
+"                                        \"space\": \"dhcp6\",\n"
+"                                        \"user-context\": {\n"
+"                                            \"comment\": \"An option in a reservation\"\n"
+"                                        }\n"
 "                                    }\n"
 "                                ],\n"
-"                                \"prefixes\": [ ]\n"
+"                                \"prefixes\": [ ],\n"
+"                                \"user-context\": {\n"
+"                                    \"comment\": \"A host reservation\"\n"
+"                                }\n"
 "                            }\n"
 "                        ],\n"
 "                        \"store-extended-info\": false,\n"
 "                        \"subnet\": \"2001:db1::/48\",\n"
 "                        \"t1-percent\": 0.5,\n"
 "                        \"t2-percent\": 0.8,\n"
+"                        \"user-context\": {\n"
+"                            \"comment\": \"A subnet\"\n"
+"                        },\n"
 "                        \"valid-lifetime\": 7200\n"
 "                    }\n"
 "                ],\n"
 "                \"t1-percent\": 0.5,\n"
 "                \"t2-percent\": 0.8,\n"
+"                \"user-context\": {\n"
+"                    \"comment\": \"A shared network\"\n"
+"                },\n"
 "                \"valid-lifetime\": 7200\n"
 "            }\n"
 "        ],\n"
@@ -8872,6 +8925,9 @@ const char* UNPARSED_CONFIGS[] = {
 "        \"subnet6\": [ ],\n"
 "        \"t1-percent\": 0.5,\n"
 "        \"t2-percent\": 0.8,\n"
+"        \"user-context\": {\n"
+"            \"comment\": \"A DHCPv6 server\"\n"
+"        },\n"
 "        \"valid-lifetime\": 7200\n"
 "    }\n",
     // CONFIGURATION 59
@@ -9334,7 +9390,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = extractComments(parseDHCP6(config));
+    ConstElementPtr json = parseDHCP6(config);
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
index 2030cb925ce04821b85941883f5e4f088f9402af..5c227dbc53881b59e8686676567e7e3046bbe9cf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -105,7 +105,7 @@ static_assert(max_config_counter == sizeof(UNPARSED_CONFIGS) / sizeof(char*),
 void
 outputFormatted(const std::string& config) {
     // pretty print it
-    ConstElementPtr json = extractComments(parseDHCP6(config));
+    ConstElementPtr json = parseDHCP6(config);
     std::string prettier = prettyPrint(json, 4, 4);
     // get it as a line array
     std::list<std::string> lines;
index 38c6bceb7d1dccce07f62f4da40dfec79fa3d1d0..d08aed20c0f4e2b8438795639903a0c57d05d3e0 100644 (file)
@@ -4,7 +4,6 @@
         "hooks-libraries": [ ],
         "managed-servers": {
             "dhcp4": {
-                "comment": "Kea DHCP4 server serving network on floor 13",
                 "boot-update": true,
                 "control-socket": {
                     "socket-name": "/tmp/kea4-ctrl-socket",
@@ -13,6 +12,9 @@
                 },
                 "model": "kea-dhcp4-server",
                 "subscribe-changes": true,
+                "user-context": {
+                    "comment": "Kea DHCP4 server serving network on floor 13"
+                },
                 "validate-changes": false
             }
         },
index 882f34abbfb084a05f63740fd7bb4b3b8d780340..d644c75cfad78d211a9d6bb93f875837b4faf6d2 100644 (file)
@@ -1279,26 +1279,10 @@ prettyPrint(ConstElementPtr element, std::ostream& out,
         // open the map
         out << "{\n";
 
-        bool first = true;
-        // output comment first
-        if (element->contains("comment")) {
-            // add indentation
-            out << std::string(indent + step, ' ');
-            // add keyword:
-            out << "\"comment\": ";
-            // recursive call
-            prettyPrint(element->get("comment"), out, indent + step, step);
-            // it was the first
-            first = false;
-        }
-
         // iterate on keyword: value
         const auto& m = element->mapValue();
+        bool first = true;
         for (auto it = m.begin(); it != m.end(); ++it) {
-            // skip comment
-            if (it->first == "comment") {
-                continue;
-            }
             // add the separator if not the first item
             if (first) {
                 first = false;
index a347a2469ff93b5dd473358f5e55c877af52e813..41b20d46036c745f88ba45ed0c986636cebfeeb1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2009-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2009-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -1147,8 +1147,8 @@ TEST(Element, prettyPrint) {
 
     // default step is 2, order is alphabetic, no \n at the end
     string text = "{\n"
-        "  \"comment\": \"this is an exception\",\n"
         "  \"boolean\": true,\n"
+        "  \"comment\": \"this is an exception\",\n"
         "  \"empty-list\": [ ],\n"
         "  \"empty-map\": { },\n"
         "  \"integer\": 1,\n"
index 3035e99ade294684e436508e4d0cf6775b550eb6..e88b421fec845dfa6f6d86eeeed2c2c69dcaa131 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2018-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -74,7 +74,7 @@ TEST(UserContext, onlyComment) {
     ElementPtr map = gen();
     parent.contextToElement(map);
     ElementPtr expected = gen();
-    merge(expected, ctx);
+    expected->set("user-context", ctx);
     EXPECT_EQ(*expected, *map);
 }
 
@@ -86,8 +86,7 @@ TEST(UserContext, both) {
     ElementPtr map = gen();
     parent.contextToElement(map);
     ElementPtr expected = gen();
-    expected->set("comment", Element::create("foobar"));
-    expected->set("user-context", Element::fromJSON("{ \"version\": 1 }"));
+    expected->set("user-context", ctx);
     EXPECT_EQ(*expected, *map);
 }
 
@@ -118,9 +117,7 @@ TEST(toElement, onlyComment) {
     ConstElementPtr ctx = Element::fromJSON("{ \"comment\": \"foobar\" }");
     map->set("user-context", ctx);
     ConstElementPtr result = UserContext::toElement(map);
-    ElementPtr expected = gen();
-    merge(expected, ctx);
-    EXPECT_EQ(*expected, *result);
+    EXPECT_EQ(*result, *map);
 }
 
 TEST(toElement, both) {
@@ -129,10 +126,7 @@ TEST(toElement, both) {
         Element::fromJSON("{ \"comment\": \"foobar\", \"version\": 1 }");
     map->set("user-context", ctx);
     ConstElementPtr result = UserContext::toElement(map);
-    ElementPtr expected = gen();
-    expected->set("comment", Element::create("foobar"));
-    expected->set("user-context", Element::fromJSON("{ \"version\": 1 }"));
-    EXPECT_EQ(*expected, *result);
+    EXPECT_EQ(*result, *map);
 }
 
 }
index 3194fcd6ae5ada9998c452f1f608a415a2902015..2ff1984cc934cb73fe12227424a5d088bb39d0d0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -15,43 +15,14 @@ void
 UserContext::contextToElement(ElementPtr map) const {
     // Set user-context extracting comment
     ConstElementPtr context = getContext();
-    if (!isNull(context)) {
-        if ((context->getType() == Element::map) &&
-            context->contains("comment")) {
-            ElementPtr copied = isc::data::copy(context);
-            map->set("comment", copied->get("comment"));
-            copied->remove("comment");
-            if (copied->size() > 0) {
-                map->set("user-context", copied);
-            }
-        } else {
-            map->set("user-context", context);
-        }
+    if (context) {
+        map->set("user-context", context);
     }
 }
 
 ElementPtr
 UserContext::toElement(ConstElementPtr map) {
     ElementPtr result = isc::data::copy(map);
-    // Protect against argument not map
-    if (result->getType() != Element::map) {
-        return (result);
-    }
-    ConstElementPtr ctx = result->get("user-context");
-    // Protect against user context not map
-    if (!ctx || (ctx->getType() != Element::map)) {
-        return (result);
-    }
-    // Extract comment
-    if (ctx->contains("comment")) {
-        ElementPtr ctx_copy = isc::data::copy(ctx);
-        result->set("comment", ctx_copy->get("comment"));
-        ctx_copy->remove("comment");
-        result->remove("user-context");
-        if (ctx_copy->size() > 0) {
-            result->set("user-context", ctx_copy);
-        }
-    }
     return (result);
 }
 
index ae795b6753c8b30eac5cfbfc6b2ec407e5a406f7..2804c7ef44ae5673034b296a9d4b48de9a8404ff 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -34,15 +34,16 @@ struct UserContext {
     /// @brief Merge unparse a user_context object.
     ///
     /// Add user-context to map, but only if defined. Omit if it was not.
-    /// Extract comment so it will be pretty-printed first.
     ///
     /// @param map A pointer to map where the user context will be unparsed.
     void contextToElement(data::ElementPtr map) const;
 
-    /// @brief Copy extracting comments an Element map
+    /// @brief Copy an Element map
+    ///
+    /// A previous version of this extracted comments.
     ///
     /// @param map A pointer to map.
-    /// @return a copy of map where comment is extracted.
+    /// @return a copy of map
     static data::ElementPtr toElement(data::ConstElementPtr map);
 
 protected:
index d15cc5567bfff150140c532edb5a5da9b761d8be..73c6af1781186c2eba877f903635e8619ab46cbc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -130,14 +130,14 @@ TEST_F(CfgDUIDTest, setValues) {
     EXPECT_EQ(user_context, cfg_duid.getContext()->str());
 
     std::string expected = "{\n"
-        " \"comment\": \"bar\",\n"
         " \"type\": \"EN\",\n"
         " \"identifier\": \"ABCDEF\",\n"
         " \"htype\": 100,\n"
         " \"time\": 32100,\n"
         " \"enterprise-id\": 10,\n"
         " \"persist\": false,\n"
-        " \"user-context\": { \"foo\": 1 }\n"
+        " \"user-context\": { \"foo\": 1,\n"
+        " \"comment\": \"bar\" }\n"
         "}";
     runToElementTest<CfgDUID>(expected, cfg_duid);
 }
index a6aa610f19b1f8af0b9dabfadff6f446407526f4..770004bcf2a4a0eaf6c43656c487f5429d7be6ab 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -486,10 +486,10 @@ TEST_F(CfgIfaceTest, unparse) {
 
     // Check unparse
     std::string expected =
-        "{ \"comment\": \"foo\", "
+        "{ "
         "\"interfaces\": [ \"*\", \"eth0\", \"eth1/192.0.2.3\" ], "
         "\"re-detect\": false, "
-        "\"user-context\": { \"bar\": 1 } }";
+        "\"user-context\": { \"comment\": \"foo\", \"bar\": 1 } }";
     runToElementTest<CfgIface>(expected, cfg4);
 
     // Now check IPv6
@@ -501,10 +501,10 @@ TEST_F(CfgIfaceTest, unparse) {
     EXPECT_NO_THROW(cfg6.setContext(Element::fromJSON(comment)));
 
     expected =
-        "{ \"comment\": \"bar\", "
+        "{ "
         "\"interfaces\": [ \"*\", \"eth1\", \"eth0/2001:db8:1::1\" ], "
         "\"re-detect\": false, "
-        "\"user-context\": { \"foo\": 2 } }";
+        "\"user-context\": { \"comment\": \"bar\", \"foo\": 2 } }";
     runToElementTest<CfgIface>(expected, cfg6);
 }
 
index aa5b1ca5379aec093ae120baeba3c823345f1815..1aa9d96d52b7303e29def694defe95e8a46e85ee 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -318,13 +318,12 @@ TEST(CfgOptionDefTest, unparse) {
         "},{\n"
         "    \"name\": \"option-rec\",\n"
         "    \"code\": 6,\n"
-        "    \"comment\": \"foo\",\n"
         "    \"type\": \"record\",\n"
         "    \"array\": false,\n"
         "    \"record-types\": \"uint16, uint16\",\n"
         "    \"encapsulate\": \"\",\n"
         "    \"space\": \"dns\",\n"
-        "    \"user-context\": { \"bar\": 1 }\n"
+        "    \"user-context\": { \"comment\": \"foo\", \"bar\": 1 }\n"
         "},{\n"
         "    \"name\": \"option-foo\",\n"
         "    \"code\": 5,\n"
index f2f8dc72bec9d4a34766ce9d751129d033977de4..10f128b06c07f6d993bfa434190131fd676b9fa3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -1097,13 +1097,12 @@ TEST_F(CfgOptionTest, unparse) {
         "    \"data\": \"12121212\",\n"
         "    \"always-send\": false\n"
         "},{\n"
-        "    \"comment\": \"foo\",\n"
         "    \"code\": 101,\n"
         "    \"space\": \"dns\",\n"
         "    \"csv-format\": true,\n"
         "    \"data\": \"12, 12, 12, 12\",\n"
         "    \"always-send\": false,\n"
-        "    \"user-context\": { \"bar\": 1 }\n"
+        "    \"user-context\": { \"comment\": \"foo\", \"bar\": 1 }\n"
         "},{\n"
         "    \"code\": 13,\n"
         "    \"name\": \"status-code\",\n"
index 7b15ddd4d811d1e9809e523765eb871260367e41..6b064a42989289cd7fa20d5b941b3159a906ec3a 100644 (file)
@@ -1057,7 +1057,6 @@ TEST(CfgSubnets4Test, unparseSubnet) {
     // Unparse
     std::string expected = "[\n"
         "{\n"
-        "    \"comment\": \"foo\",\n"
         "    \"id\": 123,\n"
         "    \"subnet\": \"192.0.2.0/26\",\n"
         "    \"t1-percent\": 0.45,"
@@ -1071,7 +1070,8 @@ TEST(CfgSubnets4Test, unparseSubnet) {
         "    \"4o6-interface-id\": \"\",\n"
         "    \"4o6-subnet\": \"\",\n"
         "    \"option-data\": [ ],\n"
-        "    \"pools\": [ ]\n"
+        "    \"pools\": [ ],\n"
+        "    \"user-context\": { \"comment\": \"foo\" }\n"
         "},{\n"
         "    \"id\": 124,\n"
         "    \"subnet\": \"192.0.2.64/26\",\n"
@@ -1161,10 +1161,10 @@ TEST(CfgSubnets4Test, unparsePool) {
         "    \"option-data\": [],\n"
         "    \"pools\": [\n"
         "        {\n"
-        "            \"comment\": \"foo\",\n"
         "            \"option-data\": [ ],\n"
         "            \"pool\": \"192.0.2.1-192.0.2.10\",\n"
-        "            \"user-context\": { \"version\": 1 }\n"
+        "            \"user-context\": { \"comment\": \"foo\",\n"
+        "                                \"version\": 1 }\n"
         "        },{\n"
         "            \"option-data\": [ ],\n"
         "            \"pool\": \"192.0.2.64/26\",\n"
index a934f6a749b46ebed00ebd13aa3c270c88cdd626..bc2979a59822d67e03a9cc26b140abd828ab72d7 100644 (file)
@@ -657,7 +657,6 @@ TEST(CfgSubnets6Test, unparseSubnet) {
     // Unparse
     std::string expected = "[\n"
         "{\n"
-        "    \"comment\": \"foo\",\n"
         "    \"id\": 123,\n"
         "    \"subnet\": \"2001:db8:1::/48\",\n"
         "    \"t1-percent\": 0.45,"
@@ -671,7 +670,8 @@ TEST(CfgSubnets6Test, unparseSubnet) {
         "    \"client-class\": \"foo\",\n"
         "    \"pools\": [ ],\n"
         "    \"pd-pools\": [ ],\n"
-        "    \"option-data\": [ ]\n"
+        "    \"option-data\": [ ],\n"
+        "    \"user-context\": { \"comment\": \"foo\" }\n"
         "},{\n"
         "    \"id\": 124,\n"
         "    \"subnet\": \"2001:db8:2::/48\",\n"
@@ -757,9 +757,9 @@ TEST(CfgSubnets6Test, unparsePool) {
         "    \"valid-lifetime\": 4,\n"
         "    \"pools\": [\n"
         "        {\n"
-        "            \"comment\": \"foo\",\n"
         "            \"pool\": \"2001:db8:1::100-2001:db8:1::199\",\n"
-        "            \"user-context\": { \"version\": 1 },\n"
+        "            \"user-context\": { \"version\": 1,\n"
+        "                                \"comment\": \"foo\" },\n"
         "            \"option-data\": [ ]\n"
         "        },{\n"
         "            \"pool\": \"2001:db8:1:1::/64\",\n"
index 37fa7b5f19c5cdcf3db4d8dc7031057467236b9b..1c862b8c35f4721e26e502bd512f76208d57e917 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -504,7 +504,6 @@ TEST(ClientClassDef, unparseDef) {
 
     // Unparse it
     std::string expected = "{\n"
-        "\"comment\": \"" + comment + "\",\n"
         "\"name\": \"" + name + "\",\n"
         "\"test\": \"" + test + "\",\n"
         "\"only-if-required\": true,\n"
@@ -512,7 +511,8 @@ TEST(ClientClassDef, unparseDef) {
         "\"server-hostname\": \"" + sname + "\",\n"
         "\"boot-file-name\": \"" + filename + "\",\n"
         "\"option-data\": [ ],\n"
-        "\"user-context\": { \"bar\": 1 } }\n";
+        "\"user-context\": { \"bar\": 1,\n"
+        "\"comment\": \"" + comment + "\" } }\n";
     runToElementTest<ClientClassDef>(expected, *cclass);
 }
 
index 46126ba4d3d0db7680b2a37ca8e43e0e98bb4255..5fc2a2b80ed15fa7a23fa9aaf5949816e52b1c6b 100644 (file)
@@ -118,7 +118,6 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) {
 
     // Verify what toElement returns.
     std::string expected = "{\n"
-        "\"comment\": \"bar\",\n"
         "\"enable-updates\": true,\n"
         "\"server-ip\": \"127.0.0.1\",\n"
         "\"server-port\": 477,\n"
@@ -127,7 +126,7 @@ TEST(D2ClientConfigTest, constructorsAndAccessors) {
         "\"max-queue-size\": 2048,\n"
         "\"ncr-protocol\": \"UDP\",\n"
         "\"ncr-format\": \"JSON\",\n"
-        "\"user-context\": { \"foo\": 1 }\n"
+        "\"user-context\": { \"foo\": 1, \"comment\": \"bar\" }\n"
         "}\n";
     runToElementTest<D2ClientConfig>(expected, *d2_client_config);
 
index 3c4c448e69310432f659c21866923887c66aba7b..34ffb4fa053264157b2ae9bdea0e4adf98b9289d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -1093,24 +1093,24 @@ TEST_F(HostTest, unparse) {
     EXPECT_EQ("{ "
               "\"boot-file-name\": \"\", "
               "\"client-classes\": [  ], "
-              "\"comment\": \"a host reservation\", "
               "\"hostname\": \"myhost.example.com\", "
               "\"hw-address\": \"01:02:03:04:05:06\", "
               "\"ip-address\": \"192.0.2.3\", "
               "\"next-server\": \"0.0.0.0\", "
               "\"option-data\": [  ], "
-              "\"server-hostname\": \"\" "
+              "\"server-hostname\": \"\", "
+              "\"user-context\": { \"comment\": \"a host reservation\" } "
               "}",
               host->toElement4()->str());
 
     EXPECT_EQ("{ "
               "\"client-classes\": [  ], "
-              "\"comment\": \"a host reservation\", "
               "\"hostname\": \"myhost.example.com\", "
               "\"hw-address\": \"01:02:03:04:05:06\", "
               "\"ip-addresses\": [ \"2001:db8:1::cafe\", \"2001:db8:1::1\" ], "
               "\"option-data\": [  ], "
-              "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ] "
+              "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ], "
+              "\"user-context\": { \"comment\": \"a host reservation\" } "
               "}",
               host->toElement6()->str());
 
@@ -1122,23 +1122,23 @@ TEST_F(HostTest, unparse) {
     EXPECT_EQ("{ "
               "\"boot-file-name\": \"\", "
               "\"client-classes\": [  ], "
-              "\"comment\": \"a host reservation\", "
               "\"hostname\": \"\", "
               "\"hw-address\": \"01:02:03:04:05:06\", "
               "\"next-server\": \"0.0.0.0\", "
               "\"option-data\": [  ], "
-              "\"server-hostname\": \"\" "
+              "\"server-hostname\": \"\", "
+              "\"user-context\": { \"comment\": \"a host reservation\" } "
               "}",
               host->toElement4()->str());
 
     EXPECT_EQ("{ "
               "\"client-classes\": [  ], "
-              "\"comment\": \"a host reservation\", "
               "\"hostname\": \"\", "
               "\"hw-address\": \"01:02:03:04:05:06\", "
               "\"ip-addresses\": [ \"2001:db8:1::cafe\", \"2001:db8:1::1\" ], "
               "\"option-data\": [  ], "
-              "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ] "
+              "\"prefixes\": [ \"2001:db8:1:1::/64\", \"2001:db8:1:2::/64\" ], "
+              "\"user-context\": { \"comment\": \"a host reservation\" } "
               "}",
               host->toElement6()->str());
 
index 0aa941174694c85b09a619541d9a6d3c308c36b9..4b490ec96d099dc2ac1f9ee62ad9d9086c5b83e4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -535,7 +535,7 @@ TEST_F(Lease4Test, toElement) {
 
     expected = "{"
         "\"cltt\": 12345678,"
-        "\"comment\": \"a comment\","
+        "\"user-context\": { \"comment\": \"a comment\" },"
         "\"fqdn-fwd\": true,"
         "\"fqdn-rev\": true,"
         "\"hostname\": \"urania.example.org\","
@@ -1119,7 +1119,7 @@ TEST(Lease6Test, toElementAddress) {
 
     expected = "{"
         "\"cltt\": 12345678,"
-        "\"comment\": \"a comment\","
+        "\"user-context\": { \"comment\": \"a comment\" },"
         "\"duid\": \"00:01:02:03:04:05:06:0a:0b:0c:0d:0e:0f\","
         "\"fqdn-fwd\": false,"
         "\"fqdn-rev\": false,"
@@ -1207,15 +1207,17 @@ TEST(Lease6Test, toElementPrefix) {
     l = lease.toElement();
     EXPECT_FALSE(l->contains("hw-address"));
     EXPECT_FALSE(l->contains("user-context"));
-    EXPECT_FALSE(l->contains("comment"));
 
     // And to finish try with a comment.
     lease.setContext(Element::fromJSON("{ \"comment\": \"a comment\" }"));
     l = lease.toElement();
     EXPECT_FALSE(l->contains("hw-address"));
-    EXPECT_FALSE(l->contains("user-context"));
-    ASSERT_TRUE(l->contains("comment"));
-    EXPECT_EQ("a comment", l->get("comment")->stringValue());
+    ConstElementPtr ctx = l->get("user-context");
+    ASSERT_TRUE(ctx);
+    ASSERT_EQ(Element::map, ctx->getType());
+    EXPECT_EQ(1, ctx->size());
+    ASSERT_TRUE(ctx->contains("comment"));
+    EXPECT_EQ("a comment", ctx->get("comment")->stringValue());
 }
 
 // Verify that the IA_NA can be created from JSON.
index ec93caddd820565eeccb95af676a0d737f4ed98b..ee83c601de64aa1f09485ba69a2e42e7927c5e11 100644 (file)
@@ -648,7 +648,6 @@ TEST(SharedNetwork4Test, unparse) {
     network->add(subnet2);
 
     std::string expected = "{\n"
-        "    \"comment\": \"bar\",\n"
         "    \"authoritative\": false,\n"
         "    \"interface\": \"eth1\",\n"
         "    \"match-client-id\": false,\n"
@@ -693,7 +692,7 @@ TEST(SharedNetwork4Test, unparse) {
         "        \"valid-lifetime\": 30\n"
         "      }\n"
         "    ],\n"
-        "    \"user-context\": { \"foo\": 1 },\n"
+        "    \"user-context\": { \"comment\": \"bar\", \"foo\": 1 },\n"
         "    \"valid-lifetime\": 200\n"
         "}\n";
 
index 9040a5d3fb5da33026ee98602f5b817b5a49769c..7a8d1f113fb2f2f0f060d3647678dcb1c43a1c93 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -96,11 +96,14 @@ TEST_F(LoggingInfoTest, defaults) {
     // Add a user context
     std::string comment = "\"comment\": \"foo\"";
     std::string user_context = "{ " + comment + " }";
+    std::string user_context_nl = "{\n" + comment + "\n}";
     EXPECT_FALSE(info_non_verbose.getContext());
     info_non_verbose.setContext(Element::fromJSON(user_context));
     ASSERT_TRUE(info_non_verbose.getContext());
     EXPECT_EQ(user_context, info_non_verbose.getContext()->str());
-    expected = header + comment + ",\n" + begin + "INFO" + dbglvl + "0" + trailer;
+    expected = header;
+    expected += "\"user-context\": " + user_context_nl + ",\n";
+    expected += begin + "INFO" + dbglvl + "0" + trailer;
     runToElementTest<LoggingInfo>(expected, info_non_verbose);
 
     Daemon::setVerbose(true);
@@ -123,7 +126,9 @@ TEST_F(LoggingInfoTest, defaults) {
     info_verbose.setContext(Element::fromJSON(user_context));
     ASSERT_TRUE(info_verbose.getContext());
     EXPECT_EQ(user_context, info_verbose.getContext()->str());
-    expected = header + comment + ",\n" + begin + "DEBUG" + dbglvl + "99" + trailer;
+    expected = header;
+    expected += "\"user-context\": " + user_context_nl + ",\n";
+    expected += begin + "DEBUG" + dbglvl + "99" + trailer;
     runToElementTest<LoggingInfo>(expected, info_verbose);
 }
 
index 33799f39b1a675225a42aec234405f675cdc957b..bad26bc87cc3829dfd6a46f80eb1d0f94c4c4521 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -133,113 +133,5 @@ ConstElementPtr moveComments(ConstElementPtr element) {
     return (result.get());
 }
 
-}; // end of isc::test namespace
-}; // end of isc namespace
-
-namespace {
-
-/// @brief Recursive helper
-///
-/// Instead of returning a unmodified copy a @ref UnModified exception
-/// is raised with the unmodified value
-///
-/// @tparam EP ElementPtr or ConstElementPtr (compiler will infer which one)
-/// @param element the element to traverse
-/// @return a modified copy where comment entries were moved from user-context
-/// or the unmodified original argument encapsulated into a Value
-template<typename EP>
-Value<EP> extractComments1(EP element) {
-    bool modified = false;
-
-    // On lists recurse on items
-    if (element->getType() == Element::list) {
-        ElementPtr result = ElementPtr(new ListElement());
-        typedef std::vector<ElementPtr> ListType;
-        const ListType& list = element->listValue();
-        for (ListType::const_iterator it = list.cbegin();
-             it != list.cend(); ++it) {
-            Value<ElementPtr> item = extractComments1(*it);
-            result->add(item.get());
-            if (!item.isShared()) {
-                modified = true;
-            }
-        }
-        if (!modified) {
-            return (Value<EP>::mkShare(element));
-        } else {
-            return (Value<EP>::mkCopy(result));
-        }
-    } else if (element->getType() != Element::map) {
-        return (Value<EP>::mkShare(element));
-    }
-
-    // Process maps: recurse on items
-    ElementPtr result = ElementPtr(new MapElement());
-    bool has_comment = false;
-    typedef std::map<std::string, ConstElementPtr> map_type;
-    const map_type& map = element->mapValue();
-    for (map_type::const_iterator it = map.cbegin(); it != map.cend(); ++it) {
-        if (it->first == "comment") {
-            // Do not traverse comment entries
-            result->set("comment", it->second);
-        } else if (it->first == "user-context") {
-            if (it->second->contains("comment")) {
-                // Note there is a  entry to move
-                has_comment = true;
-            } else {
-                // Do not traverse user-context entries
-                result->set("user-context", it->second);
-            }
-        } else {
-            // Not comment or user-context
-            Value<ConstElementPtr> item = extractComments1(it->second);
-            result->set(it->first, item.get());
-            if (!item.isShared()) {
-                modified = true;
-            }
-        }
-    }
-    // Check if the value should be not modified
-    if (!has_comment && !modified) {
-        return (Value<EP>::mkShare(element));
-    }
-
-    if (has_comment) {
-        // Move the comment entry
-        const map_type& uc_map = element->get("user-context")->mapValue();
-        ElementPtr user_context = Element::createMap();
-        ConstElementPtr comment;
-        for (map_type::const_iterator it = uc_map.cbegin();
-             it != uc_map.cend(); ++it) {
-            if  (it->first == "comment") {
-                comment = it->second;
-            } else {
-                user_context->set(it->first, it->second);
-            }
-        }
-        if (user_context->size() > 0) {
-            result->set("user-context", user_context);
-        }
-        result->set("comment", comment);
-    }
-
-    return (Value<EP>::mkCopy(result));
-}
-
-} // anonymous namespace
-
-namespace isc {
-namespace test {
-
-ElementPtr extractComments(ElementPtr element) {
-    Value<ElementPtr> result = extractComments1(element);
-    return (result.get());
-}
-
-ConstElementPtr extractComments(ConstElementPtr element) {
-    Value<ConstElementPtr> result = extractComments1(element);
-    return (result.get());
-}
-
-}; // end of isc::test namespace
-}; // end of isc namespace
+} // end of isc::test namespace
+} // end of isc namespace
index 498efe4805d70c7718005dfa980df242a758f750..3a04f41b0b8b28f9abf77981b5f7fa380d6a3e47 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2017-2020 Internet Systems Consortium, Inc. ("ISC")
 //
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -29,23 +29,7 @@ isc::data::ElementPtr moveComments(isc::data::ElementPtr element);
 /// @return a processed copy of element or unmodified element
 isc::data::ConstElementPtr moveComments(isc::data::ConstElementPtr element);
 
-/// @brief Extract comment entries from user-context
-///
-/// Process an element looking for user-context entries carrying
-/// comments and moving these comments at the same level than
-/// user-contexts. As the common case is no comment and this routine
-/// tries to maximize sharing the standard behavior is just to return
-/// the argument unchanged.
-///
-/// @param element
-/// @return a processed copy of element or unmodified element
-isc::data::ElementPtr extractComments(isc::data::ElementPtr element);
-
-/// @brief Extract comment entries from user-context (const variant)
-///
-/// @param element
-/// @return a processed copy of element or unmodified element
-isc::data::ConstElementPtr extractComments(isc::data::ConstElementPtr element);
+/// extractComments was removed.
 
 }; // end of isc::test namespace
 }; // end of isc namespace