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
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
}
},
"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",
},
"hooks-libraries": [
{
- "library": "/opt/local/control-agent-commands.so",
+ "library": "/tmp/k1100/src/bin/agent/tests/.libs/libbasic.so",
"parameters": {
"param1": "foo"
}
"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": [
" }\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"
" }\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"
" \"server-hostname\": \"\"\n"
" },\n"
" {\n"
-" \"comment\": \"a comment\",\n"
" \"boot-file-name\": \"\",\n"
" \"name\": \"both\",\n"
" \"next-server\": \"0.0.0.0\",\n"
" \"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"
" \"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"
" \"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"
" \"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"
" \"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"
" \"server-tag\": \"\",\n"
" \"shared-networks\": [\n"
" {\n"
-" \"comment\": \"A shared network\",\n"
" \"calculate-tee-times\": false,\n"
" \"name\": \"foo\",\n"
" \"option-data\": [ ],\n"
" \"store-extended-info\": false,\n"
" \"subnet4\": [\n"
" {\n"
-" \"comment\": \"A subnet\",\n"
" \"4o6-interface\": \"\",\n"
" \"4o6-interface-id\": \"\",\n"
" \"4o6-subnet\": \"\",\n"
" \"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"
" },\n"
" \"reservations\": [\n"
" {\n"
-" \"comment\": \"A host reservation\",\n"
" \"boot-file-name\": \"\",\n"
" \"client-classes\": [ ],\n"
" \"hostname\": \"foo.example.com\",\n"
" \"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"
" \"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
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;
-// 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
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;
" }\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"
" }\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"
" \"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"
" \"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"
" \"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"
" },\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"
" \"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"
" \"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"
" },\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"
" \"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
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;
-// 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
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;
"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",
},
"model": "kea-dhcp4-server",
"subscribe-changes": true,
+ "user-context": {
+ "comment": "Kea DHCP4 server serving network on floor 13"
+ },
"validate-changes": false
}
},
// 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;
-// 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
// 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"
-// 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
ElementPtr map = gen();
parent.contextToElement(map);
ElementPtr expected = gen();
- merge(expected, ctx);
+ expected->set("user-context", ctx);
EXPECT_EQ(*expected, *map);
}
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);
}
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) {
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);
}
}
-// 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
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);
}
-// 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
/// @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:
-// 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
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);
}
-// 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
// 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
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);
}
-// 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
"},{\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"
-// 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
" \"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"
// Unparse
std::string expected = "[\n"
"{\n"
- " \"comment\": \"foo\",\n"
" \"id\": 123,\n"
" \"subnet\": \"192.0.2.0/26\",\n"
" \"t1-percent\": 0.45,"
" \"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"
" \"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"
// Unparse
std::string expected = "[\n"
"{\n"
- " \"comment\": \"foo\",\n"
" \"id\": 123,\n"
" \"subnet\": \"2001:db8:1::/48\",\n"
" \"t1-percent\": 0.45,"
" \"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"
" \"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"
-// 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
// Unparse it
std::string expected = "{\n"
- "\"comment\": \"" + comment + "\",\n"
"\"name\": \"" + name + "\",\n"
"\"test\": \"" + test + "\",\n"
"\"only-if-required\": true,\n"
"\"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);
}
// 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"
"\"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);
-// 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
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());
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());
-// 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
expected = "{"
"\"cltt\": 12345678,"
- "\"comment\": \"a comment\","
+ "\"user-context\": { \"comment\": \"a comment\" },"
"\"fqdn-fwd\": true,"
"\"fqdn-rev\": true,"
"\"hostname\": \"urania.example.org\","
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,"
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.
network->add(subnet2);
std::string expected = "{\n"
- " \"comment\": \"bar\",\n"
" \"authoritative\": false,\n"
" \"interface\": \"eth1\",\n"
" \"match-client-id\": false,\n"
" \"valid-lifetime\": 30\n"
" }\n"
" ],\n"
- " \"user-context\": { \"foo\": 1 },\n"
+ " \"user-context\": { \"comment\": \"bar\", \"foo\": 1 },\n"
" \"valid-lifetime\": 200\n"
"}\n";
-// 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
// 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);
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);
}
-// 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
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
-// 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
/// @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