libd2_la_SOURCES += d2_process.cc d2_process.h
libd2_la_SOURCES += d2_config.cc d2_config.h
libd2_la_SOURCES += d2_cfg_mgr.cc d2_cfg_mgr.h
+libd2_la_SOURCES += d2_lexer.ll location.hh position.hh stack.hh
+libd2_la_SOURCES += d2_parser.cc d2_parser.h
libd2_la_SOURCES += d2_queue_mgr.cc d2_queue_mgr.h
+libd2_la_SOURCES += d2_simple_parser.cc d2_simple_parser.h
libd2_la_SOURCES += d2_update_message.cc d2_update_message.h
libd2_la_SOURCES += d2_update_mgr.cc d2_update_mgr.h
libd2_la_SOURCES += d2_zone.cc d2_zone.h
libd2_la_SOURCES += nc_remove.cc nc_remove.h
libd2_la_SOURCES += nc_trans.cc nc_trans.h
libd2_la_SOURCES += d2_controller.cc d2_controller.h
+libd2_la_SOURCES += parser_context.cc parser_context.h parser_context_decl.h
nodist_libd2_la_SOURCES = d2_messages.h d2_messages.cc
EXTRA_DIST += d2_messages.mes
kea_dhcp_ddnsdir = $(pkgdatadir)
kea_dhcp_ddns_DATA = dhcp-ddns.spec
+
+if GENERATE_PARSER
+
+parser: d2_lexer.cc location.hh position.hh stack.hh d2_parser.cc d2_parser.h
+ @echo "Flex/bison files regenerated"
+
+# --- Flex/Bison stuff below --------------------------------------------------
+# When debugging grammar issues, it's useful to add -v to bison parameters.
+# bison will generate parser.output file that explains the whole grammar.
+# It can be used to manually follow what's going on in the parser.
+# This is especially useful if yydebug_ is set to 1 as that variable
+# will cause parser to print out its internal state.
+# Call flex with -s to check that the default rule can be suppressed
+# Call bison with -W to get warnings like unmarked empty rules
+# Note C++11 deprecated register still used by flex < 2.6.0
+location.hh position.hh stack.hh d2_parser.cc d2_parser.h: d2_parser.yy
+ $(YACC) --defines=d2_parser.h --report=all --report-file=d2_parser.report -o d2_parser.cc d2_parser.yy
+
+d2_lexer.cc: d2_lexer.ll
+ $(LEX) --prefix d2_parser_ -o d2_lexer.cc d2_lexer.ll
+
+else
+
+parser location.hh position.hh stack.hh d2_parser.cc d2_parser.h d2_lexer.cc:
+ @echo Parser generation disabled. Configure with --enable-generate-parser to enable it.
+
+endif
+
#include <d2/d2_log.h>
#include <d2/d2_cfg_mgr.h>
+#include <d2/d2_simple_parser.h>
#include <util/encode/hex.h>
#include <boost/foreach.hpp>
return (getD2Params()->getConfigSummary());
}
-void
-D2CfgMgr::buildParams(isc::data::ConstElementPtr params_config) {
- // Base class build creates parses and invokes build on each parser.
- // This populate the context scalar stores with all of the parameters.
- DCfgMgrBase::buildParams(params_config);
-
- // Fetch and validate the parameters from the context to create D2Params.
- // We validate them here rather than just relying on D2Param constructor
- // so we can spit out config text position info with errors.
+namespace {
- // Fetch and validate ip_address.
- D2CfgContextPtr context = getD2CfgContext();
- isc::dhcp::StringStoragePtr strings = context->getStringStorage();
- asiolink::IOAddress ip_address(D2Params::DFT_IP_ADDRESS);
+template <typename int_type> int_type
+getInt(const std::string& name, isc::data::ConstElementPtr value) {
+ int64_t val_int = value->intValue();
+ if ((val_int < std::numeric_limits<int_type>::min()) ||
+ (val_int > std::numeric_limits<int_type>::max())) {
+ isc_throw(D2CfgError, "out of range value (" << val_int
+ << ") specified for parameter '" << name
+ << "' (" << value->getPosition() << ")");
+ }
+ return (static_cast<int_type>(val_int));
+}
- std::string ip_address_str = strings->getOptionalParam("ip-address",
- D2Params::
- DFT_IP_ADDRESS);
+isc::asiolink::IOAddress
+getIOAddress(const std::string& name, isc::data::ConstElementPtr value) {
+ std::string str = value->stringValue();
try {
- ip_address = asiolink::IOAddress(ip_address_str);
+ return (isc::asiolink::IOAddress(str));
} catch (const std::exception& ex) {
- isc_throw(D2CfgError, "IP address invalid : \""
- << ip_address_str << "\" ("
- << strings->getPosition("ip-address") << ")");
- }
-
- if ((ip_address.toText() == "0.0.0.0") || (ip_address.toText() == "::")) {
- isc_throw(D2CfgError, "IP address cannot be \"" << ip_address << "\" ("
- << strings->getPosition("ip-address") << ")");
+ isc_throw(D2CfgError, "invalid address (" << str
+ << ") specified for parameter '" << name
+ << "' (" << value->getPosition() << ")");
}
+}
- // Fetch and validate port.
- isc::dhcp::Uint32StoragePtr ints = context->getUint32Storage();
- uint32_t port = ints->getOptionalParam("port", D2Params::DFT_PORT);
-
- if (port == 0) {
- isc_throw(D2CfgError, "port cannot be 0 ("
- << ints->getPosition("port") << ")");
- }
-
- // Fetch and validate dns_server_timeout.
- uint32_t dns_server_timeout
- = ints->getOptionalParam("dns-server-timeout",
- D2Params::DFT_DNS_SERVER_TIMEOUT);
-
- if (dns_server_timeout < 1) {
- isc_throw(D2CfgError, "DNS server timeout must be larger than 0 ("
- << ints->getPosition("dns-server-timeout") << ")");
+dhcp_ddns::NameChangeProtocol
+getProtocol(const std::string& name, isc::data::ConstElementPtr value) {
+ std::string str = value->stringValue();
+ try {
+ return (dhcp_ddns::stringToNcrProtocol(str));
+ } catch (const std::exception& ex) {
+ isc_throw(D2CfgError,
+ "invalid NameChangeRequest protocol (" << str
+ << ") specified for parameter '" << name
+ << "' (" << value->getPosition() << ")");
}
+}
- // Fetch and validate ncr_protocol.
- dhcp_ddns::NameChangeProtocol ncr_protocol;
+dhcp_ddns::NameChangeFormat
+getFormat(const std::string& name, isc::data::ConstElementPtr value) {
+ std::string str = value->stringValue();
try {
- ncr_protocol = dhcp_ddns::
- stringToNcrProtocol(strings->
- getOptionalParam("ncr-protocol",
- D2Params::
- DFT_NCR_PROTOCOL));
+ return (dhcp_ddns::stringToNcrFormat(str));
} catch (const std::exception& ex) {
- isc_throw(D2CfgError, "ncr-protocol : "
- << ex.what() << " ("
- << strings->getPosition("ncr-protocol") << ")");
+ isc_throw(D2CfgError,
+ "invalid NameChangeRequest format (" << str
+ << ") specified for parameter '" << name
+ << "' (" << value->getPosition() << ")");
}
+}
- if (ncr_protocol != dhcp_ddns::NCR_UDP) {
- isc_throw(D2CfgError, "ncr-protocol : "
- << dhcp_ddns::ncrProtocolToString(ncr_protocol)
- << " is not yet supported ("
- << strings->getPosition("ncr-protocol") << ")");
- }
+} // anon
- // Fetch and validate ncr_format.
- dhcp_ddns::NameChangeFormat ncr_format;
+void
+D2CfgMgr::parseElement(const std::string& element_id,
+ isc::data::ConstElementPtr element) {
try {
- ncr_format = dhcp_ddns::
- stringToNcrFormat(strings->
- getOptionalParam("ncr-format",
- D2Params::
- DFT_NCR_FORMAT));
+ // Get D2 specific context.
+ D2CfgContextPtr context = getD2CfgContext();
+
+ if ((element_id == "ip-address") ||
+ (element_id == "ncr-protocol") ||
+ (element_id == "ncr-format") ||
+ (element_id == "port") ||
+ (element_id == "dns-server-timeout")) {
+ // global scalar params require nothing extra be done
+ } else if (element_id == "tsig-keys") {
+ TSIGKeyInfoListParser parser;
+ context->setKeys(parser.parse(element));
+ } else if (element_id == "forward-ddns") {
+ DdnsDomainListMgrParser parser;
+ DdnsDomainListMgrPtr mgr = parser.parse(element, element_id,
+ context->getKeys());
+ context->setForwardMgr(mgr);
+ } else if (element_id == "reverse-ddns") {
+ DdnsDomainListMgrParser parser;
+ DdnsDomainListMgrPtr mgr = parser.parse(element, element_id,
+ context->getKeys());
+ context->setReverseMgr(mgr);
+ } else {
+ // Shouldn't occur if the JSON parser is doing its job.
+ isc_throw(D2CfgError, "Unsupported element: "
+ << element_id << element->getPosition());
+ }
+ } catch (const D2CfgError& ex) {
+ // Should already have a specific error and position info
+ throw ex;
} catch (const std::exception& ex) {
- isc_throw(D2CfgError, "ncr-format : "
- << ex.what() << " ("
- << strings->getPosition("ncr-format") << ")");
+ isc_throw(D2CfgError, "element: " << element_id << " : " << ex.what()
+ << element->getPosition());
}
+};
+
+void
+D2CfgMgr::setCfgDefaults(isc::data::ElementPtr mutable_config) {
+ D2SimpleParser::setAllDefaults(mutable_config);
+}
+
+void
+D2CfgMgr::buildParams(isc::data::ConstElementPtr params_config) {
+
+ // Base class build creates parses and invokes build on each parser.
+ // This populate the context scalar stores with all of the parameters.
+ DCfgMgrBase::buildParams(params_config);
+
+ // Fetch the parameters in the config, performing any logcial
+ // validation required.
+ asiolink::IOAddress ip_address(0);
+ uint32_t port = 0;
+ uint32_t dns_server_timeout = 0;
+ dhcp_ddns::NameChangeProtocol ncr_protocol = dhcp_ddns::NCR_UDP;
+ dhcp_ddns::NameChangeFormat ncr_format = dhcp_ddns::FMT_JSON;
+
+ // Assumes that params_config has had defaults added
+ BOOST_FOREACH(isc::dhcp::ConfigPair param, params_config->mapValue()) {
+ std::string entry(param.first);
+ isc::data::ConstElementPtr value(param.second);
+ try {
+ if (entry == "ip-address") {
+ ip_address = getIOAddress(entry, value);
+ if ((ip_address.toText() == "0.0.0.0") ||
+ (ip_address.toText() == "::")) {
+ isc_throw(D2CfgError, "IP address cannot be \""
+ << ip_address << "\""
+ << " (" << value->getPosition() << ")");
+ }
+ } else if (entry == "port") {
+ port = getInt<uint32_t>(entry, value);
+ } else if (entry == "dns-server-timeout") {
+ dns_server_timeout = getInt<uint32_t>(entry, value);
+ } else if (entry == "ncr-protocol") {
+ ncr_protocol = getProtocol(entry, value);
+ if (ncr_protocol != dhcp_ddns::NCR_UDP) {
+ isc_throw(D2CfgError, "ncr-protocol : "
+ << dhcp_ddns::ncrProtocolToString(ncr_protocol)
+ << " is not yet supported "
+ << " (" << value->getPosition() << ")");
+ }
+ } else if (entry == "ncr-format") {
+ ncr_format = getFormat(entry, value);
+ if (ncr_format != dhcp_ddns::FMT_JSON) {
+ isc_throw(D2CfgError, "NCR Format:"
+ << dhcp_ddns::ncrFormatToString(ncr_format)
+ << " is not yet supported"
+ << " (" << value->getPosition() << ")");
+ }
+ } else {
+ isc_throw(D2CfgError,
+ "unsupported parameter '" << entry
+ << " (" << value->getPosition() << ")");
+ }
+ } catch (const isc::data::TypeError&) {
+ isc_throw(D2CfgError,
+ "invalid value type specified for parameter '" << entry
+ << " (" << value->getPosition() << ")");
+ }
- if (ncr_format != dhcp_ddns::FMT_JSON) {
- isc_throw(D2CfgError, "NCR Format:"
- << dhcp_ddns::ncrFormatToString(ncr_format)
- << " is not yet supported ("
- << strings->getPosition("ncr-format") << ")");
}
// Attempt to create the new client config. This ought to fly as
D2ParamsPtr params(new D2Params(ip_address, port, dns_server_timeout,
ncr_protocol, ncr_format));
- context->getD2Params() = params;
-}
-
-isc::dhcp::ParserPtr
-D2CfgMgr::createConfigParser(const std::string& config_id,
- const isc::data::Element::Position& pos) {
- // Get D2 specific context.
- D2CfgContextPtr context = getD2CfgContext();
-
- // Create parser instance based on element_id.
- isc::dhcp::ParserPtr parser;
- if ((config_id.compare("port") == 0) ||
- (config_id.compare("dns-server-timeout") == 0)) {
- parser.reset(new isc::dhcp::Uint32Parser(config_id,
- context->getUint32Storage()));
- } else if ((config_id.compare("ip-address") == 0) ||
- (config_id.compare("ncr-protocol") == 0) ||
- (config_id.compare("ncr-format") == 0)) {
- parser.reset(new isc::dhcp::StringParser(config_id,
- context->getStringStorage()));
- } else if (config_id == "forward-ddns") {
- parser.reset(new DdnsDomainListMgrParser("forward-ddns",
- context->getForwardMgr(),
- context->getKeys()));
- } else if (config_id == "reverse-ddns") {
- parser.reset(new DdnsDomainListMgrParser("reverse-ddns",
- context->getReverseMgr(),
- context->getKeys()));
- } else if (config_id == "tsig-keys") {
- parser.reset(new TSIGKeyInfoListParser("tsig-key-list",
- context->getKeys()));
- } else {
- isc_throw(NotImplemented,
- "parser error: D2CfgMgr parameter not supported : "
- " (" << config_id << pos << ")");
- }
-
- return (parser);
+ getD2CfgContext()->getD2Params() = params;
}
}; // end of isc::dhcp namespace
-// Copyright (C) 2014-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2017 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 (forward_mgr_);
}
+ /// @brief Sets the forward domain list manager
+ /// @param forward_mgr pointer to the new forward manager
+ void setForwardMgr(DdnsDomainListMgrPtr forward_mgr) {
+ forward_mgr_ = forward_mgr;
+ }
+
/// @brief Fetches the reverse DNS domain list manager.
///
/// @return returns a pointer to the reverse manager.
return (reverse_mgr_);
}
+ /// @brief Sets the reverse domain list manager
+ /// @param reverse_mgr pointer to the new reverse manager
+ void setReverseMgr(DdnsDomainListMgrPtr reverse_mgr) {
+ reverse_mgr_ = reverse_mgr;
+ }
+
/// @brief Fetches the map of TSIG keys.
///
/// @return returns a pointer to the key map.
return (keys_);
}
+ /// @brief Sets the map of TSIG keys
+ ///
+ /// @param keys pointer to the new TSIG key map
+ void setKeys(const TSIGKeyInfoMapPtr& keys) {
+ keys_ = keys;
+ }
+
protected:
/// @brief Copy constructor for use by derivations in clone().
D2CfgContext(const D2CfgContext& rhs);
virtual std::string getConfigSummary(const uint32_t selection);
protected:
+
+ /// @brief Parses an element using alternate parsers
+ ///
+ /// Each element to be parsed is passed first into this method to allow
+ /// it to be processed by SimpleParser derivations if they've been
+ /// implemented. The method should return true if it has processed the
+ /// element or false if the element should be passed onto the original
+ /// DhcpConfigParer mechanisms. This method is invoked in both
+ /// @c DCfgMgrBase::buildParams() and DCfgMgrBase::buildAndCommit().
+ ///
+ /// @param element_id name of the element as it is expected in the cfg
+ /// @param element value of the element as ElementPtr
+ virtual void parseElement(const std::string& element_id,
+ isc::data::ConstElementPtr element);
+
+ /// @brief Adds default values to the given config
+ ///
+ /// Adds the D2 default values to the configuration Element map. This
+ /// method is invoked by @c DCfgMgrBase::paserConfig().
+ ///
+ /// @param mutable_config - configuration to which defaults should be added
+ virtual void setCfgDefaults(isc::data::ElementPtr mutable_config);
+
/// @brief Performs the parsing of the given "params" element.
///
/// Iterates over the set of parameters, creating a parser based on the
/// -# ncr_format is invalid, currently only FMT_JSON is supported
virtual void buildParams(isc::data::ConstElementPtr params_config);
- /// @brief Given an element_id returns an instance of the appropriate
- /// parser.
- ///
- /// It is responsible for top-level or outermost DHCP-DDNS configuration
- /// elements (see dhcp-ddns.spec):
- /// -# ip_address
- /// -# port
- /// -# dns_server_timeout
- /// -# ncr_protocol
- /// -# ncr_format
- /// -# tsig_keys
- /// -# forward_ddns
- /// -# reverse_ddns
- ///
- /// @param element_id is the string name of the element as it will appear
- /// in the configuration set.
- /// @param pos position within the configuration text (or file) of element
- /// to be parsed. This is passed for error messaging.
- ///
- /// @return returns a ParserPtr to the parser instance.
- /// @throw throws DCfgMgrBaseError if an error occurs.
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& element_id,
- const isc::data::Element::Position& pos =
- isc::data::Element::Position());
-
/// @brief Creates an new, blank D2CfgContext context
///
/// This method is used at the beginning of configuration process to
#include <asiolink/io_error.h>
#include <boost/foreach.hpp>
-#include <boost/lexical_cast.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/algorithm/string/predicate.hpp>
// *********************** D2Params *************************
-const char *D2Params::DFT_IP_ADDRESS = "127.0.0.1";
-const size_t D2Params::DFT_PORT = 53001;
-const size_t D2Params::DFT_DNS_SERVER_TIMEOUT = 100;
-const char *D2Params::DFT_NCR_PROTOCOL = "UDP";
-const char *D2Params::DFT_NCR_FORMAT = "JSON";
-
D2Params::D2Params(const isc::asiolink::IOAddress& ip_address,
const size_t port,
const size_t dns_server_timeout,
}
D2Params::D2Params()
- : ip_address_(isc::asiolink::IOAddress(DFT_IP_ADDRESS)),
- port_(DFT_PORT),
- dns_server_timeout_(DFT_DNS_SERVER_TIMEOUT),
+ : ip_address_(isc::asiolink::IOAddress("127.0.0.1")),
+ port_(53001), dns_server_timeout_(100),
ncr_protocol_(dhcp_ddns::NCR_UDP),
ncr_format_(dhcp_ddns::FMT_JSON) {
validateContents();
}
// *********************** DnsServerInfo *************************
-
-const char* DnsServerInfo::EMPTY_IP_STR = "0.0.0.0";
-
DnsServerInfo::DnsServerInfo(const std::string& hostname,
isc::asiolink::IOAddress ip_address, uint32_t port,
bool enabled)
// *********************** TSIGKeyInfoParser *************************
-TSIGKeyInfoParser::TSIGKeyInfoParser(const std::string& entry_name,
- TSIGKeyInfoMapPtr keys)
- : entry_name_(entry_name), keys_(keys), local_scalars_() {
- if (!keys_) {
- isc_throw(D2CfgError, "TSIGKeyInfoParser ctor:"
- " key storage cannot be null");
- }
-}
-
-TSIGKeyInfoParser::~TSIGKeyInfoParser() {
-}
-
-void
-TSIGKeyInfoParser::build(isc::data::ConstElementPtr key_config) {
- isc::dhcp::ConfigPair config_pair;
- // For each element in the key configuration:
- // 1. Create a parser for the element.
- // 2. Invoke the parser's build method passing in the element's
- // configuration.
- // 3. Invoke the parser's commit method to store the element's parsed
- // data to the parser's local storage.
- BOOST_FOREACH (config_pair, key_config->mapValue()) {
- isc::dhcp::ParserPtr parser(createConfigParser(config_pair.first,
- config_pair.second->
- getPosition()));
- parser->build(config_pair.second);
- parser->commit();
- }
-
- std::string name;
- std::string algorithm;
- uint32_t digestbits = 0;
- std::string secret;
- std::map<std::string, isc::data::Element::Position> pos;
-
- // Fetch the key's parsed scalar values from parser's local storage.
- // Only digestbits is optional and doesn't throw when missing
- try {
- pos["name"] = local_scalars_.getParam("name", name);
- pos["algorithm"] = local_scalars_.getParam("algorithm", algorithm);
- pos["digest-bits"] = local_scalars_.getParam("digest-bits", digestbits,
- DCfgContextBase::OPTIONAL);
- pos["secret"] = local_scalars_.getParam("secret", secret);
- } catch (const std::exception& ex) {
- isc_throw(D2CfgError, "TSIG Key incomplete : " << ex.what()
- << " (" << key_config->getPosition() << ")");
- }
-
- // Name cannot be blank.
- if (name.empty()) {
- isc_throw(D2CfgError, "TSIG key must specify name (" << pos["name"] << ")");
- }
-
- // Currently, the premise is that key storage is always empty prior to
- // parsing so we are always adding keys never replacing them. Duplicates
- // are not allowed and should be flagged as a configuration error.
- if (keys_->find(name) != keys_->end()) {
- isc_throw(D2CfgError, "Duplicate TSIG key name specified : " << name
- << " (" << pos["name"] << ")");
- }
+TSIGKeyInfoPtr
+TSIGKeyInfoParser::parse(data::ConstElementPtr key_config) {
+ std::string name = getString(key_config, "name");
+ std::string algorithm = getString(key_config, "algorithm");
+ uint32_t digestbits = getInteger(key_config, "digest-bits");
+ std::string secret = getString(key_config, "secret");
// Algorithm must be valid.
try {
TSIGKeyInfo::stringToAlgorithmName(algorithm);
} catch (const std::exception& ex) {
- isc_throw(D2CfgError, "TSIG key : " << ex.what() << " (" << pos["algorithm"] << ")");
- }
-
- // Not zero Digestbits must be an integral number of octets, greater
- // than 80 and the half of the full length
- if (digestbits > 0) {
- if ((digestbits % 8) != 0) {
- isc_throw(D2CfgError, "Invalid TSIG key digest_bits specified : " <<
- digestbits << " (" << pos["digest-bits"] << ")");
- }
- if (digestbits < 80) {
- isc_throw(D2CfgError, "TSIG key digest_bits too small : " <<
- digestbits << " (" << pos["digest-bits"] << ")");
- }
- if (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA224_STR)) {
- if (digestbits < 112) {
- isc_throw(D2CfgError, "TSIG key digest_bits too small : " <<
- digestbits << " (" << pos["digest-bits"]
- << ")");
- }
- } else if (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA256_STR)) {
- if (digestbits < 128) {
- isc_throw(D2CfgError, "TSIG key digest_bits too small : " <<
- digestbits << " (" << pos["digest-bits"]
- << ")");
- }
- } else if (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA384_STR)) {
- if (digestbits < 192) {
- isc_throw(D2CfgError, "TSIG key digest_bits too small : " <<
- digestbits << " (" << pos["digest-bits"]
- << ")");
- }
- } else if (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA512_STR)) {
- if (digestbits < 256) {
- isc_throw(D2CfgError, "TSIG key digest_bits too small : " <<
- digestbits << " (" << pos["digest-bits"]
- << ")");
- }
- }
- }
-
- // Secret cannot be blank.
- // Cryptolink lib doesn't offer any way to validate these. As long as it
- // isn't blank we'll accept it. If the content is bad, the call to in
- // TSIGKeyInfo::remakeKey() made in the TSIGKeyInfo ctor will throw.
- // We'll deal with that below.
- if (secret.empty()) {
- isc_throw(D2CfgError, "TSIG key must specify secret (" << pos["secret"] << ")");
- }
+ isc_throw(D2CfgError, "tsig-key : " << ex.what()
+ << " (" << getPosition("algorithm", key_config) << ")");
+ }
+
+ // Non-zero digest-bits must be an integral number of octets, greater
+ // than 80 and at least half of the algorithm key length. It defaults
+ // to zero and JSON parsing ensures it's a multiple of 8.
+ if ((digestbits > 0) &&
+ ((digestbits < 80) ||
+ (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA224_STR)
+ && (digestbits < 112)) ||
+ (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA256_STR)
+ && (digestbits < 128)) ||
+ (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA384_STR)
+ && (digestbits < 192)) ||
+ (boost::iequals(algorithm, TSIGKeyInfo::HMAC_SHA512_STR)
+ && (digestbits < 256)))) {
+ isc_throw(D2CfgError, "tsig-key: digest-bits too small : "
+ << " (" << getPosition("digest-bits", key_config) << ")");
+ }
// Everything should be valid, so create the key instance.
// It is possible for the asiodns::dns::TSIGKey create to fail such as
try {
key_info.reset(new TSIGKeyInfo(name, algorithm, secret, digestbits));
} catch (const std::exception& ex) {
- isc_throw(D2CfgError, ex.what() << " (" << key_config->getPosition() << ")");
-
- }
-
- // Add the new TSIGKeyInfo to the key storage.
- (*keys_)[name]=key_info;
-}
-
-isc::dhcp::ParserPtr
-TSIGKeyInfoParser::createConfigParser(const std::string& config_id,
- const isc::data::Element::Position& pos) {
- DhcpConfigParser* parser = NULL;
- // Based on the configuration id of the element, create the appropriate
- // parser. Scalars are set to use the parser's local scalar storage.
- if ((config_id == "name") ||
- (config_id == "algorithm") ||
- (config_id == "secret")) {
- parser = new isc::dhcp::StringParser(config_id,
- local_scalars_.getStringStorage());
- } else if (config_id == "digest-bits") {
- parser = new isc::dhcp::Uint32Parser(config_id,
- local_scalars_.getUint32Storage());
- } else {
- isc_throw(NotImplemented,
- "parser error: TSIGKeyInfo parameter not supported: "
- << config_id << " (" << pos << ")");
+ isc_throw(D2CfgError, ex.what() << " ("
+ << key_config->getPosition() << ")");
}
- // Return the new parser instance.
- return (isc::dhcp::ParserPtr(parser));
-}
-
-void
-TSIGKeyInfoParser::commit() {
+ return (key_info);
}
// *********************** TSIGKeyInfoListParser *************************
-TSIGKeyInfoListParser::TSIGKeyInfoListParser(const std::string& list_name,
- TSIGKeyInfoMapPtr keys)
- :list_name_(list_name), keys_(keys), local_keys_(new TSIGKeyInfoMap()),
- parsers_() {
- if (!keys_) {
- isc_throw(D2CfgError, "TSIGKeyInfoListParser ctor:"
- " key storage cannot be null");
- }
-}
-
-TSIGKeyInfoListParser::~TSIGKeyInfoListParser() {
-}
-
-void
-TSIGKeyInfoListParser::
-build(isc::data::ConstElementPtr key_list) {
- int i = 0;
- isc::data::ConstElementPtr key_config;
- // For each key element in the key list:
- // 1. Create a parser for the key element.
- // 2. Invoke the parser's build method passing in the key's
- // configuration.
- // 3. Add the parser to a local collection of parsers.
+TSIGKeyInfoMapPtr
+TSIGKeyInfoListParser::parse(data::ConstElementPtr key_list) {
+ TSIGKeyInfoMapPtr keys(new TSIGKeyInfoMap());
+ data::ConstElementPtr key_config;
+ TSIGKeyInfoParser key_parser;
BOOST_FOREACH(key_config, key_list->listValue()) {
- // Create a name for the parser based on its position in the list.
- std::string entry_name = boost::lexical_cast<std::string>(i++);
- isc::dhcp::ParserPtr parser(new TSIGKeyInfoParser(entry_name,
- local_keys_));
- parser->build(key_config);
- parsers_.push_back(parser);
- }
-
- // Now that we know we have a valid list, commit that list to the
- // area given to us during construction (i.e. to the d2 context).
- *keys_ = *local_keys_;
-}
-
-void
-TSIGKeyInfoListParser::commit() {
- // Invoke commit on each server parser. This will cause each one to
- // create it's server instance and commit it to storage.
- BOOST_FOREACH(isc::dhcp::ParserPtr parser, parsers_) {
- parser->commit();
- }
-}
+ TSIGKeyInfoPtr key = key_parser.parse(key_config);
-// *********************** DnsServerInfoParser *************************
+ // Duplicates are not allowed and should be flagged as an error.
+ if (keys->find(key->getName()) != keys->end()) {
+ isc_throw(D2CfgError, "Duplicate TSIG key name specified : "
+ << key->getName()
+ << " (" << getPosition("name", key_config) << ")");
+ }
-DnsServerInfoParser::DnsServerInfoParser(const std::string& entry_name,
- DnsServerInfoStoragePtr servers)
- : entry_name_(entry_name), servers_(servers), local_scalars_() {
- if (!servers_) {
- isc_throw(D2CfgError, "DnsServerInfoParser ctor:"
- " server storage cannot be null");
+ (*keys)[key->getName()] = key;
}
-}
-DnsServerInfoParser::~DnsServerInfoParser() {
+ return (keys);
}
-void
-DnsServerInfoParser::build(isc::data::ConstElementPtr server_config) {
- isc::dhcp::ConfigPair config_pair;
- // For each element in the server configuration:
- // 1. Create a parser for the element.
- // 2. Invoke the parser's build method passing in the element's
- // configuration.
- // 3. Invoke the parser's commit method to store the element's parsed
- // data to the parser's local storage.
- BOOST_FOREACH (config_pair, server_config->mapValue()) {
- isc::dhcp::ParserPtr parser(createConfigParser(config_pair.first,
- config_pair.second->
- getPosition()));
- parser->build(config_pair.second);
- parser->commit();
- }
-
- std::string hostname;
- std::string ip_address;
- uint32_t port = DnsServerInfo::STANDARD_DNS_PORT;
- std::map<std::string, isc::data::Element::Position> pos;
+// *********************** DnsServerInfoParser *************************
- // Fetch the server configuration's parsed scalar values from parser's
- // local storage. They're all optional, so no try-catch here.
- pos["hostname"] = local_scalars_.getParam("hostname", hostname,
- DCfgContextBase::OPTIONAL);
- pos["ip-address"] = local_scalars_.getParam("ip-address", ip_address,
- DCfgContextBase::OPTIONAL);
- pos["port"] = local_scalars_.getParam("port", port,
- DCfgContextBase::OPTIONAL);
+DnsServerInfoPtr
+DnsServerInfoParser::parse(data::ConstElementPtr server_config) {
+ std::string hostname = getString(server_config, "hostname");
+ std::string ip_address = getString(server_config, "ip-address");
+ uint32_t port = getInteger(server_config, "port");
// The configuration must specify one or the other.
if (hostname.empty() == ip_address.empty()) {
<< " (" << server_config->getPosition() << ")");
}
- // Port cannot be zero.
- if (port == 0) {
- isc_throw(D2CfgError, "Dns Server : port cannot be 0"
- << " (" << pos["port"] << ")");
- }
-
- DnsServerInfoPtr serverInfo;
+ DnsServerInfoPtr server_info;
if (!hostname.empty()) {
/// @todo when resolvable hostname is supported we create the entry
/// as follows:
/// @code
/// // When hostname is specified, create a valid, blank IOAddress
/// // and then create the DnsServerInfo.
- /// isc::asiolink::IOAddress io_addr(DnsServerInfo::EMPTY_IP_STR);
/// serverInfo.reset(new DnsServerInfo(hostname, io_addr, port));
///
/// @endcode
/// processing.
/// Until then we'll throw unsupported.
isc_throw(D2CfgError, "Dns Server : hostname is not yet supported"
- << " (" << pos["hostname"] << ")");
+ << " (" << getPosition("hostname", server_config) << ")");
} else {
try {
// Create an IOAddress from the IP address string given and then
// create the DnsServerInfo.
isc::asiolink::IOAddress io_addr(ip_address);
- serverInfo.reset(new DnsServerInfo(hostname, io_addr, port));
+ server_info.reset(new DnsServerInfo(hostname, io_addr, port));
} catch (const isc::asiolink::IOError& ex) {
isc_throw(D2CfgError, "Dns Server : invalid IP address : "
- << ip_address << " (" << pos["ip-address"] << ")");
+ << ip_address
+ << " (" << getPosition("ip-address", server_config) << ")");
}
}
- // Add the new DnsServerInfo to the server storage.
- servers_->push_back(serverInfo);
-}
-
-isc::dhcp::ParserPtr
-DnsServerInfoParser::createConfigParser(const std::string& config_id,
- const isc::data::Element::
- Position& pos) {
- DhcpConfigParser* parser = NULL;
- // Based on the configuration id of the element, create the appropriate
- // parser. Scalars are set to use the parser's local scalar storage.
- if ((config_id == "hostname") ||
- (config_id == "ip-address")) {
- parser = new isc::dhcp::StringParser(config_id,
- local_scalars_.getStringStorage());
- } else if (config_id == "port") {
- parser = new isc::dhcp::Uint32Parser(config_id,
- local_scalars_.getUint32Storage());
- } else {
- isc_throw(NotImplemented,
- "parser error: DnsServerInfo parameter not supported: "
- << config_id << " (" << pos << ")");
- }
-
- // Return the new parser instance.
- return (isc::dhcp::ParserPtr(parser));
-}
-
-void
-DnsServerInfoParser::commit() {
+ return(server_info);
}
// *********************** DnsServerInfoListParser *************************
-DnsServerInfoListParser::DnsServerInfoListParser(const std::string& list_name,
- DnsServerInfoStoragePtr servers)
- :list_name_(list_name), servers_(servers), parsers_() {
- if (!servers_) {
- isc_throw(D2CfgError, "DdnsServerInfoListParser ctor:"
- " server storage cannot be null");
- }
-}
-
-DnsServerInfoListParser::~DnsServerInfoListParser(){
-}
-
-void
-DnsServerInfoListParser::
-build(isc::data::ConstElementPtr server_list){
- int i = 0;
- isc::data::ConstElementPtr server_config;
- // For each server element in the server list:
- // 1. Create a parser for the server element.
- // 2. Invoke the parser's build method passing in the server's
- // configuration.
- // 3. Add the parser to a local collection of parsers.
+DnsServerInfoStoragePtr
+DnsServerInfoListParser::parse(data::ConstElementPtr server_list) {
+ DnsServerInfoStoragePtr servers(new DnsServerInfoStorage());
+ data::ConstElementPtr server_config;
+ DnsServerInfoParser parser;
BOOST_FOREACH(server_config, server_list->listValue()) {
- // Create a name for the parser based on its position in the list.
- std::string entry_name = boost::lexical_cast<std::string>(i++);
- isc::dhcp::ParserPtr parser(new DnsServerInfoParser(entry_name,
- servers_));
- parser->build(server_config);
- parsers_.push_back(parser);
- }
-
- // Domains must have at least one server.
- if (parsers_.size() == 0) {
- isc_throw (D2CfgError, "Server List must contain at least one server"
- << " (" << server_list->getPosition() << ")");
+ DnsServerInfoPtr server = parser.parse(server_config);
+ servers->push_back(server);
}
-}
-void
-DnsServerInfoListParser::commit() {
- // Invoke commit on each server parser.
- BOOST_FOREACH(isc::dhcp::ParserPtr parser, parsers_) {
- parser->commit();
- }
+ return (servers);
}
// *********************** DdnsDomainParser *************************
-DdnsDomainParser::DdnsDomainParser(const std::string& entry_name,
- DdnsDomainMapPtr domains,
- TSIGKeyInfoMapPtr keys)
- : entry_name_(entry_name), domains_(domains), keys_(keys),
- local_servers_(new DnsServerInfoStorage()), local_scalars_() {
- if (!domains_) {
- isc_throw(D2CfgError,
- "DdnsDomainParser ctor, domain storage cannot be null");
- }
-}
-
-
-DdnsDomainParser::~DdnsDomainParser() {
-}
-
-void
-DdnsDomainParser::build(isc::data::ConstElementPtr domain_config) {
- // For each element in the domain configuration:
- // 1. Create a parser for the element.
- // 2. Invoke the parser's build method passing in the element's
- // configuration.
- // 3. Invoke the parser's commit method to store the element's parsed
- // data to the parser's local storage.
- isc::dhcp::ConfigPair config_pair;
- BOOST_FOREACH(config_pair, domain_config->mapValue()) {
- isc::dhcp::ParserPtr parser(createConfigParser(config_pair.first,
- config_pair.second->
- getPosition()));
- parser->build(config_pair.second);
- parser->commit();
- }
-
- // Now construct the domain.
- std::string name;
- std::string key_name;
- std::map<std::string, isc::data::Element::Position> pos;
-
-
- // Fetch the parsed scalar values from parser's local storage.
- // Any required that are missing will throw.
- try {
- pos["name"] = local_scalars_.getParam("name", name);
- pos["key-name"] = local_scalars_.getParam("key-name", key_name,
- DCfgContextBase::OPTIONAL);
- } catch (const std::exception& ex) {
- isc_throw(D2CfgError, "DdnsDomain incomplete : " << ex.what()
- << " (" << domain_config->getPosition() << ")");
- }
-
- // Blank domain names are not allowed.
- if (name.empty()) {
- isc_throw(D2CfgError, "DndsDomain : name cannot be blank ("
- << pos["name"] << ")");
- }
-
- // Currently, the premise is that domain storage is always empty
- // prior to parsing so always adding domains never replacing them.
- // Duplicates are not allowed and should be flagged as a configuration
- // error.
- if (domains_->find(name) != domains_->end()) {
- isc_throw(D2CfgError, "Duplicate domain specified:" << name
- << " (" << pos["name"] << ")");
- }
+DdnsDomainPtr DdnsDomainParser::parse(data::ConstElementPtr domain_config,
+ const TSIGKeyInfoMapPtr keys) {
+ std::string name = getString(domain_config, "name");
+ std::string key_name = getString(domain_config, "key-name");
// Key name is optional. If it is not blank, then find the key in the
- /// list of defined keys.
+ // list of defined keys.
TSIGKeyInfoPtr tsig_key_info;
if (!key_name.empty()) {
- if (keys_) {
- TSIGKeyInfoMap::iterator kit = keys_->find(key_name);
- if (kit != keys_->end()) {
+ if (keys) {
+ TSIGKeyInfoMap::iterator kit = keys->find(key_name);
+ if (kit != keys->end()) {
tsig_key_info = kit->second;
}
}
if (!tsig_key_info) {
isc_throw(D2CfgError, "DdnsDomain : " << name
<< " specifies an undefined key: " << key_name
- << " (" << pos["key-name"] << ")");
+ << " (" << getPosition("key-name", domain_config) << ")");
}
}
- // Instantiate the new domain and add it to domain storage.
- DdnsDomainPtr domain(new DdnsDomain(name, local_servers_, tsig_key_info));
-
- // Add the new domain to the domain storage.
- (*domains_)[name] = domain;
-}
+ // Parse the list of DNS servers
+ data::ConstElementPtr servers_config;
+ try {
+ servers_config = domain_config->get("dns-servers");
+ } catch (const std::exception& ex) {
+ isc_throw(D2CfgError, "DdnsDomain : missing dns-server list"
+ << " (" << servers_config->getPosition() << ")");
+ }
-isc::dhcp::ParserPtr
-DdnsDomainParser::createConfigParser(const std::string& config_id,
- const isc::data::Element::Position& pos) {
- DhcpConfigParser* parser = NULL;
- // Based on the configuration id of the element, create the appropriate
- // parser. Scalars are set to use the parser's local scalar storage.
- if ((config_id == "name") ||
- (config_id == "key-name")) {
- parser = new isc::dhcp::StringParser(config_id,
- local_scalars_.getStringStorage());
- } else if (config_id == "dns-servers") {
- // Server list parser is given in our local server storage. It will pass
- // this down to its server parsers and is where they will write their
- // server instances upon commit.
- parser = new DnsServerInfoListParser(config_id, local_servers_);
- } else {
- isc_throw(NotImplemented,
- "parser error: DdnsDomain parameter not supported: "
- << config_id << " (" << pos << ")");
+ DnsServerInfoListParser server_parser;
+ DnsServerInfoStoragePtr servers = server_parser.parse(servers_config);
+ if (servers->size() == 0) {
+ isc_throw(D2CfgError, "DNS server list cannot be empty"
+ << servers_config->getPosition());
}
- // Return the new domain parser instance.
- return (isc::dhcp::ParserPtr(parser));
-}
+ // Instantiate the new domain and add it to domain storage.
+ DdnsDomainPtr domain(new DdnsDomain(name, servers, tsig_key_info));
-void
-DdnsDomainParser::commit() {
+ return(domain);
}
// *********************** DdnsDomainListParser *************************
-DdnsDomainListParser::DdnsDomainListParser(const std::string& list_name,
- DdnsDomainMapPtr domains,
- TSIGKeyInfoMapPtr keys)
- :list_name_(list_name), domains_(domains), keys_(keys), parsers_() {
- if (!domains_) {
- isc_throw(D2CfgError, "DdnsDomainListParser ctor:"
- " domain storage cannot be null");
- }
-}
+DdnsDomainMapPtr DdnsDomainListParser::parse(data::ConstElementPtr domain_list,
+ const TSIGKeyInfoMapPtr keys) {
+ DdnsDomainMapPtr domains(new DdnsDomainMap());
+ DdnsDomainParser parser;
+ data::ConstElementPtr domain_config;
+ BOOST_FOREACH(domain_config, domain_list->listValue()) {
+ DdnsDomainPtr domain = parser.parse(domain_config, keys);
-DdnsDomainListParser::~DdnsDomainListParser(){
-}
+ // Duplicates are not allowed
+ if (domains->find(domain->getName()) != domains->end()) {
+ isc_throw(D2CfgError, "Duplicate domain specified:"
+ << domain->getName()
+ << " (" << getPosition("name", domain_config) << ")");
+ }
-void
-DdnsDomainListParser::
-build(isc::data::ConstElementPtr domain_list){
- // For each domain element in the domain list:
- // 1. Create a parser for the domain element.
- // 2. Invoke the parser's build method passing in the domain's
- // configuration.
- // 3. Add the parser to the local collection of parsers.
- int i = 0;
- isc::data::ConstElementPtr domain_config;
- BOOST_FOREACH(domain_config, domain_list->listValue()) {
- std::string entry_name = boost::lexical_cast<std::string>(i++);
- isc::dhcp::ParserPtr parser(new DdnsDomainParser(entry_name,
- domains_, keys_));
- parser->build(domain_config);
- parsers_.push_back(parser);
+ (*domains)[domain->getName()] = domain;
}
-}
-void
-DdnsDomainListParser::commit() {
- // Invoke commit on each server parser. This will cause each one to
- // create it's server instance and commit it to storage.
- BOOST_FOREACH(isc::dhcp::ParserPtr parser, parsers_) {
- parser->commit();
- }
+ return (domains);
}
-
// *********************** DdnsDomainListMgrParser *************************
-DdnsDomainListMgrParser::DdnsDomainListMgrParser(const std::string& entry_name,
- DdnsDomainListMgrPtr mgr, TSIGKeyInfoMapPtr keys)
- : entry_name_(entry_name), mgr_(mgr), keys_(keys),
- local_domains_(new DdnsDomainMap()), local_scalars_() {
-}
-
-
-DdnsDomainListMgrParser::~DdnsDomainListMgrParser() {
-}
-
-void
-DdnsDomainListMgrParser::build(isc::data::ConstElementPtr domain_config) {
- // For each element in the domain manager configuration:
- // 1. Create a parser for the element.
- // 2. Invoke the parser's build method passing in the element's
- // configuration.
- // 3. Invoke the parser's commit method to store the element's parsed
- // data to the parser's local storage.
- isc::dhcp::ConfigPair config_pair;
- BOOST_FOREACH(config_pair, domain_config->mapValue()) {
- isc::dhcp::ParserPtr parser(createConfigParser(config_pair.first,
- config_pair.second->
- getPosition()));
- parser->build(config_pair.second);
- parser->commit();
- }
+DdnsDomainListMgrPtr
+DdnsDomainListMgrParser::parse(data::ConstElementPtr mgr_config,
+ const std::string& mgr_name,
+ const TSIGKeyInfoMapPtr keys) {
+ DdnsDomainListMgrPtr mgr(new DdnsDomainListMgr(mgr_name));
- // Add the new domain to the domain storage.
- mgr_->setDomains(local_domains_);
-}
+ // Parse the list of domains
+ data::ConstElementPtr domains_config = mgr_config->get("ddns-domains");
+ if (domains_config) {
+ DdnsDomainListParser domain_parser;
+ DdnsDomainMapPtr domains = domain_parser.parse(domains_config, keys);
-isc::dhcp::ParserPtr
-DdnsDomainListMgrParser::createConfigParser(const std::string& config_id,
- const isc::data::Element::
- Position& pos) {
- DhcpConfigParser* parser = NULL;
- if (config_id == "ddns-domains") {
- // Domain list parser is given our local domain storage. It will pass
- // this down to its domain parsers and is where they will write their
- // domain instances upon commit.
- parser = new DdnsDomainListParser(config_id, local_domains_, keys_);
- } else {
- isc_throw(NotImplemented, "parser error: "
- "DdnsDomainListMgr parameter not supported: " << config_id
- << " (" << pos << ")");
+ // Add the new domain to the domain storage.
+ mgr->setDomains(domains);
}
- // Return the new domain parser instance.
- return (isc::dhcp::ParserPtr(parser));
+ return(mgr);
}
-void
-DdnsDomainListMgrParser::commit() {
-}
-
-
}; // end of isc::dhcp namespace
}; // end of isc namespace
#include <asiolink/io_service.h>
#include <cc/data.h>
+#include <cc/simple_parser.h>
#include <dhcpsrv/parsers/dhcp_parsers.h>
#include <dns/tsig.h>
#include <exceptions/exceptions.h>
/// a name, the algorithm method name, optionally the minimum truncated
/// length, and its secret key component.
///
-/// @todo NOTE that TSIG configuration parsing is functional, the use of
-/// TSIG Keys during the actual DNS update transactions is not. This will be
-/// implemented in a future release.
-///
/// Each managed domain list consists of a list one or more domains and is
/// represented by the class DdnsDomainListMgr.
///
/// that the application can carry out DNS update exchanges with it. Servers
/// are represented by the class, DnsServerInfo.
///
-/// The configuration specification for use with Kea is detailed in the file
-/// dhcp-ddns.spec.
-///
/// The parsing class hierarchy reflects this same scheme. Working top down:
///
/// A DdnsDomainListMgrParser parses a managed domain list entry. It handles
/// @brief Acts as a storage vault for D2 global scalar parameters
class D2Params {
public:
- /// @brief Default configuration constants.
- //@{
- /// @todo For now these are hard-coded as configuration layer cannot
- /// readily provide them (see Trac #3358).
- static const char *DFT_IP_ADDRESS;
- static const size_t DFT_PORT;
- static const size_t DFT_DNS_SERVER_TIMEOUT;
- static const char *DFT_NCR_PROTOCOL;
- static const char *DFT_NCR_FORMAT;
- //@}
-
/// @brief Constructor
///
/// @param ip_address IP address at which D2 should listen for NCRs
/// updates.
class DnsServerInfo {
public:
-
/// @brief defines DNS standard port value
static const uint32_t STANDARD_DNS_PORT = 53;
- /// @brief defines an "empty" string version of an ip address.
- static const char* EMPTY_IP_STR;
-
-
/// @brief Constructor
///
/// @param hostname is the resolvable name of the server. If not blank,
/// @brief Defines a pointer for DScalarContext instances.
typedef boost::shared_ptr<DScalarContext> DScalarContextPtr;
-/// @brief Parser for TSIGKeyInfo
+/// @brief Parser for TSIGKeyInfo
///
-/// This class parses the configuration element "tsig-key" defined in
-/// src/bin/d2/dhcp-ddns.spec and creates an instance of a TSIGKeyInfo.
-class TSIGKeyInfoParser : public isc::dhcp::DhcpConfigParser {
+/// This class parses the configuration element "tsig-key"
+/// and creates an instance of a TSIGKeyInfo.
+class TSIGKeyInfoParser : public data::SimpleParser {
public:
- /// @brief Constructor
- ///
- /// @param entry_name is an arbitrary label assigned to this configuration
- /// definition. Since servers are specified in a list this value is likely
- /// be something akin to "key:0", set during parsing.
- /// @param keys is a pointer to the storage area to which the parser
- /// should commit the newly created TSIGKeyInfo instance.
- TSIGKeyInfoParser(const std::string& entry_name, TSIGKeyInfoMapPtr keys);
-
- /// @brief Destructor
- virtual ~TSIGKeyInfoParser();
-
- /// @brief Performs the actual parsing of the given "tsig-key" element.
+ /// @brief Performs the actual parsing of the given "tsig-key" element.
///
/// Parses a configuration for the elements needed to instantiate a
/// TSIGKeyInfo, validates those entries, creates a TSIGKeyInfo instance
- /// then attempts to add to a list of keys
///
/// @param key_config is the "tsig-key" configuration to parse
- virtual void build(isc::data::ConstElementPtr key_config);
-
- /// @brief Creates a parser for the given "tsig-key" member element id.
- ///
- /// The key elements currently supported are(see dhcp-ddns.spec):
- /// 1. name
- /// 2. algorithm
- /// 3. digestbits
- /// 4. secret
///
- /// @param config_id is the "item_name" for a specific member element of
- /// the "tsig-key" specification.
- /// @param pos position within the configuration text (or file) of element
- /// to be parsed. This is passed for error messaging.
- ///
- /// @return returns a pointer to newly created parser.
- ///
- /// @throw D2CfgError if configuration contains an unknown parameter
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& config_id,
- const isc::data::Element::Position& pos =
- isc::data::Element::ZERO_POSITION());
+ /// @return pointer to the new TSIGKeyInfo instance
+ TSIGKeyInfoPtr parse(data::ConstElementPtr key_config);
- /// @brief Commits the TSIGKeyInfo configuration
- /// Currently this method is a NOP, as the key instance is created and
- /// then added to a local list of keys in build().
- virtual void commit();
-
-private:
- /// @brief Arbitrary label assigned to this parser instance.
- /// Since servers are specified in a list this value is likely be something
- /// akin to "key:0", set during parsing. Primarily here for diagnostics.
- std::string entry_name_;
-
- /// @brief Pointer to the storage area to which the parser should commit
- /// the newly created TSIGKeyInfo instance. This is given to us as a
- /// constructor argument by an upper level.
- TSIGKeyInfoMapPtr keys_;
-
- /// @brief Local storage area for scalar parameter values. Use to hold
- /// data until time to commit.
- DScalarContext local_scalars_;
};
/// @brief Parser for a list of TSIGKeyInfos
///
/// This class parses a list of "tsig-key" configuration elements.
-/// (see src/bin/d2/dhcp-ddns.spec). The TSIGKeyInfo instances are added
-/// to the given storage upon commit.
-class TSIGKeyInfoListParser : public isc::dhcp::DhcpConfigParser {
+/// The TSIGKeyInfo instances are added to the given storage upon commit.
+class TSIGKeyInfoListParser : public data::SimpleParser {
public:
-
- /// @brief Constructor
- ///
- /// @param list_name is an arbitrary label assigned to this parser instance.
- /// @param keys is a pointer to the storage area to which the parser
- /// should commit the newly created TSIGKeyInfo instance.
- TSIGKeyInfoListParser(const std::string& list_name, TSIGKeyInfoMapPtr keys);
-
- /// @brief Destructor
- virtual ~TSIGKeyInfoListParser();
-
/// @brief Performs the parsing of the given list "tsig-key" elements.
///
- /// It iterates over each key entry in the list:
- /// 1. Instantiate a TSIGKeyInfoParser for the entry
- /// 2. Pass the element configuration to the parser's build method
- /// 3. Add the parser instance to local storage
+ /// Creates an empty TSIGKeyInfoMap
///
- /// The net effect is to parse all of the key entries in the list
- /// prepping them for commit.
+ /// Instantiates a TSIGKeyInfoParser
+ /// It iterates over each key entry in the list:
+ /// 2. Pass the element configuration to the parser's parse method
+ /// 3. Add the new TSIGKeyInfo instance to the key map
///
/// @param key_list_config is the list of "tsig_key" elements to parse.
- virtual void build(isc::data::ConstElementPtr key_list_config);
-
- /// @brief Commits the list of TSIG keys
///
- /// Iterates over the internal list of TSIGKeyInfoParsers, invoking
- /// commit on each one. Then commits the local list of keys to
- /// storage.
- virtual void commit();
-
-private:
- /// @brief Arbitrary label assigned to this parser instance.
- std::string list_name_;
-
- /// @brief Pointer to the storage area to which the parser should commit
- /// the list of newly created TSIGKeyInfo instances. This is given to us
- /// as a constructor argument by an upper level.
- TSIGKeyInfoMapPtr keys_;
-
- /// @brief Local storage area to which individual key parsers commit.
- TSIGKeyInfoMapPtr local_keys_;
-
- /// @brief Local storage of TSIGKeyInfoParser instances
- isc::dhcp::ParserCollection parsers_;
+ /// @return a map containing the TSIGKeyInfo instances
+ TSIGKeyInfoMapPtr parse(data::ConstElementPtr key_list_config);
};
/// @brief Parser for DnsServerInfo
///
-/// This class parses the configuration element "dns-server" defined in
-/// src/bin/d2/dhcp-ddns.spec and creates an instance of a DnsServerInfo.
-class DnsServerInfoParser : public isc::dhcp::DhcpConfigParser {
+/// This class parses the configuration element "dns-server"
+/// and creates an instance of a DnsServerInfo.
+class DnsServerInfoParser : public data::SimpleParser {
public:
- /// @brief Constructor
- ///
- /// @param entry_name is an arbitrary label assigned to this configuration
- /// definition. Since servers are specified in a list this value is likely
- /// be something akin to "server:0", set during parsing.
- /// @param servers is a pointer to the storage area to which the parser
- /// should commit the newly created DnsServerInfo instance.
- DnsServerInfoParser(const std::string& entry_name,
- DnsServerInfoStoragePtr servers);
-
- /// @brief Destructor
- virtual ~DnsServerInfoParser();
-
/// @brief Performs the actual parsing of the given "dns-server" element.
///
/// Parses a configuration for the elements needed to instantiate a
/// DnsServerInfo, validates those entries, creates a DnsServerInfo instance
- /// then attempts to add to a list of servers.
+ /// and returns it.
///
/// @param server_config is the "dns-server" configuration to parse
///
+ /// @return a pointer to the newly created server instance
+ ///
/// @throw D2CfgError if:
/// -# hostname is not blank, hostname is not yet supported
/// -# ip_address is invalid
/// -# port is 0
- virtual void build(isc::data::ConstElementPtr server_config);
-
- /// @brief Creates a parser for the given "dns-server" member element id.
- ///
- /// The server elements currently supported are(see dhcp-ddns.spec):
- /// 1. hostname
- /// 2. ip_address
- /// 3. port
- ///
- /// @param config_id is the "item_name" for a specific member element of
- /// the "dns-server" specification.
- /// @param pos position within the configuration text (or file) of element
- /// to be parsed. This is passed for error messaging.
- ///
- /// @return returns a pointer to newly created parser.
- ///
- /// @throw D2CfgError if configuration contains an unknown parameter
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& config_id,
- const isc::data::Element::Position& =
- isc::data::Element::ZERO_POSITION());
-
- /// @brief Commits the configured DnsServerInfo
- /// Currently this method is a NOP, as the server instance is created and
- /// then added to the list of servers in build().
- virtual void commit();
-
-private:
- /// @brief Arbitrary label assigned to this parser instance.
- /// Since servers are specified in a list this value is likely be something
- /// akin to "server:0", set during parsing. Primarily here for diagnostics.
- std::string entry_name_;
-
- /// @brief Pointer to the storage area to which the parser should commit
- /// the newly created DnsServerInfo instance. This is given to us as a
- /// constructor argument by an upper level.
- DnsServerInfoStoragePtr servers_;
-
- /// @brief Local storage area for scalar parameter values. Use to hold
- /// data until time to commit.
- DScalarContext local_scalars_;
+ DnsServerInfoPtr parse(data::ConstElementPtr server_config);
};
/// @brief Parser for a list of DnsServerInfos
///
/// This class parses a list of "dns-server" configuration elements.
-/// (see src/bin/d2/dhcp-ddns.spec). The DnsServerInfo instances are added
+/// The DnsServerInfo instances are added
/// to the given storage upon commit.
-class DnsServerInfoListParser : public isc::dhcp::DhcpConfigParser {
+class DnsServerInfoListParser : public data::SimpleParser{
public:
-
- /// @brief Constructor
- ///
- /// @param list_name is an arbitrary label assigned to this parser instance.
- /// @param servers is a pointer to the storage area to which the parser
- /// should commit the newly created DnsServerInfo instance.
- DnsServerInfoListParser(const std::string& list_name,
- DnsServerInfoStoragePtr servers);
-
- /// @brief Destructor
- virtual ~DnsServerInfoListParser();
-
/// @brief Performs the actual parsing of the given list "dns-server"
/// elements.
- /// It iterates over each server entry in the list:
- /// 1. Instantiate a DnsServerInfoParser for the entry
- /// 2. Pass the element configuration to the parser's build method
- /// 3. Add the parser instance to local storage
///
- /// The net effect is to parse all of the server entries in the list
- /// prepping them for commit.
+ /// Creates an empty server list
+ /// It iterates over each server entry in the list:
+ /// 1. Creates a server instance by passing the entry to @c
+ /// DnsSeverInfoParser::parse()
+ /// 2. Adds the server to the server list
///
/// @param server_list_config is the list of "dns-server" elements to parse.
- virtual void build(isc::data::ConstElementPtr server_list_config);
-
- /// @brief Commits the list of DnsServerInfos
- ///
- /// Iterates over the internal list of DdnsServerInfoParsers, invoking
- /// commit on each one.
- virtual void commit();
-
-private:
- /// @brief Arbitrary label assigned to this parser instance.
- std::string list_name_;
-
- /// @brief Pointer to the storage area to which the parser should commit
- /// the list of newly created DnsServerInfo instances. This is given to us
- /// as a constructor argument by an upper level.
- DnsServerInfoStoragePtr servers_;
-
- /// @brief Local storage of DnsServerInfoParser instances
- isc::dhcp::ParserCollection parsers_;
+ /// @return A pointer to the new, populated server list
+ DnsServerInfoStoragePtr parse(data::ConstElementPtr server_list_config);
};
/// @brief Parser for DdnsDomain
///
-/// This class parses the configuration element "ddns-domain" defined in
-/// src/bin/d2/dhcp-ddns.spec and creates an instance of a DdnsDomain.
-class DdnsDomainParser : public isc::dhcp::DhcpConfigParser {
+/// This class parses the configuration element "ddns-domain"
+/// and creates an instance of a DdnsDomain.
+class DdnsDomainParser : public data::SimpleParser {
public:
- /// @brief Constructor
- ///
- /// @param entry_name is an arbitrary label assigned to this configuration
- /// definition. Since domains are specified in a list this value is likely
- /// be something akin to "forward-ddns:0", set during parsing.
- /// @param domains is a pointer to the storage area to which the parser
- /// @param keys is a pointer to a map of the defined TSIG keys.
- /// should commit the newly created DdnsDomain instance.
- DdnsDomainParser(const std::string& entry_name, DdnsDomainMapPtr domains,
- TSIGKeyInfoMapPtr keys);
-
- /// @brief Destructor
- virtual ~DdnsDomainParser();
-
/// @brief Performs the actual parsing of the given "ddns-domain" element.
///
/// Parses a configuration for the elements needed to instantiate a
- /// DdnsDomain, validates those entries, creates a DdnsDomain instance
- /// then attempts to add it to a list of domains.
+ /// DdnsDomain, validates those entries, and creates a DdnsDomain instance.
///
/// @param domain_config is the "ddns-domain" configuration to parse
- virtual void build(isc::data::ConstElementPtr domain_config);
-
- /// @brief Creates a parser for the given "ddns-domain" member element id.
- ///
- /// The domain elements currently supported are(see dhcp-ddns.spec):
- /// 1. name
- /// 2. key_name
- /// 3. dns_servers
- ///
- /// @param config_id is the "item_name" for a specific member element of
- /// the "ddns-domain" specification.
- /// @param pos position within the configuration text (or file) of element
- /// to be parsed. This is passed for error messaging.
+ /// @param keys map of defined TSIG keys
///
- /// @return returns a pointer to newly created parser.
- ///
- /// @throw D2CfgError if configuration contains an unknown parameter
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& config_id,
- const isc::data::Element::Position& pos =
- isc::data::Element::ZERO_POSITION());
-
- /// @brief Commits the configured DdnsDomain
- /// Currently this method is a NOP, as the domain instance is created and
- /// then added to the list of domains in build().
- virtual void commit();
-
-private:
-
- /// @brief Arbitrary label assigned to this parser instance.
- std::string entry_name_;
-
- /// @brief Pointer to the storage area to which the parser should commit
- /// the newly created DdnsDomain instance. This is given to us as a
- /// constructor argument by an upper level.
- DdnsDomainMapPtr domains_;
-
- /// @brief Pointer to the map of defined TSIG keys.
- /// This map is passed into us and contains all of the TSIG keys defined
- /// for this configuration. It is used to validate the key name entry of
- /// DdnsDomains that specify one.
- TSIGKeyInfoMapPtr keys_;
-
- /// @brief Local storage for DnsServerInfo instances. This is passed into
- /// DnsServerInfoListParser(s), which in turn passes it into each
- /// DnsServerInfoParser. When the DnsServerInfoParsers "commit" they add
- /// their server instance to this storage.
- DnsServerInfoStoragePtr local_servers_;
-
- /// @brief Local storage area for scalar parameter values. Use to hold
- /// data until time to commit.
- DScalarContext local_scalars_;
+ /// @return a pointer to the new domain instance
+ DdnsDomainPtr parse(data::ConstElementPtr domain_config,
+ const TSIGKeyInfoMapPtr keys);
};
/// @brief Parser for a list of DdnsDomains
///
-/// This class parses a list of "ddns-domain" configuration elements.
-/// (see src/bin/d2/dhcp-ddns.spec). The DdnsDomain instances are added
-/// to the given storage upon commit.
-class DdnsDomainListParser : public isc::dhcp::DhcpConfigParser {
+/// This class parses a list of "ddns-domain" configuration elements
+/// into a map of DdnsDomains.
+class DdnsDomainListParser : public data::SimpleParser {
public:
-
- /// @brief Constructor
- ///
- /// @param list_name is an arbitrary label assigned to this parser instance.
- /// @param domains is a pointer to the storage area to which the parser
- /// @param keys is a pointer to a map of the defined TSIG keys.
- /// should commit the newly created DdnsDomain instance.
- DdnsDomainListParser(const std::string& list_name,
- DdnsDomainMapPtr domains, TSIGKeyInfoMapPtr keys);
-
- /// @brief Destructor
- virtual ~DdnsDomainListParser();
-
/// @brief Performs the actual parsing of the given list "ddns-domain"
/// elements.
+ /// Creates a new DdnsDomain map
/// It iterates over each domain entry in the list:
- /// 1. Instantiate a DdnsDomainParser for the entry
- /// 2. Pass the element configuration to the parser's build method
- /// 3. Add the parser instance to local storage
- ///
- /// The net effect is to parse all of the domain entries in the list
- /// prepping them for commit.
+ /// 1. Creates a DdnsDomain instance by passing the entry into @c
+ /// DdnsDomainParser::parser()
+ /// 2. Adds the DdnsDomain instance to the domain map
///
/// @param domain_list_config is the list of "ddns-domain" elements to
/// parse.
- virtual void build(isc::data::ConstElementPtr domain_list_config);
-
- /// @brief Commits the list of DdnsDomains
- ///
- /// Iterates over the internal list of DdnsDomainParsers, invoking
- /// commit on each one.
- virtual void commit();
-
-private:
- /// @brief Arbitrary label assigned to this parser instance.
- std::string list_name_;
-
- /// @brief Pointer to the storage area to which the parser should commit
- /// the list of newly created DdnsDomain instances. This is given to us
- /// as a constructor argument by an upper level.
- DdnsDomainMapPtr domains_;
-
- /// @brief Pointer to the map of defined TSIG keys.
- /// This map is passed into us and contains all of the TSIG keys defined
- /// for this configuration. It is used to validate the key name entry of
- /// DdnsDomains that specify one.
- TSIGKeyInfoMapPtr keys_;
-
- /// @brief Local storage of DdnsDomainParser instances
- isc::dhcp::ParserCollection parsers_;
+ /// @param keys map of defined TSIG keys
+ /// @return a pointer to the newly populated domain map
+ DdnsDomainMapPtr parse(data::ConstElementPtr domain_list_config,
+ const TSIGKeyInfoMapPtr keys);
};
/// @brief Parser for DdnsDomainListMgr
///
/// This class parses the configuration elements "forward-ddns" and
-/// "reverse-ddns" as defined in src/bin/d2/dhcp-ddns.spec. It populates the
-/// given DdnsDomainListMgr with parsed information upon commit. Note that
-/// unlike other parsers, this parser does NOT instantiate the final object
-/// during the commit phase, it populates it. It must pre-exist.
-class DdnsDomainListMgrParser : public isc::dhcp::DhcpConfigParser {
+/// "reverse-ddns". It populates the given DdnsDomainListMgr with parsed
+/// information.
+class DdnsDomainListMgrParser : public data::SimpleParser {
public:
- /// @brief Constructor
- ///
- /// @param entry_name is an arbitrary label assigned to this configuration
- /// definition.
- /// @param mgr is a pointer to the DdnsDomainListMgr to populate.
- /// @param keys is a pointer to a map of the defined TSIG keys.
- /// @throw throws D2CfgError if mgr pointer is empty.
- DdnsDomainListMgrParser(const std::string& entry_name,
- DdnsDomainListMgrPtr mgr, TSIGKeyInfoMapPtr keys);
-
- /// @brief Destructor
- virtual ~DdnsDomainListMgrParser();
-
/// @brief Performs the actual parsing of the given manager element.
///
/// Parses a configuration for the elements needed to instantiate a
/// DdnsDomainListMgr, validates those entries, then creates a
/// DdnsDomainListMgr.
///
- /// @param mgr_config is the manager configuration to parse
- virtual void build(isc::data::ConstElementPtr mgr_config);
-
- /// @brief Creates a parser for the given manager member element id.
+ /// @param mgr_config manager configuration to parse
+ /// @param mgr_name convenience label for the manager instance
+ /// @param keys map of defined TSIG keys
///
- /// The manager elements currently supported are (see dhcp-ddns.spec):
- /// 1. ddns_domains
- ///
- /// @param config_id is the "item_name" for a specific member element of
- /// the manager specification.
- /// @param pos position within the configuration text (or file) of element
- /// to be parsed. This is passed for error messaging.
- ///
- /// @return returns a pointer to newly created parser.
- ///
- /// @throw D2CfgError if configuration contains an unknown parameter
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& config_id,
- const isc::data::Element::Position& pos =
- isc::data::Element::ZERO_POSITION());
-
- /// @brief Commits the configured DdsnDomainListMgr
- /// Currently this method is a NOP, as the manager instance is created
- /// in build().
- virtual void commit();
-
-private:
- /// @brief Arbitrary label assigned to this parser instance.
- std::string entry_name_;
-
- /// @brief Pointer to manager instance to which the parser should commit
- /// the parsed data. This is given to us as a constructor argument by an
- /// upper level.
- DdnsDomainListMgrPtr mgr_;
-
- /// @brief Pointer to the map of defined TSIG keys.
- /// This map is passed into us and contains all of the TSIG keys defined
- /// for this configuration. It is used to validate the key name entry of
- /// DdnsDomains that specify one.
- TSIGKeyInfoMapPtr keys_;
-
- /// @brief Local storage for DdnsDomain instances. This is passed into a
- /// DdnsDomainListParser(s), which in turn passes it into each
- /// DdnsDomainParser. When the DdnsDomainParsers "commit" they add their
- /// domain instance to this storage.
- DdnsDomainMapPtr local_domains_;
-
- /// @brief Local storage area for scalar parameter values. Use to hold
- /// data until time to commit.
- /// @todo Currently, the manager has no scalars but this is likely to
- /// change as matching capabilities expand.
- DScalarContext local_scalars_;
+ /// @return a pointer to the new manager instance
+ DdnsDomainListMgrPtr parse(data::ConstElementPtr mgr_config,
+ const std::string& mgr_name,
+ const TSIGKeyInfoMapPtr keys);
};
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
#include <d2/d2_controller.h>
#include <d2/d2_process.h>
+#include <d2/parser_context.h>
#include <process/spec_config.h>
#include <stdlib.h>
}
}
+isc::data::ConstElementPtr
+D2Controller::parseFile(const std::string& file_name) {
+ isc::data::ConstElementPtr elements;
+
+ // Read contents of the file and parse it as JSON
+ D2ParserContext parser;
+ elements = parser.parseFile(file_name, D2ParserContext::PARSER_DHCPDDNS);
+ if (!elements) {
+ isc_throw(isc::BadValue, "no configuration found in file");
+ }
+
+ return (elements);
+}
+
D2Controller::~D2Controller() {
}
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
/// pointer.
virtual process::DProcessBase* createProcess();
+ ///@brief Parse a given file into Elements
+ ///
+ /// Uses bison parsing to parse a JSON configuration file into an
+ /// a element map.
+ ///
+ /// @param file_name pathname of the file to parse
+ ///
+ /// @return pointer to the map of elements created
+ /// @throw BadValue if the file is empty
+ virtual isc::data::ConstElementPtr parseFile(const std::string& file_name);
+
/// @brief Constructor is declared private to maintain the integrity of
/// the singleton instance.
D2Controller();
--- /dev/null
+#line 1 "d2_lexer.cc"
+
+#line 3 "d2_lexer.cc"
+
+#define YY_INT_ALIGNED short int
+
+/* A lexical scanner generated by flex */
+
+/* %not-for-header */
+/* %if-c-only */
+/* %if-not-reentrant */
+#define yy_create_buffer d2_parser__create_buffer
+#define yy_delete_buffer d2_parser__delete_buffer
+#define yy_flex_debug d2_parser__flex_debug
+#define yy_init_buffer d2_parser__init_buffer
+#define yy_flush_buffer d2_parser__flush_buffer
+#define yy_load_buffer_state d2_parser__load_buffer_state
+#define yy_switch_to_buffer d2_parser__switch_to_buffer
+#define yyin d2_parser_in
+#define yyleng d2_parser_leng
+#define yylex d2_parser_lex
+#define yylineno d2_parser_lineno
+#define yyout d2_parser_out
+#define yyrestart d2_parser_restart
+#define yytext d2_parser_text
+#define yywrap d2_parser_wrap
+#define yyalloc d2_parser_alloc
+#define yyrealloc d2_parser_realloc
+#define yyfree d2_parser_free
+
+/* %endif */
+/* %endif */
+/* %ok-for-header */
+
+#define FLEX_SCANNER
+#define YY_FLEX_MAJOR_VERSION 2
+#define YY_FLEX_MINOR_VERSION 6
+#define YY_FLEX_SUBMINOR_VERSION 3
+#if YY_FLEX_SUBMINOR_VERSION > 0
+#define FLEX_BETA
+#endif
+
+/* %if-c++-only */
+/* %endif */
+
+/* %if-c-only */
+ #define yy_create_buffer d2_parser__create_buffer
+
+ #define yy_delete_buffer d2_parser__delete_buffer
+
+ #define yy_scan_buffer d2_parser__scan_buffer
+
+ #define yy_scan_string d2_parser__scan_string
+
+ #define yy_scan_bytes d2_parser__scan_bytes
+
+ #define yy_init_buffer d2_parser__init_buffer
+
+ #define yy_flush_buffer d2_parser__flush_buffer
+
+ #define yy_load_buffer_state d2_parser__load_buffer_state
+
+ #define yy_switch_to_buffer d2_parser__switch_to_buffer
+
+ #define yypush_buffer_state d2_parser_push_buffer_state
+
+ #define yypop_buffer_state d2_parser_pop_buffer_state
+
+ #define yyensure_buffer_stack d2_parser_ensure_buffer_stack
+
+ #define yylex d2_parser_lex
+
+ #define yyrestart d2_parser_restart
+
+ #define yylex_init d2_parser_lex_init
+
+ #define yylex_init_extra d2_parser_lex_init_extra
+
+ #define yylex_destroy d2_parser_lex_destroy
+
+ #define yyget_debug d2_parser_get_debug
+
+ #define yyset_debug d2_parser_set_debug
+
+ #define yyget_extra d2_parser_get_extra
+
+ #define yyset_extra d2_parser_set_extra
+
+ #define yyget_in d2_parser_get_in
+
+ #define yyset_in d2_parser_set_in
+
+ #define yyget_out d2_parser_get_out
+
+ #define yyset_out d2_parser_set_out
+
+ #define yyget_leng d2_parser_get_leng
+
+ #define yyget_text d2_parser_get_text
+
+ #define yyget_lineno d2_parser_get_lineno
+
+ #define yyset_lineno d2_parser_set_lineno
+
+ #define yywrap d2_parser_wrap
+
+/* %endif */
+
+ #define yyalloc d2_parser_alloc
+
+ #define yyrealloc d2_parser_realloc
+
+ #define yyfree d2_parser_free
+
+/* %if-c-only */
+
+ #define yytext d2_parser_text
+
+ #define yyleng d2_parser_leng
+
+ #define yyin d2_parser_in
+
+ #define yyout d2_parser_out
+
+ #define yy_flex_debug d2_parser__flex_debug
+
+ #define yylineno d2_parser_lineno
+
+/* %endif */
+
+/* First, we deal with platform-specific or compiler-specific issues. */
+
+/* begin standard C headers. */
+/* %if-c-only */
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <stdlib.h>
+/* %endif */
+
+/* %if-tables-serialization */
+/* %endif */
+/* end standard C headers. */
+
+/* %if-c-or-c++ */
+/* flex integer type definitions */
+
+#ifndef FLEXINT_H
+#define FLEXINT_H
+
+/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
+
+#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+
+/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
+ * if you want the limit (max/min) macros for int types.
+ */
+#ifndef __STDC_LIMIT_MACROS
+#define __STDC_LIMIT_MACROS 1
+#endif
+
+#include <inttypes.h>
+typedef int8_t flex_int8_t;
+typedef uint8_t flex_uint8_t;
+typedef int16_t flex_int16_t;
+typedef uint16_t flex_uint16_t;
+typedef int32_t flex_int32_t;
+typedef uint32_t flex_uint32_t;
+#else
+typedef signed char flex_int8_t;
+typedef short int flex_int16_t;
+typedef int flex_int32_t;
+typedef unsigned char flex_uint8_t;
+typedef unsigned short int flex_uint16_t;
+typedef unsigned int flex_uint32_t;
+
+/* Limits of integral types. */
+#ifndef INT8_MIN
+#define INT8_MIN (-128)
+#endif
+#ifndef INT16_MIN
+#define INT16_MIN (-32767-1)
+#endif
+#ifndef INT32_MIN
+#define INT32_MIN (-2147483647-1)
+#endif
+#ifndef INT8_MAX
+#define INT8_MAX (127)
+#endif
+#ifndef INT16_MAX
+#define INT16_MAX (32767)
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+#ifndef UINT8_MAX
+#define UINT8_MAX (255U)
+#endif
+#ifndef UINT16_MAX
+#define UINT16_MAX (65535U)
+#endif
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#endif /* ! C99 */
+
+#endif /* ! FLEXINT_H */
+
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+/* TODO: this is always defined, so inline it */
+#define yyconst const
+
+#if defined(__GNUC__) && __GNUC__ >= 3
+#define yynoreturn __attribute__((__noreturn__))
+#else
+#define yynoreturn
+#endif
+
+/* %not-for-header */
+/* Returned upon end-of-file. */
+#define YY_NULL 0
+/* %ok-for-header */
+
+/* %not-for-header */
+/* Promotes a possibly negative, possibly signed char to an
+ * integer in range [0..255] for use as an array index.
+ */
+#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
+/* %ok-for-header */
+
+/* %if-reentrant */
+/* %endif */
+
+/* %if-not-reentrant */
+
+/* %endif */
+
+/* Enter a start condition. This macro really ought to take a parameter,
+ * but we do it the disgusting crufty way forced on us by the ()-less
+ * definition of BEGIN.
+ */
+#define BEGIN (yy_start) = 1 + 2 *
+/* Translate the current start state into a value that can be later handed
+ * to BEGIN to return to the state. The YYSTATE alias is for lex
+ * compatibility.
+ */
+#define YY_START (((yy_start) - 1) / 2)
+#define YYSTATE YY_START
+/* Action number for EOF rule of a given start state. */
+#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
+/* Special action meaning "start processing a new file". */
+#define YY_NEW_FILE d2_parser_restart(d2_parser_in )
+#define YY_END_OF_BUFFER_CHAR 0
+
+/* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k.
+ * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
+ * Ditto for the __ia64__ case accordingly.
+ */
+#define YY_BUF_SIZE 32768
+#else
+#define YY_BUF_SIZE 16384
+#endif /* __ia64__ */
+#endif
+
+/* The state buf must be large enough to hold one state per character in the main buffer.
+ */
+#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
+
+#ifndef YY_TYPEDEF_YY_BUFFER_STATE
+#define YY_TYPEDEF_YY_BUFFER_STATE
+typedef struct yy_buffer_state *YY_BUFFER_STATE;
+#endif
+
+#ifndef YY_TYPEDEF_YY_SIZE_T
+#define YY_TYPEDEF_YY_SIZE_T
+typedef size_t yy_size_t;
+#endif
+
+/* %if-not-reentrant */
+extern int d2_parser_leng;
+/* %endif */
+
+/* %if-c-only */
+/* %if-not-reentrant */
+extern FILE *d2_parser_in, *d2_parser_out;
+/* %endif */
+/* %endif */
+
+#define EOB_ACT_CONTINUE_SCAN 0
+#define EOB_ACT_END_OF_FILE 1
+#define EOB_ACT_LAST_MATCH 2
+
+ #define YY_LESS_LINENO(n)
+ #define YY_LINENO_REWIND_TO(ptr)
+
+/* Return all but the first "n" matched characters back to the input stream. */
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up d2_parser_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ *yy_cp = (yy_hold_char); \
+ YY_RESTORE_YY_MORE_OFFSET \
+ (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
+ YY_DO_BEFORE_ACTION; /* set up d2_parser_text again */ \
+ } \
+ while ( 0 )
+#define unput(c) yyunput( c, (yytext_ptr) )
+
+#ifndef YY_STRUCT_YY_BUFFER_STATE
+#define YY_STRUCT_YY_BUFFER_STATE
+struct yy_buffer_state
+ {
+/* %if-c-only */
+ FILE *yy_input_file;
+/* %endif */
+
+/* %if-c++-only */
+/* %endif */
+
+ char *yy_ch_buf; /* input buffer */
+ char *yy_buf_pos; /* current position in input buffer */
+
+ /* Size of input buffer in bytes, not including room for EOB
+ * characters.
+ */
+ int yy_buf_size;
+
+ /* Number of characters read into yy_ch_buf, not including EOB
+ * characters.
+ */
+ int yy_n_chars;
+
+ /* Whether we "own" the buffer - i.e., we know we created it,
+ * and can realloc() it to grow it, and should free() it to
+ * delete it.
+ */
+ int yy_is_our_buffer;
+
+ /* Whether this is an "interactive" input source; if so, and
+ * if we're using stdio for input, then we want to use getc()
+ * instead of fread(), to make sure we stop fetching input after
+ * each newline.
+ */
+ int yy_is_interactive;
+
+ /* Whether we're considered to be at the beginning of a line.
+ * If so, '^' rules will be active on the next match, otherwise
+ * not.
+ */
+ int yy_at_bol;
+
+ int yy_bs_lineno; /**< The line count. */
+ int yy_bs_column; /**< The column count. */
+
+ /* Whether to try to fill the input buffer when we reach the
+ * end of it.
+ */
+ int yy_fill_buffer;
+
+ int yy_buffer_status;
+
+#define YY_BUFFER_NEW 0
+#define YY_BUFFER_NORMAL 1
+ /* When an EOF's been seen but there's still some text to process
+ * then we mark the buffer as YY_EOF_PENDING, to indicate that we
+ * shouldn't try reading from the input source any more. We might
+ * still have a bunch of tokens to match, though, because of
+ * possible backing-up.
+ *
+ * When we actually see the EOF, we change the status to "new"
+ * (via d2_parser_restart()), so that the user can continue scanning by
+ * just pointing d2_parser_in at a new input file.
+ */
+#define YY_BUFFER_EOF_PENDING 2
+
+ };
+#endif /* !YY_STRUCT_YY_BUFFER_STATE */
+
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+/* %if-not-reentrant */
+
+/* Stack of input buffers. */
+static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
+static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
+static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
+/* %endif */
+/* %ok-for-header */
+
+/* %endif */
+
+/* We provide macros for accessing buffer states in case in the
+ * future we want to put the buffer states in a more general
+ * "scanner state".
+ *
+ * Returns the top of the stack, or NULL.
+ */
+#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
+ ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
+ : NULL)
+/* Same as previous macro, but useful when we know that the buffer stack is not
+ * NULL or when we need an lvalue. For internal use only.
+ */
+#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
+
+/* %if-c-only Standard (non-C++) definition */
+
+/* %if-not-reentrant */
+/* %not-for-header */
+/* yy_hold_char holds the character lost when d2_parser_text is formed. */
+static char yy_hold_char;
+static int yy_n_chars; /* number of characters read into yy_ch_buf */
+int d2_parser_leng;
+
+/* Points to current character in buffer. */
+static char *yy_c_buf_p = NULL;
+static int yy_init = 0; /* whether we need to initialize */
+static int yy_start = 0; /* start state number */
+
+/* Flag which is used to allow d2_parser_wrap()'s to do buffer switches
+ * instead of setting up a fresh d2_parser_in. A bit of a hack ...
+ */
+static int yy_did_buffer_switch_on_eof;
+/* %ok-for-header */
+
+/* %endif */
+
+void d2_parser_restart ( FILE *input_file );
+void d2_parser__switch_to_buffer ( YY_BUFFER_STATE new_buffer );
+YY_BUFFER_STATE d2_parser__create_buffer ( FILE *file, int size );
+void d2_parser__delete_buffer ( YY_BUFFER_STATE b );
+void d2_parser__flush_buffer ( YY_BUFFER_STATE b );
+void d2_parser_push_buffer_state ( YY_BUFFER_STATE new_buffer );
+void d2_parser_pop_buffer_state ( void );
+
+static void d2_parser_ensure_buffer_stack ( void );
+static void d2_parser__load_buffer_state ( void );
+static void d2_parser__init_buffer ( YY_BUFFER_STATE b, FILE *file );
+#define YY_FLUSH_BUFFER d2_parser__flush_buffer(YY_CURRENT_BUFFER )
+
+YY_BUFFER_STATE d2_parser__scan_buffer ( char *base, yy_size_t size );
+YY_BUFFER_STATE d2_parser__scan_string ( const char *yy_str );
+YY_BUFFER_STATE d2_parser__scan_bytes ( const char *bytes, int len );
+
+/* %endif */
+
+void *d2_parser_alloc ( yy_size_t );
+void *d2_parser_realloc ( void *, yy_size_t );
+void d2_parser_free ( void * );
+
+#define yy_new_buffer d2_parser__create_buffer
+#define yy_set_interactive(is_interactive) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){ \
+ d2_parser_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ d2_parser__create_buffer(d2_parser_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
+ }
+#define yy_set_bol(at_bol) \
+ { \
+ if ( ! YY_CURRENT_BUFFER ){\
+ d2_parser_ensure_buffer_stack (); \
+ YY_CURRENT_BUFFER_LVALUE = \
+ d2_parser__create_buffer(d2_parser_in,YY_BUF_SIZE ); \
+ } \
+ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
+ }
+#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
+
+/* %% [1.0] d2_parser_text/d2_parser_in/d2_parser_out/yy_state_type/d2_parser_lineno etc. def's & init go here */
+/* Begin user sect3 */
+
+#define d2_parser_wrap() (/*CONSTCOND*/1)
+#define YY_SKIP_YYWRAP
+
+#define FLEX_DEBUG
+typedef flex_uint8_t YY_CHAR;
+
+FILE *d2_parser_in = NULL, *d2_parser_out = NULL;
+
+typedef int yy_state_type;
+
+extern int d2_parser_lineno;
+int d2_parser_lineno = 1;
+
+extern char *d2_parser_text;
+#ifdef yytext_ptr
+#undef yytext_ptr
+#endif
+#define yytext_ptr d2_parser_text
+
+/* %% [1.5] DFA */
+
+/* %if-c-only Standard (non-C++) definition */
+
+static yy_state_type yy_get_previous_state ( void );
+static yy_state_type yy_try_NUL_trans ( yy_state_type current_state );
+static int yy_get_next_buffer ( void );
+static void yynoreturn yy_fatal_error ( const char* msg );
+
+/* %endif */
+
+/* Done after the current pattern has been matched and before the
+ * corresponding action - sets up d2_parser_text.
+ */
+#define YY_DO_BEFORE_ACTION \
+ (yytext_ptr) = yy_bp; \
+/* %% [2.0] code to fiddle d2_parser_text and d2_parser_leng for yymore() goes here \ */\
+ d2_parser_leng = (int) (yy_cp - yy_bp); \
+ (yy_hold_char) = *yy_cp; \
+ *yy_cp = '\0'; \
+/* %% [3.0] code to copy yytext_ptr to d2_parser_text[] goes here, if %array \ */\
+ (yy_c_buf_p) = yy_cp;
+/* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */
+#define YY_NUM_RULES 58
+#define YY_END_OF_BUFFER 59
+/* This struct is not used in this scanner,
+ but its presence is necessary. */
+struct yy_trans_info
+ {
+ flex_int32_t yy_verify;
+ flex_int32_t yy_nxt;
+ };
+static const flex_int16_t yy_accept[336] =
+ { 0,
+ 51, 51, 0, 0, 0, 0, 0, 0, 0, 0,
+ 59, 57, 10, 11, 57, 1, 51, 48, 51, 51,
+ 57, 50, 49, 57, 57, 57, 57, 57, 44, 45,
+ 57, 57, 57, 46, 47, 5, 5, 5, 57, 57,
+ 57, 10, 11, 0, 0, 40, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 1, 51, 51, 0, 50,
+ 51, 3, 2, 6, 0, 51, 0, 0, 0, 0,
+ 0, 0, 4, 0, 0, 9, 0, 41, 0, 0,
+ 0, 0, 0, 0, 0, 43, 0, 0, 0, 0,
+
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 2, 0, 0, 0, 0, 0,
+ 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
+ 42, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 56, 54, 0, 53, 52, 0, 0, 0, 0,
+ 0, 19, 18, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 55, 52, 0, 0, 0, 0, 0, 20,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 0, 0, 35, 0, 0, 0, 14, 0, 0, 0,
+ 0, 0, 0, 38, 39, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 7, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 34,
+ 0, 0, 30, 0, 0, 0, 31, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 32, 0, 0, 0,
+ 0, 0, 0, 12, 0, 0, 0, 0, 0, 0,
+ 26, 0, 24, 0, 0, 0, 0, 37, 0, 28,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+
+ 27, 0, 36, 0, 0, 0, 0, 13, 17, 0,
+ 0, 0, 0, 29, 0, 25, 0, 0, 0, 0,
+ 23, 0, 21, 16, 0, 22, 0, 0, 0, 33,
+ 0, 0, 0, 15, 0
+ } ;
+
+static const YY_CHAR yy_ec[256] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
+ 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 4, 5, 6, 7, 5, 5, 5, 5, 5,
+ 5, 8, 9, 10, 11, 12, 13, 14, 14, 14,
+ 14, 15, 14, 16, 14, 14, 14, 17, 5, 18,
+ 5, 19, 20, 5, 21, 22, 23, 24, 25, 26,
+ 5, 5, 5, 27, 5, 28, 5, 29, 30, 31,
+ 5, 32, 33, 34, 35, 5, 5, 5, 5, 5,
+ 36, 37, 38, 5, 39, 5, 40, 41, 42, 43,
+
+ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
+ 54, 55, 5, 56, 57, 58, 59, 60, 61, 5,
+ 62, 5, 63, 5, 64, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5
+ } ;
+
+static const YY_CHAR yy_meta[65] =
+ { 0,
+ 1, 1, 2, 3, 3, 4, 3, 3, 3, 3,
+ 3, 3, 3, 5, 5, 5, 3, 3, 3, 3,
+ 5, 5, 5, 5, 5, 5, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 5,
+ 5, 5, 5, 5, 5, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
+ 3, 3, 3, 3
+ } ;
+
+static const flex_int16_t yy_base[348] =
+ { 0,
+ 0, 0, 63, 66, 69, 0, 67, 71, 52, 68,
+ 296, 2262, 87, 289, 133, 0, 96, 2262, 130, 133,
+ 84, 150, 2262, 268, 109, 69, 67, 72, 2262, 2262,
+ 110, 71, 97, 2262, 2262, 2262, 97, 271, 229, 0,
+ 235, 139, 247, 132, 194, 2262, 200, 206, 212, 218,
+ 224, 227, 250, 256, 268, 275, 288, 305, 313, 329,
+ 335, 345, 351, 359, 374, 0, 375, 390, 312, 398,
+ 393, 2262, 0, 2262, 220, 230, 128, 165, 163, 177,
+ 214, 164, 2262, 196, 226, 2262, 148, 2262, 380, 426,
+ 442, 448, 455, 464, 211, 472, 506, 487, 481, 501,
+
+ 534, 551, 557, 563, 572, 584, 590, 596, 604, 613,
+ 622, 628, 637, 650, 0, 240, 247, 127, 246, 267,
+ 185, 160, 2262, 0, 666, 679, 688, 698, 704, 198,
+ 2262, 728, 711, 721, 727, 754, 773, 760, 779, 786,
+ 793, 799, 805, 811, 826, 832, 838, 849, 855, 864,
+ 295, 2262, 2262, 315, 2262, 2262, 113, 0, 882, 870,
+ 910, 2262, 2262, 945, 919, 925, 936, 942, 975, 990,
+ 999, 1005, 1012, 1018, 1032, 1038, 1044, 1055, 1065, 1071,
+ 1083, 1093, 2262, 2262, 120, 0, 1104, 1110, 1116, 2262,
+ 1123, 1163, 1132, 1155, 1162, 1194, 1209, 1217, 1223, 1231,
+
+ 1238, 1255, 2262, 1263, 1278, 1284, 2262, 1292, 1300, 1306,
+ 1322, 115, 0, 2262, 2262, 1329, 1338, 1344, 1350, 1359,
+ 1368, 1387, 1405, 1412, 1419, 1425, 1431, 1444, 1452, 1464,
+ 1470, 1481, 1489, 1496, 2262, 1507, 1514, 1521, 1528, 1535,
+ 1547, 1553, 1560, 1572, 1580, 1590, 1598, 1604, 1617, 2262,
+ 1627, 1636, 2262, 1642, 1649, 1656, 2262, 1664, 1681, 1688,
+ 1694, 1704, 1721, 1732, 1743, 1749, 2262, 1759, 1765, 1771,
+ 1781, 1788, 1803, 2262, 1809, 1826, 1832, 1841, 1847, 1853,
+ 2262, 1864, 2262, 1870, 1885, 1879, 1892, 2262, 1903, 2262,
+ 1909, 1917, 1930, 1941, 1947, 1954, 1962, 1968, 1979, 1987,
+
+ 2262, 2000, 2262, 2006, 2012, 2027, 2044, 2262, 2262, 2052,
+ 2059, 2065, 2071, 2262, 2077, 2262, 2084, 2091, 2103, 2109,
+ 2262, 2117, 2262, 2262, 2128, 2262, 2135, 2141, 2147, 2262,
+ 2156, 2165, 2174, 2262, 2262, 2223, 2228, 2233, 2238, 2243,
+ 2248, 2253, 2256, 146, 132, 91, 88
+ } ;
+
+static const flex_int16_t yy_def[348] =
+ { 0,
+ 335, 1, 336, 336, 1, 5, 5, 5, 5, 5,
+ 335, 335, 335, 335, 337, 338, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 339,
+ 335, 335, 335, 340, 337, 335, 337, 337, 337, 337,
+ 337, 341, 337, 337, 337, 337, 337, 337, 337, 337,
+ 337, 337, 337, 337, 337, 338, 335, 335, 335, 335,
+ 335, 335, 342, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 339, 335, 340, 335, 335, 337,
+ 337, 337, 337, 337, 343, 337, 341, 337, 337, 337,
+
+ 337, 337, 337, 337, 337, 337, 337, 337, 337, 337,
+ 337, 337, 337, 337, 342, 335, 335, 335, 335, 335,
+ 335, 335, 335, 344, 337, 337, 337, 337, 337, 343,
+ 335, 341, 337, 337, 337, 337, 337, 337, 337, 337,
+ 337, 337, 337, 337, 337, 337, 337, 337, 337, 337,
+ 335, 335, 335, 335, 335, 335, 335, 345, 337, 337,
+ 337, 335, 335, 341, 337, 337, 337, 337, 337, 337,
+ 337, 337, 337, 337, 337, 337, 337, 337, 337, 337,
+ 337, 337, 335, 335, 335, 346, 337, 337, 337, 335,
+ 337, 341, 337, 337, 337, 337, 337, 337, 337, 337,
+
+ 337, 337, 335, 337, 337, 337, 335, 337, 337, 337,
+ 337, 335, 347, 335, 335, 337, 337, 337, 337, 337,
+ 337, 337, 337, 337, 337, 337, 337, 337, 337, 337,
+ 337, 337, 337, 337, 335, 337, 337, 337, 337, 337,
+ 337, 337, 337, 337, 337, 337, 337, 337, 337, 335,
+ 337, 337, 335, 337, 337, 337, 335, 337, 337, 337,
+ 337, 337, 337, 337, 337, 337, 335, 337, 337, 337,
+ 337, 337, 337, 335, 337, 337, 337, 337, 337, 337,
+ 335, 337, 335, 337, 337, 337, 337, 335, 337, 335,
+ 337, 337, 337, 337, 337, 337, 337, 337, 337, 337,
+
+ 335, 337, 335, 337, 337, 337, 337, 335, 335, 337,
+ 337, 337, 337, 335, 337, 335, 337, 337, 337, 337,
+ 335, 337, 335, 335, 337, 335, 337, 337, 337, 335,
+ 337, 337, 337, 335, 0, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335
+ } ;
+
+static const flex_int16_t yy_nxt[2327] =
+ { 0,
+ 12, 13, 14, 13, 12, 15, 16, 12, 17, 18,
+ 19, 20, 21, 22, 22, 22, 23, 24, 12, 12,
+ 12, 12, 12, 12, 25, 26, 12, 12, 27, 12,
+ 12, 12, 12, 28, 12, 29, 12, 30, 12, 12,
+ 12, 12, 12, 25, 31, 12, 12, 12, 12, 12,
+ 12, 12, 32, 12, 12, 12, 12, 33, 12, 12,
+ 12, 12, 34, 35, 37, 14, 37, 37, 14, 37,
+ 38, 41, 40, 38, 12, 12, 40, 12, 12, 12,
+ 12, 12, 12, 12, 12, 12, 12, 41, 42, 77,
+ 42, 72, 87, 12, 12, 213, 73, 12, 42, 12,
+
+ 42, 78, 12, 79, 12, 78, 12, 67, 77, 68,
+ 68, 68, 12, 12, 12, 12, 39, 75, 12, 75,
+ 69, 12, 76, 76, 76, 78, 12, 79, 79, 81,
+ 77, 12, 12, 44, 44, 44, 186, 88, 46, 69,
+ 42, 67, 42, 70, 70, 70, 71, 71, 71, 80,
+ 158, 153, 82, 88, 69, 116, 47, 69, 235, 48,
+ 49, 67, 212, 70, 70, 70, 50, 51, 89, 52,
+ 153, 185, 53, 69, 69, 54, 69, 55, 116, 56,
+ 57, 48, 58, 59, 89, 60, 61, 62, 63, 64,
+ 65, 51, 117, 69, 44, 44, 44, 118, 118, 46,
+
+ 44, 44, 44, 131, 116, 46, 44, 44, 44, 153,
+ 157, 46, 44, 44, 44, 117, 131, 46, 44, 44,
+ 44, 118, 121, 46, 44, 44, 44, 119, 156, 46,
+ 52, 123, 96, 76, 76, 76, 52, 122, 91, 45,
+ 93, 117, 52, 76, 76, 76, 90, 94, 52, 43,
+ 44, 44, 44, 86, 52, 46, 44, 44, 44, 93,
+ 52, 46, 91, 45, 120, 92, 94, 45, 44, 44,
+ 44, 45, 151, 46, 152, 44, 44, 44, 151, 45,
+ 46, 84, 45, 83, 45, 97, 52, 74, 44, 44,
+ 44, 43, 52, 46, 152, 335, 151, 152, 99, 100,
+
+ 98, 335, 154, 101, 52, 44, 44, 44, 102, 335,
+ 46, 52, 335, 44, 44, 44, 335, 155, 46, 183,
+ 75, 103, 75, 335, 52, 76, 76, 76, 104, 44,
+ 44, 44, 335, 335, 46, 44, 44, 44, 183, 183,
+ 46, 52, 105, 335, 335, 44, 44, 44, 106, 52,
+ 46, 44, 44, 44, 335, 335, 46, 335, 184, 44,
+ 44, 44, 335, 335, 46, 52, 107, 335, 108, 335,
+ 109, 52, 335, 335, 44, 44, 44, 335, 335, 46,
+ 335, 52, 335, 335, 335, 87, 335, 52, 71, 71,
+ 71, 335, 87, 110, 112, 52, 93, 335, 111, 69,
+
+ 335, 67, 113, 68, 68, 68, 71, 71, 71, 67,
+ 52, 70, 70, 70, 69, 93, 87, 69, 69, 335,
+ 87, 335, 69, 335, 87, 335, 44, 44, 44, 335,
+ 114, 46, 87, 69, 335, 87, 69, 87, 124, 335,
+ 335, 69, 44, 44, 44, 335, 335, 46, 44, 44,
+ 44, 335, 335, 46, 335, 44, 44, 44, 335, 335,
+ 46, 335, 52, 335, 44, 44, 44, 125, 335, 46,
+ 335, 126, 44, 44, 44, 335, 335, 46, 52, 335,
+ 335, 44, 44, 44, 52, 128, 46, 44, 44, 44,
+ 335, 52, 46, 127, 129, 126, 335, 335, 335, 335,
+
+ 52, 44, 44, 44, 335, 335, 46, 335, 52, 128,
+ 335, 335, 335, 335, 335, 335, 335, 52, 129, 132,
+ 132, 132, 335, 52, 335, 335, 132, 132, 132, 132,
+ 132, 132, 133, 134, 44, 44, 44, 52, 335, 46,
+ 335, 135, 335, 335, 335, 132, 132, 132, 132, 132,
+ 132, 44, 44, 44, 335, 335, 46, 44, 44, 44,
+ 335, 335, 46, 44, 44, 44, 335, 335, 46, 335,
+ 52, 335, 44, 44, 44, 335, 335, 46, 335, 136,
+ 335, 335, 140, 335, 44, 44, 44, 52, 335, 46,
+ 44, 44, 44, 52, 335, 46, 44, 44, 44, 52,
+
+ 335, 46, 335, 335, 44, 44, 44, 137, 52, 46,
+ 335, 335, 138, 44, 44, 44, 335, 335, 46, 139,
+ 52, 335, 44, 44, 44, 335, 52, 46, 44, 44,
+ 44, 335, 52, 46, 335, 142, 335, 44, 44, 44,
+ 52, 335, 46, 335, 335, 141, 335, 143, 335, 52,
+ 44, 44, 44, 335, 335, 46, 335, 335, 52, 144,
+ 335, 335, 335, 335, 52, 335, 44, 44, 44, 335,
+ 145, 46, 335, 52, 335, 335, 335, 146, 148, 44,
+ 44, 44, 335, 335, 46, 335, 52, 147, 44, 44,
+ 44, 335, 335, 46, 335, 335, 149, 150, 44, 44,
+
+ 44, 335, 52, 162, 44, 44, 44, 160, 335, 163,
+ 335, 44, 44, 44, 335, 52, 46, 335, 335, 335,
+ 159, 44, 44, 44, 52, 335, 46, 44, 44, 44,
+ 335, 160, 46, 161, 52, 335, 335, 335, 335, 335,
+ 52, 164, 164, 164, 335, 335, 335, 52, 164, 164,
+ 164, 164, 164, 164, 44, 44, 44, 52, 335, 46,
+ 44, 44, 44, 52, 165, 46, 335, 164, 164, 164,
+ 164, 164, 164, 44, 44, 44, 335, 166, 46, 44,
+ 44, 44, 335, 169, 46, 167, 44, 44, 44, 335,
+ 52, 46, 335, 44, 44, 44, 52, 168, 46, 44,
+
+ 44, 44, 335, 173, 46, 44, 44, 44, 335, 52,
+ 46, 44, 44, 44, 335, 52, 46, 335, 335, 335,
+ 170, 176, 52, 335, 335, 172, 44, 44, 44, 52,
+ 335, 46, 44, 44, 44, 52, 171, 46, 44, 44,
+ 44, 52, 335, 46, 174, 335, 335, 52, 175, 44,
+ 44, 44, 335, 335, 46, 44, 44, 44, 335, 335,
+ 46, 335, 52, 335, 44, 44, 44, 335, 52, 46,
+ 44, 44, 44, 335, 52, 190, 335, 335, 335, 335,
+ 177, 179, 44, 44, 44, 52, 335, 46, 335, 178,
+ 335, 52, 335, 335, 335, 335, 187, 188, 181, 335,
+
+ 52, 335, 335, 335, 180, 189, 52, 335, 335, 182,
+ 44, 44, 44, 335, 335, 46, 335, 335, 52, 44,
+ 44, 44, 335, 335, 46, 44, 44, 44, 335, 335,
+ 46, 335, 335, 335, 335, 194, 44, 44, 44, 335,
+ 335, 46, 44, 44, 44, 335, 52, 46, 335, 335,
+ 335, 335, 335, 335, 335, 52, 335, 191, 192, 192,
+ 192, 52, 335, 335, 335, 192, 192, 192, 192, 192,
+ 192, 335, 52, 335, 193, 44, 44, 44, 52, 335,
+ 46, 195, 335, 335, 192, 192, 192, 192, 192, 192,
+ 44, 44, 44, 335, 335, 46, 335, 335, 196, 44,
+
+ 44, 44, 335, 335, 46, 44, 44, 44, 335, 335,
+ 46, 52, 44, 44, 44, 335, 335, 46, 44, 44,
+ 44, 335, 335, 46, 335, 335, 52, 335, 335, 198,
+ 335, 197, 44, 44, 44, 52, 335, 203, 44, 44,
+ 44, 52, 335, 46, 44, 44, 44, 200, 52, 46,
+ 335, 199, 335, 335, 52, 44, 44, 44, 335, 335,
+ 207, 202, 335, 335, 201, 44, 44, 44, 52, 335,
+ 46, 44, 44, 44, 52, 335, 46, 335, 335, 335,
+ 52, 335, 204, 44, 44, 44, 335, 335, 46, 335,
+ 335, 52, 205, 44, 44, 44, 335, 335, 46, 335,
+
+ 335, 52, 206, 211, 44, 44, 44, 52, 335, 214,
+ 44, 44, 44, 335, 209, 215, 44, 44, 44, 52,
+ 208, 46, 335, 44, 44, 44, 335, 335, 46, 52,
+ 335, 335, 44, 44, 44, 335, 335, 46, 210, 335,
+ 52, 335, 335, 335, 335, 335, 52, 335, 335, 335,
+ 335, 335, 52, 335, 335, 44, 44, 44, 216, 52,
+ 46, 335, 44, 44, 44, 335, 335, 46, 52, 335,
+ 335, 335, 335, 335, 335, 217, 45, 45, 45, 218,
+ 335, 335, 335, 45, 45, 45, 45, 45, 45, 335,
+ 335, 52, 335, 335, 44, 44, 44, 219, 52, 46,
+
+ 335, 335, 45, 45, 45, 45, 45, 45, 335, 44,
+ 44, 44, 220, 335, 46, 335, 335, 44, 44, 44,
+ 335, 335, 46, 44, 44, 44, 335, 335, 46, 335,
+ 52, 44, 44, 44, 335, 335, 46, 335, 44, 44,
+ 44, 335, 335, 46, 335, 52, 335, 335, 335, 335,
+ 335, 221, 222, 52, 335, 44, 44, 44, 335, 52,
+ 46, 335, 224, 44, 44, 44, 335, 52, 46, 335,
+ 335, 335, 223, 225, 52, 335, 335, 226, 44, 44,
+ 44, 335, 335, 46, 44, 44, 44, 335, 335, 46,
+ 335, 52, 44, 44, 44, 335, 335, 46, 335, 52,
+
+ 44, 44, 44, 335, 335, 46, 44, 44, 44, 335,
+ 227, 46, 335, 335, 52, 335, 228, 335, 335, 335,
+ 52, 335, 44, 44, 44, 335, 335, 46, 52, 44,
+ 44, 44, 335, 229, 46, 335, 52, 335, 44, 44,
+ 44, 230, 52, 46, 44, 44, 44, 335, 231, 46,
+ 44, 44, 44, 233, 335, 46, 335, 232, 52, 44,
+ 44, 44, 335, 335, 46, 52, 335, 335, 44, 44,
+ 44, 234, 335, 46, 52, 335, 335, 335, 241, 335,
+ 52, 236, 335, 237, 335, 335, 52, 44, 44, 44,
+ 335, 335, 46, 335, 335, 52, 335, 335, 335, 335,
+
+ 335, 238, 240, 239, 52, 44, 44, 44, 335, 335,
+ 46, 335, 44, 44, 44, 335, 335, 46, 335, 44,
+ 44, 44, 335, 52, 46, 44, 44, 44, 335, 335,
+ 46, 44, 44, 44, 335, 335, 46, 335, 335, 335,
+ 335, 52, 242, 335, 44, 44, 44, 243, 52, 46,
+ 335, 335, 44, 44, 44, 52, 335, 46, 335, 335,
+ 335, 52, 335, 244, 44, 44, 44, 52, 335, 250,
+ 44, 44, 44, 335, 245, 46, 246, 335, 335, 335,
+ 52, 44, 44, 44, 335, 335, 253, 247, 52, 44,
+ 44, 44, 335, 335, 46, 335, 44, 44, 44, 248,
+
+ 52, 46, 251, 335, 335, 249, 52, 44, 44, 44,
+ 335, 335, 46, 252, 44, 44, 44, 52, 335, 257,
+ 335, 44, 44, 44, 335, 52, 46, 335, 44, 44,
+ 44, 335, 52, 46, 335, 44, 44, 44, 335, 255,
+ 46, 335, 335, 52, 335, 335, 254, 44, 44, 44,
+ 52, 335, 46, 44, 44, 44, 335, 52, 46, 335,
+ 44, 44, 44, 256, 52, 46, 335, 258, 335, 335,
+ 263, 52, 44, 44, 44, 335, 335, 46, 335, 259,
+ 44, 44, 44, 52, 335, 46, 335, 261, 335, 52,
+ 44, 44, 44, 335, 260, 46, 52, 335, 44, 44,
+
+ 44, 335, 335, 267, 44, 44, 44, 335, 52, 46,
+ 335, 335, 262, 335, 335, 264, 52, 44, 44, 44,
+ 335, 335, 46, 265, 335, 335, 52, 44, 44, 44,
+ 335, 335, 46, 266, 52, 335, 44, 44, 44, 335,
+ 52, 46, 44, 44, 44, 335, 271, 46, 335, 44,
+ 44, 44, 335, 52, 46, 268, 44, 44, 44, 335,
+ 335, 274, 335, 52, 44, 44, 44, 335, 335, 46,
+ 335, 335, 52, 335, 269, 335, 335, 335, 52, 335,
+ 270, 44, 44, 44, 335, 52, 46, 335, 44, 44,
+ 44, 335, 52, 46, 44, 44, 44, 335, 335, 46,
+
+ 52, 335, 335, 272, 44, 44, 44, 335, 335, 46,
+ 273, 335, 335, 335, 335, 275, 335, 52, 335, 335,
+ 276, 44, 44, 44, 52, 335, 46, 335, 335, 335,
+ 52, 277, 44, 44, 44, 335, 335, 281, 335, 335,
+ 52, 278, 335, 44, 44, 44, 335, 279, 46, 44,
+ 44, 44, 335, 335, 283, 335, 335, 52, 335, 44,
+ 44, 44, 335, 280, 46, 44, 44, 44, 52, 335,
+ 46, 44, 44, 44, 335, 335, 46, 335, 335, 52,
+ 335, 44, 44, 44, 335, 52, 46, 335, 44, 44,
+ 44, 335, 335, 288, 335, 52, 335, 335, 284, 282,
+
+ 335, 52, 335, 44, 44, 44, 335, 52, 46, 44,
+ 44, 44, 335, 335, 290, 335, 335, 52, 285, 335,
+ 335, 335, 335, 287, 52, 286, 44, 44, 44, 335,
+ 335, 46, 44, 44, 44, 335, 335, 46, 335, 52,
+ 335, 44, 44, 44, 335, 52, 46, 44, 44, 44,
+ 335, 335, 46, 44, 44, 44, 335, 335, 46, 289,
+ 335, 335, 52, 335, 44, 44, 44, 335, 52, 46,
+ 44, 44, 44, 291, 335, 46, 335, 52, 335, 44,
+ 44, 44, 292, 52, 46, 44, 44, 44, 335, 52,
+ 46, 335, 44, 44, 44, 295, 335, 46, 293, 335,
+
+ 52, 335, 294, 44, 44, 44, 52, 335, 301, 44,
+ 44, 44, 335, 335, 46, 52, 335, 44, 44, 44,
+ 296, 52, 303, 335, 335, 335, 298, 297, 52, 335,
+ 44, 44, 44, 335, 300, 46, 299, 335, 335, 52,
+ 335, 44, 44, 44, 335, 52, 46, 44, 44, 44,
+ 335, 305, 46, 52, 44, 44, 44, 335, 335, 308,
+ 335, 302, 44, 44, 44, 335, 52, 309, 44, 44,
+ 44, 335, 335, 46, 335, 335, 335, 52, 335, 44,
+ 44, 44, 335, 52, 46, 335, 304, 44, 44, 44,
+ 52, 335, 46, 335, 335, 335, 335, 306, 52, 307,
+
+ 44, 44, 44, 335, 52, 46, 44, 44, 44, 335,
+ 335, 314, 44, 44, 44, 52, 335, 46, 335, 335,
+ 335, 310, 335, 52, 335, 335, 311, 44, 44, 44,
+ 335, 335, 316, 335, 335, 335, 52, 335, 335, 312,
+ 335, 335, 52, 335, 44, 44, 44, 335, 52, 46,
+ 335, 335, 44, 44, 44, 335, 313, 46, 335, 44,
+ 44, 44, 335, 52, 46, 44, 44, 44, 335, 315,
+ 46, 44, 44, 44, 335, 335, 321, 44, 44, 44,
+ 52, 335, 46, 335, 44, 44, 44, 335, 52, 323,
+ 335, 44, 44, 44, 335, 52, 324, 335, 335, 335,
+
+ 317, 52, 318, 44, 44, 44, 335, 52, 46, 44,
+ 44, 44, 319, 52, 326, 335, 335, 44, 44, 44,
+ 52, 320, 46, 335, 322, 335, 335, 52, 44, 44,
+ 44, 335, 335, 46, 335, 44, 44, 44, 335, 52,
+ 46, 44, 44, 44, 335, 52, 330, 44, 44, 44,
+ 335, 335, 46, 52, 335, 325, 44, 44, 44, 335,
+ 335, 46, 335, 335, 52, 44, 44, 44, 327, 335,
+ 46, 52, 335, 335, 44, 44, 44, 52, 329, 334,
+ 335, 335, 335, 52, 328, 335, 335, 335, 335, 335,
+ 335, 335, 52, 335, 335, 335, 335, 335, 335, 335,
+
+ 331, 52, 335, 335, 335, 335, 335, 335, 335, 335,
+ 52, 335, 335, 335, 332, 335, 335, 335, 335, 335,
+ 335, 335, 333, 36, 36, 36, 36, 36, 45, 45,
+ 45, 45, 45, 66, 335, 66, 66, 66, 85, 335,
+ 85, 335, 85, 87, 87, 87, 87, 87, 95, 95,
+ 95, 95, 95, 115, 335, 115, 115, 115, 130, 130,
+ 130, 11, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335
+ } ;
+
+static const flex_int16_t yy_chk[2327] =
+ { 0,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 3, 3, 3, 4, 4, 4,
+ 3, 9, 7, 4, 5, 5, 8, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 10, 13, 26,
+ 13, 21, 347, 5, 5, 346, 21, 5, 37, 9,
+
+ 37, 27, 5, 28, 5, 32, 5, 17, 26, 17,
+ 17, 17, 5, 5, 7, 10, 5, 25, 8, 25,
+ 17, 5, 25, 25, 25, 27, 5, 28, 33, 32,
+ 31, 5, 5, 15, 15, 15, 345, 44, 15, 17,
+ 42, 19, 42, 19, 19, 19, 20, 20, 20, 31,
+ 344, 118, 33, 87, 19, 77, 15, 20, 212, 15,
+ 15, 22, 185, 22, 22, 22, 15, 15, 44, 15,
+ 118, 157, 15, 19, 22, 15, 20, 15, 77, 15,
+ 15, 15, 15, 15, 87, 15, 15, 15, 15, 15,
+ 15, 15, 78, 22, 45, 45, 45, 79, 82, 45,
+
+ 47, 47, 47, 130, 80, 47, 48, 48, 48, 121,
+ 122, 48, 49, 49, 49, 78, 95, 49, 50, 50,
+ 50, 79, 82, 50, 51, 51, 51, 80, 121, 51,
+ 45, 85, 52, 75, 75, 75, 47, 84, 48, 52,
+ 50, 81, 48, 76, 76, 76, 47, 51, 49, 43,
+ 53, 53, 53, 41, 50, 53, 54, 54, 54, 50,
+ 51, 54, 48, 52, 81, 49, 51, 52, 55, 55,
+ 55, 52, 116, 55, 117, 56, 56, 56, 119, 52,
+ 56, 39, 52, 38, 52, 52, 53, 24, 57, 57,
+ 57, 14, 54, 57, 120, 11, 116, 117, 54, 54,
+
+ 53, 0, 119, 54, 55, 58, 58, 58, 54, 0,
+ 58, 56, 0, 59, 59, 59, 0, 120, 59, 151,
+ 69, 55, 69, 0, 57, 69, 69, 69, 56, 60,
+ 60, 60, 0, 0, 60, 61, 61, 61, 151, 154,
+ 61, 58, 57, 0, 0, 62, 62, 62, 58, 59,
+ 62, 63, 63, 63, 0, 0, 63, 0, 154, 64,
+ 64, 64, 0, 0, 64, 60, 59, 0, 60, 0,
+ 60, 61, 0, 0, 65, 65, 65, 0, 0, 65,
+ 0, 62, 0, 0, 0, 89, 0, 63, 67, 67,
+ 67, 0, 89, 61, 63, 64, 65, 0, 62, 67,
+
+ 0, 68, 64, 68, 68, 68, 71, 71, 71, 70,
+ 65, 70, 70, 70, 68, 65, 89, 71, 67, 0,
+ 89, 0, 70, 0, 89, 0, 90, 90, 90, 0,
+ 65, 90, 89, 68, 0, 89, 71, 89, 89, 0,
+ 0, 70, 91, 91, 91, 0, 0, 91, 92, 92,
+ 92, 0, 0, 92, 0, 93, 93, 93, 0, 0,
+ 93, 0, 90, 0, 94, 94, 94, 90, 0, 94,
+ 0, 91, 96, 96, 96, 0, 0, 96, 91, 0,
+ 0, 99, 99, 99, 92, 93, 99, 98, 98, 98,
+ 0, 93, 98, 92, 94, 91, 0, 0, 0, 0,
+
+ 94, 100, 100, 100, 0, 0, 100, 0, 96, 93,
+ 0, 0, 0, 0, 0, 0, 0, 99, 94, 97,
+ 97, 97, 0, 98, 0, 0, 97, 97, 97, 97,
+ 97, 97, 98, 99, 101, 101, 101, 100, 0, 101,
+ 0, 100, 0, 0, 0, 97, 97, 97, 97, 97,
+ 97, 102, 102, 102, 0, 0, 102, 103, 103, 103,
+ 0, 0, 103, 104, 104, 104, 0, 0, 104, 0,
+ 101, 0, 105, 105, 105, 0, 0, 105, 0, 101,
+ 0, 0, 105, 0, 106, 106, 106, 102, 0, 106,
+ 107, 107, 107, 103, 0, 107, 108, 108, 108, 104,
+
+ 0, 108, 0, 0, 109, 109, 109, 102, 105, 109,
+ 0, 0, 103, 110, 110, 110, 0, 0, 110, 104,
+ 106, 0, 111, 111, 111, 0, 107, 111, 112, 112,
+ 112, 0, 108, 112, 0, 107, 0, 113, 113, 113,
+ 109, 0, 113, 0, 0, 106, 0, 108, 0, 110,
+ 114, 114, 114, 0, 0, 114, 0, 0, 111, 109,
+ 0, 0, 0, 0, 112, 0, 125, 125, 125, 0,
+ 110, 125, 0, 113, 0, 0, 0, 111, 113, 126,
+ 126, 126, 0, 0, 126, 0, 114, 112, 127, 127,
+ 127, 0, 0, 127, 0, 0, 113, 114, 128, 128,
+
+ 128, 0, 125, 128, 129, 129, 129, 126, 0, 129,
+ 0, 133, 133, 133, 0, 126, 133, 0, 0, 0,
+ 125, 134, 134, 134, 127, 0, 134, 135, 135, 135,
+ 0, 126, 135, 127, 128, 0, 0, 0, 0, 0,
+ 129, 132, 132, 132, 0, 0, 0, 133, 132, 132,
+ 132, 132, 132, 132, 136, 136, 136, 134, 0, 136,
+ 138, 138, 138, 135, 133, 138, 0, 132, 132, 132,
+ 132, 132, 132, 137, 137, 137, 0, 134, 137, 139,
+ 139, 139, 0, 137, 139, 135, 140, 140, 140, 0,
+ 136, 140, 0, 141, 141, 141, 138, 136, 141, 142,
+
+ 142, 142, 0, 141, 142, 143, 143, 143, 0, 137,
+ 143, 144, 144, 144, 0, 139, 144, 0, 0, 0,
+ 138, 144, 140, 0, 0, 140, 145, 145, 145, 141,
+ 0, 145, 146, 146, 146, 142, 139, 146, 147, 147,
+ 147, 143, 0, 147, 142, 0, 0, 144, 143, 148,
+ 148, 148, 0, 0, 148, 149, 149, 149, 0, 0,
+ 149, 0, 145, 0, 150, 150, 150, 0, 146, 150,
+ 160, 160, 160, 0, 147, 160, 0, 0, 0, 0,
+ 145, 147, 159, 159, 159, 148, 0, 159, 0, 146,
+ 0, 149, 0, 0, 0, 0, 159, 159, 149, 0,
+
+ 150, 0, 0, 0, 148, 159, 160, 0, 0, 150,
+ 161, 161, 161, 0, 0, 161, 0, 0, 159, 165,
+ 165, 165, 0, 0, 165, 166, 166, 166, 0, 0,
+ 166, 0, 0, 0, 0, 166, 167, 167, 167, 0,
+ 0, 167, 168, 168, 168, 0, 161, 168, 0, 0,
+ 0, 0, 0, 0, 0, 165, 0, 161, 164, 164,
+ 164, 166, 0, 0, 0, 164, 164, 164, 164, 164,
+ 164, 0, 167, 0, 165, 169, 169, 169, 168, 0,
+ 169, 167, 0, 0, 164, 164, 164, 164, 164, 164,
+ 170, 170, 170, 0, 0, 170, 0, 0, 168, 171,
+
+ 171, 171, 0, 0, 171, 172, 172, 172, 0, 0,
+ 172, 169, 173, 173, 173, 0, 0, 173, 174, 174,
+ 174, 0, 0, 174, 0, 0, 170, 0, 0, 170,
+ 0, 169, 175, 175, 175, 171, 0, 175, 176, 176,
+ 176, 172, 0, 176, 177, 177, 177, 172, 173, 177,
+ 0, 171, 0, 0, 174, 178, 178, 178, 0, 0,
+ 178, 174, 0, 0, 173, 179, 179, 179, 175, 0,
+ 179, 180, 180, 180, 176, 0, 180, 0, 0, 0,
+ 177, 0, 176, 181, 181, 181, 0, 0, 181, 0,
+ 0, 178, 176, 182, 182, 182, 0, 0, 182, 0,
+
+ 0, 179, 177, 182, 187, 187, 187, 180, 0, 187,
+ 188, 188, 188, 0, 180, 188, 189, 189, 189, 181,
+ 179, 189, 0, 191, 191, 191, 0, 0, 191, 182,
+ 0, 0, 193, 193, 193, 0, 0, 193, 181, 0,
+ 187, 0, 0, 0, 0, 0, 188, 0, 0, 0,
+ 0, 0, 189, 0, 0, 194, 194, 194, 189, 191,
+ 194, 0, 195, 195, 195, 0, 0, 195, 193, 0,
+ 0, 0, 0, 0, 0, 191, 192, 192, 192, 193,
+ 0, 0, 0, 192, 192, 192, 192, 192, 192, 0,
+ 0, 194, 0, 0, 196, 196, 196, 194, 195, 196,
+
+ 0, 0, 192, 192, 192, 192, 192, 192, 0, 197,
+ 197, 197, 195, 0, 197, 0, 0, 198, 198, 198,
+ 0, 0, 198, 199, 199, 199, 0, 0, 199, 0,
+ 196, 200, 200, 200, 0, 0, 200, 0, 201, 201,
+ 201, 0, 0, 201, 0, 197, 0, 0, 0, 0,
+ 0, 196, 197, 198, 0, 202, 202, 202, 0, 199,
+ 202, 0, 199, 204, 204, 204, 0, 200, 204, 0,
+ 0, 0, 198, 200, 201, 0, 0, 201, 205, 205,
+ 205, 0, 0, 205, 206, 206, 206, 0, 0, 206,
+ 0, 202, 208, 208, 208, 0, 0, 208, 0, 204,
+
+ 209, 209, 209, 0, 0, 209, 210, 210, 210, 0,
+ 202, 210, 0, 0, 205, 0, 204, 0, 0, 0,
+ 206, 0, 211, 211, 211, 0, 0, 211, 208, 216,
+ 216, 216, 0, 205, 216, 0, 209, 0, 217, 217,
+ 217, 206, 210, 217, 218, 218, 218, 0, 208, 218,
+ 219, 219, 219, 210, 0, 219, 0, 209, 211, 220,
+ 220, 220, 0, 0, 220, 216, 0, 0, 221, 221,
+ 221, 211, 0, 221, 217, 0, 0, 0, 221, 0,
+ 218, 216, 0, 217, 0, 0, 219, 222, 222, 222,
+ 0, 0, 222, 0, 0, 220, 0, 0, 0, 0,
+
+ 0, 218, 220, 219, 221, 223, 223, 223, 0, 0,
+ 223, 0, 224, 224, 224, 0, 0, 224, 0, 225,
+ 225, 225, 0, 222, 225, 226, 226, 226, 0, 0,
+ 226, 227, 227, 227, 0, 0, 227, 0, 0, 0,
+ 0, 223, 222, 0, 228, 228, 228, 223, 224, 228,
+ 0, 0, 229, 229, 229, 225, 0, 229, 0, 0,
+ 0, 226, 0, 224, 230, 230, 230, 227, 0, 230,
+ 231, 231, 231, 0, 225, 231, 226, 0, 0, 0,
+ 228, 232, 232, 232, 0, 0, 232, 227, 229, 233,
+ 233, 233, 0, 0, 233, 0, 234, 234, 234, 228,
+
+ 230, 234, 230, 0, 0, 229, 231, 236, 236, 236,
+ 0, 0, 236, 231, 237, 237, 237, 232, 0, 237,
+ 0, 238, 238, 238, 0, 233, 238, 0, 239, 239,
+ 239, 0, 234, 239, 0, 240, 240, 240, 0, 234,
+ 240, 0, 0, 236, 0, 0, 233, 241, 241, 241,
+ 237, 0, 241, 242, 242, 242, 0, 238, 242, 0,
+ 243, 243, 243, 236, 239, 243, 0, 238, 0, 0,
+ 243, 240, 244, 244, 244, 0, 0, 244, 0, 239,
+ 245, 245, 245, 241, 0, 245, 0, 241, 0, 242,
+ 246, 246, 246, 0, 240, 246, 243, 0, 247, 247,
+
+ 247, 0, 0, 247, 248, 248, 248, 0, 244, 248,
+ 0, 0, 242, 0, 0, 244, 245, 249, 249, 249,
+ 0, 0, 249, 245, 0, 0, 246, 251, 251, 251,
+ 0, 0, 251, 246, 247, 0, 252, 252, 252, 0,
+ 248, 252, 254, 254, 254, 0, 252, 254, 0, 255,
+ 255, 255, 0, 249, 255, 248, 256, 256, 256, 0,
+ 0, 256, 0, 251, 258, 258, 258, 0, 0, 258,
+ 0, 0, 252, 0, 249, 0, 0, 0, 254, 0,
+ 251, 259, 259, 259, 0, 255, 259, 0, 260, 260,
+ 260, 0, 256, 260, 261, 261, 261, 0, 0, 261,
+
+ 258, 0, 0, 254, 262, 262, 262, 0, 0, 262,
+ 255, 0, 0, 0, 0, 258, 0, 259, 0, 0,
+ 259, 263, 263, 263, 260, 0, 263, 0, 0, 0,
+ 261, 260, 264, 264, 264, 0, 0, 264, 0, 0,
+ 262, 261, 0, 265, 265, 265, 0, 262, 265, 266,
+ 266, 266, 0, 0, 266, 0, 0, 263, 0, 268,
+ 268, 268, 0, 263, 268, 269, 269, 269, 264, 0,
+ 269, 270, 270, 270, 0, 0, 270, 0, 0, 265,
+ 0, 271, 271, 271, 0, 266, 271, 0, 272, 272,
+ 272, 0, 0, 272, 0, 268, 0, 0, 268, 265,
+
+ 0, 269, 0, 273, 273, 273, 0, 270, 273, 275,
+ 275, 275, 0, 0, 275, 0, 0, 271, 269, 0,
+ 0, 0, 0, 271, 272, 270, 276, 276, 276, 0,
+ 0, 276, 277, 277, 277, 0, 0, 277, 0, 273,
+ 0, 278, 278, 278, 0, 275, 278, 279, 279, 279,
+ 0, 0, 279, 280, 280, 280, 0, 0, 280, 273,
+ 0, 0, 276, 0, 282, 282, 282, 0, 277, 282,
+ 284, 284, 284, 276, 0, 284, 0, 278, 0, 286,
+ 286, 286, 277, 279, 286, 285, 285, 285, 0, 280,
+ 285, 0, 287, 287, 287, 280, 0, 287, 278, 0,
+
+ 282, 0, 279, 289, 289, 289, 284, 0, 289, 291,
+ 291, 291, 0, 0, 291, 286, 0, 292, 292, 292,
+ 282, 285, 292, 0, 0, 0, 285, 284, 287, 0,
+ 293, 293, 293, 0, 287, 293, 286, 0, 0, 289,
+ 0, 294, 294, 294, 0, 291, 294, 295, 295, 295,
+ 0, 294, 295, 292, 296, 296, 296, 0, 0, 296,
+ 0, 291, 297, 297, 297, 0, 293, 297, 298, 298,
+ 298, 0, 0, 298, 0, 0, 0, 294, 0, 299,
+ 299, 299, 0, 295, 299, 0, 293, 300, 300, 300,
+ 296, 0, 300, 0, 0, 0, 0, 294, 297, 295,
+
+ 302, 302, 302, 0, 298, 302, 304, 304, 304, 0,
+ 0, 304, 305, 305, 305, 299, 0, 305, 0, 0,
+ 0, 298, 0, 300, 0, 0, 299, 306, 306, 306,
+ 0, 0, 306, 0, 0, 0, 302, 0, 0, 300,
+ 0, 0, 304, 0, 307, 307, 307, 0, 305, 307,
+ 0, 0, 310, 310, 310, 0, 302, 310, 0, 311,
+ 311, 311, 0, 306, 311, 312, 312, 312, 0, 305,
+ 312, 313, 313, 313, 0, 0, 313, 315, 315, 315,
+ 307, 0, 315, 0, 317, 317, 317, 0, 310, 317,
+ 0, 318, 318, 318, 0, 311, 318, 0, 0, 0,
+
+ 307, 312, 310, 319, 319, 319, 0, 313, 319, 320,
+ 320, 320, 311, 315, 320, 0, 0, 322, 322, 322,
+ 317, 312, 322, 0, 315, 0, 0, 318, 325, 325,
+ 325, 0, 0, 325, 0, 327, 327, 327, 0, 319,
+ 327, 328, 328, 328, 0, 320, 328, 329, 329, 329,
+ 0, 0, 329, 322, 0, 319, 331, 331, 331, 0,
+ 0, 331, 0, 0, 325, 332, 332, 332, 322, 0,
+ 332, 327, 0, 0, 333, 333, 333, 328, 327, 333,
+ 0, 0, 0, 329, 325, 0, 0, 0, 0, 0,
+ 0, 0, 331, 0, 0, 0, 0, 0, 0, 0,
+
+ 329, 332, 0, 0, 0, 0, 0, 0, 0, 0,
+ 333, 0, 0, 0, 331, 0, 0, 0, 0, 0,
+ 0, 0, 332, 336, 336, 336, 336, 336, 337, 337,
+ 337, 337, 337, 338, 0, 338, 338, 338, 339, 0,
+ 339, 0, 339, 340, 340, 340, 340, 340, 341, 341,
+ 341, 341, 341, 342, 0, 342, 342, 342, 343, 343,
+ 343, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335,
+ 335, 335, 335, 335, 335, 335
+ } ;
+
+static yy_state_type yy_last_accepting_state;
+static char *yy_last_accepting_cpos;
+
+extern int d2_parser__flex_debug;
+int d2_parser__flex_debug = 1;
+
+static const flex_int16_t yy_rule_linenum[58] =
+ { 0,
+ 127, 129, 131, 136, 137, 142, 143, 144, 156, 159,
+ 164, 170, 179, 190, 201, 210, 219, 228, 238, 248,
+ 258, 267, 276, 286, 296, 306, 317, 326, 336, 346,
+ 357, 366, 375, 384, 393, 406, 415, 424, 433, 443,
+ 541, 546, 551, 556, 557, 558, 559, 560, 561, 563,
+ 581, 594, 599, 603, 605, 607, 609
+ } ;
+
+/* The intent behind this definition is that it'll catch
+ * any uses of REJECT which flex missed.
+ */
+#define REJECT reject_used_but_not_detected
+#define yymore() yymore_used_but_not_detected
+#define YY_MORE_ADJ 0
+#define YY_RESTORE_YY_MORE_OFFSET
+char *d2_parser_text;
+#line 1 "d2_lexer.ll"
+/* Copyright (C) 2017 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
+ file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+#line 8 "d2_lexer.ll"
+#include <cerrno>
+#include <climits>
+#include <cstdlib>
+#include <string>
+#include <d2/parser_context.h>
+#include <asiolink/io_address.h>
+#include <boost/lexical_cast.hpp>
+#include <exceptions/exceptions.h>
+
+// Work around an incompatibility in flex (at least versions
+// 2.5.31 through 2.5.33): it generates code that does
+// not conform to C89. See Debian bug 333231
+// <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>.
+# undef yywrap
+# define yywrap() 1
+
+namespace {
+
+bool start_token_flag = false;
+
+isc::d2::D2ParserContext::ParserType start_token_value;
+unsigned int comment_start_line = 0;
+
+};
+
+// To avoid the call to exit... oops!
+#define YY_FATAL_ERROR(msg) isc::d2::D2ParserContext::fatal(msg)
+#line 1282 "d2_lexer.cc"
+/* noyywrap disables automatic rewinding for the next file to parse. Since we
+ always parse only a single string, there's no need to do any wraps. And
+ using yywrap requires linking with -lfl, which provides the default yywrap
+ implementation that always returns 1 anyway. */
+/* nounput simplifies the lexer, by removing support for putting a character
+ back into the input stream. We never use such capability anyway. */
+/* batch means that we'll never use the generated lexer interactively. */
+/* avoid to get static global variables to remain with C++. */
+/* in last resort %option reentrant */
+/* Enables debug mode. To see the debug messages, one needs to also set
+ yy_flex_debug to 1, then the debug messages will be printed on stderr. */
+/* I have no idea what this option does, except it was specified in the bison
+ examples and Postgres folks added it to remove gcc 4.3 warnings. Let's
+ be on the safe side and keep it. */
+#define YY_NO_INPUT 1
+
+/* These are not token expressions yet, just convenience expressions that
+ can be used during actual token definitions. Note some can match
+ incorrect inputs (e.g., IP addresses) which must be checked. */
+/* for errors */
+#line 86 "d2_lexer.ll"
+// This code run each time a pattern is matched. It updates the location
+// by moving it ahead by yyleng bytes. yyleng specifies the length of the
+// currently matched token.
+#define YY_USER_ACTION driver.loc_.columns(yyleng);
+#line 1308 "d2_lexer.cc"
+#line 1309 "d2_lexer.cc"
+
+#define INITIAL 0
+#define COMMENT 1
+#define DIR_ENTER 2
+#define DIR_INCLUDE 3
+#define DIR_EXIT 4
+
+#ifndef YY_NO_UNISTD_H
+/* Special case for "unistd.h", since it is non-ANSI. We include it way
+ * down here because we want the user's section 1 to have been scanned first.
+ * The user has a chance to override it with an option.
+ */
+/* %if-c-only */
+#include <unistd.h>
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+#ifndef YY_EXTRA_TYPE
+#define YY_EXTRA_TYPE void *
+#endif
+
+/* %if-c-only Reentrant structure and macros (non-C++). */
+/* %if-reentrant */
+/* %if-c-only */
+
+static int yy_init_globals ( void );
+
+/* %endif */
+/* %if-reentrant */
+/* %endif */
+/* %endif End reentrant structures and macros. */
+
+/* Accessor methods to globals.
+ These are made visible to non-reentrant scanners for convenience. */
+
+int d2_parser_lex_destroy ( void );
+
+int d2_parser_get_debug ( void );
+
+void d2_parser_set_debug ( int debug_flag );
+
+YY_EXTRA_TYPE d2_parser_get_extra ( void );
+
+void d2_parser_set_extra ( YY_EXTRA_TYPE user_defined );
+
+FILE *d2_parser_get_in ( void );
+
+void d2_parser_set_in ( FILE * _in_str );
+
+FILE *d2_parser_get_out ( void );
+
+void d2_parser_set_out ( FILE * _out_str );
+
+ int d2_parser_get_leng ( void );
+
+char *d2_parser_get_text ( void );
+
+int d2_parser_get_lineno ( void );
+
+void d2_parser_set_lineno ( int _line_number );
+
+/* %if-bison-bridge */
+/* %endif */
+
+/* Macros after this point can all be overridden by user definitions in
+ * section 1.
+ */
+
+#ifndef YY_SKIP_YYWRAP
+#ifdef __cplusplus
+extern "C" int d2_parser_wrap ( void );
+#else
+extern int d2_parser_wrap ( void );
+#endif
+#endif
+
+/* %not-for-header */
+#ifndef YY_NO_UNPUT
+
+#endif
+/* %ok-for-header */
+
+/* %endif */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy ( char *, const char *, int );
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen ( const char * );
+#endif
+
+#ifndef YY_NO_INPUT
+/* %if-c-only Standard (non-C++) definition */
+/* %not-for-header */
+#ifdef __cplusplus
+static int yyinput ( void );
+#else
+static int input ( void );
+#endif
+/* %ok-for-header */
+
+/* %endif */
+#endif
+
+/* %if-c-only */
+
+/* %endif */
+
+/* Amount of stuff to slurp up with each read. */
+#ifndef YY_READ_BUF_SIZE
+#ifdef __ia64__
+/* On IA-64, the buffer size is 16k, not 8k */
+#define YY_READ_BUF_SIZE 16384
+#else
+#define YY_READ_BUF_SIZE 8192
+#endif /* __ia64__ */
+#endif
+
+/* Copy whatever the last rule matched to the standard output. */
+#ifndef ECHO
+/* %if-c-only Standard (non-C++) definition */
+/* This used to be an fputs(), but since the string might contain NUL's,
+ * we now use fwrite().
+ */
+#define ECHO do { if (fwrite( d2_parser_text, (size_t) d2_parser_leng, 1, d2_parser_out )) {} } while (0)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif
+
+/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
+ * is returned in "result".
+ */
+#ifndef YY_INPUT
+#define YY_INPUT(buf,result,max_size) \
+/* %% [5.0] fread()/read() definition of YY_INPUT goes here unless we're doing C++ \ */\
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
+ { \
+ int c = '*'; \
+ int n; \
+ for ( n = 0; n < max_size && \
+ (c = getc( d2_parser_in )) != EOF && c != '\n'; ++n ) \
+ buf[n] = (char) c; \
+ if ( c == '\n' ) \
+ buf[n++] = (char) c; \
+ if ( c == EOF && ferror( d2_parser_in ) ) \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, d2_parser_in)) == 0 && ferror(d2_parser_in)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(d2_parser_in); \
+ } \
+ }\
+\
+/* %if-c++-only C++ definition \ */\
+/* %endif */
+
+#endif
+
+/* No semi-colon after return; correct usage is to write "yyterminate();" -
+ * we don't want an extra ';' after the "return" because that will cause
+ * some compilers to complain about unreachable statements.
+ */
+#ifndef yyterminate
+#define yyterminate() return YY_NULL
+#endif
+
+/* Number of entries by which start-condition stack grows. */
+#ifndef YY_START_STACK_INCR
+#define YY_START_STACK_INCR 25
+#endif
+
+/* Report a fatal error. */
+#ifndef YY_FATAL_ERROR
+/* %if-c-only */
+#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+#endif
+
+/* %if-tables-serialization structures and prototypes */
+/* %not-for-header */
+/* %ok-for-header */
+
+/* %not-for-header */
+/* %tables-yydmap generated elements */
+/* %endif */
+/* end tables serialization structures and prototypes */
+
+/* %ok-for-header */
+
+/* Default declaration of generated scanner - a define so the user can
+ * easily add parameters.
+ */
+#ifndef YY_DECL
+#define YY_DECL_IS_OURS 1
+/* %if-c-only Standard (non-C++) definition */
+
+extern int d2_parser_lex (void);
+
+#define YY_DECL int d2_parser_lex (void)
+/* %endif */
+/* %if-c++-only C++ definition */
+/* %endif */
+#endif /* !YY_DECL */
+
+/* Code executed at the beginning of each rule, after d2_parser_text and d2_parser_leng
+ * have been set up.
+ */
+#ifndef YY_USER_ACTION
+#define YY_USER_ACTION
+#endif
+
+/* Code executed at the end of each rule. */
+#ifndef YY_BREAK
+#define YY_BREAK /*LINTED*/break;
+#endif
+
+/* %% [6.0] YY_RULE_SETUP definition goes here */
+#define YY_RULE_SETUP \
+ YY_USER_ACTION
+
+/* %not-for-header */
+/** The main scanner function which does all the work.
+ */
+YY_DECL
+{
+ yy_state_type yy_current_state;
+ char *yy_cp, *yy_bp;
+ int yy_act;
+
+ if ( !(yy_init) )
+ {
+ (yy_init) = 1;
+
+#ifdef YY_USER_INIT
+ YY_USER_INIT;
+#endif
+
+ if ( ! (yy_start) )
+ (yy_start) = 1; /* first start state */
+
+ if ( ! d2_parser_in )
+/* %if-c-only */
+ d2_parser_in = stdin;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! d2_parser_out )
+/* %if-c-only */
+ d2_parser_out = stdout;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+ if ( ! YY_CURRENT_BUFFER ) {
+ d2_parser_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ d2_parser__create_buffer(d2_parser_in,YY_BUF_SIZE );
+ }
+
+ d2_parser__load_buffer_state( );
+ }
+
+ {
+/* %% [7.0] user's declarations go here */
+#line 92 "d2_lexer.ll"
+
+
+
+#line 96 "d2_lexer.ll"
+ // This part of the code is copied over to the verbatim to the top
+ // of the generated yylex function. Explanation:
+ // http://www.gnu.org/software/bison/manual/html_node/Multiple-start_002dsymbols.html
+
+ // Code run each time yylex is called.
+ driver.loc_.step();
+
+ if (start_token_flag) {
+ start_token_flag = false;
+ switch (start_token_value) {
+ case D2ParserContext::PARSER_JSON:
+ default:
+ return isc::d2::D2Parser::make_TOPLEVEL_JSON(driver.loc_);
+ case D2ParserContext::PARSER_DHCPDDNS:
+ return isc::d2::D2Parser::make_TOPLEVEL_DHCPDDNS(driver.loc_);
+ case D2ParserContext::PARSER_SUB_DHCPDDNS:
+ return isc::d2::D2Parser::make_SUB_DHCPDDNS(driver.loc_);
+ case D2ParserContext::PARSER_TSIG_KEY:
+ return isc::d2::D2Parser::make_SUB_TSIG_KEY(driver.loc_);
+ case D2ParserContext::PARSER_TSIG_KEYS:
+ return isc::d2::D2Parser::make_SUB_TSIG_KEYS(driver.loc_);
+ case D2ParserContext::PARSER_DDNS_DOMAIN:
+ return isc::d2::D2Parser::make_SUB_DDNS_DOMAIN(driver.loc_);
+ case D2ParserContext::PARSER_DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_SUB_DDNS_DOMAINS(driver.loc_);
+ case D2ParserContext::PARSER_DNS_SERVER:
+ return isc::d2::D2Parser::make_SUB_DNS_SERVER(driver.loc_);
+ }
+ }
+
+
+#line 1627 "d2_lexer.cc"
+
+ while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
+ {
+/* %% [8.0] yymore()-related code goes here */
+ yy_cp = (yy_c_buf_p);
+
+ /* Support of d2_parser_text. */
+ *yy_cp = (yy_hold_char);
+
+ /* yy_bp points to the position in yy_ch_buf of the start of
+ * the current run.
+ */
+ yy_bp = yy_cp;
+
+/* %% [9.0] code to set up and find next match goes here */
+ yy_current_state = (yy_start);
+yy_match:
+ do
+ {
+ YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 336 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ ++yy_cp;
+ }
+ while ( yy_current_state != 335 );
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+
+yy_find_action:
+/* %% [10.0] code to find the action number goes here */
+ yy_act = yy_accept[yy_current_state];
+
+ YY_DO_BEFORE_ACTION;
+
+/* %% [11.0] code for d2_parser_lineno update goes here */
+
+do_action: /* This label is used only to access EOF actions. */
+
+/* %% [12.0] debug code goes here */
+ if ( d2_parser__flex_debug )
+ {
+ if ( yy_act == 0 )
+ fprintf( stderr, "--scanner backing up\n" );
+ else if ( yy_act < 58 )
+ fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n",
+ (long)yy_rule_linenum[yy_act], d2_parser_text );
+ else if ( yy_act == 58 )
+ fprintf( stderr, "--accepting default rule (\"%s\")\n",
+ d2_parser_text );
+ else if ( yy_act == 59 )
+ fprintf( stderr, "--(end of buffer or a NUL)\n" );
+ else
+ fprintf( stderr, "--EOF (start condition %d)\n", YY_START );
+ }
+
+ switch ( yy_act )
+ { /* beginning of action switch */
+/* %% [13.0] actions go here */
+ case 0: /* must back up */
+ /* undo the effects of YY_DO_BEFORE_ACTION */
+ *yy_cp = (yy_hold_char);
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+
+case 1:
+YY_RULE_SETUP
+#line 127 "d2_lexer.ll"
+;
+ YY_BREAK
+case 2:
+YY_RULE_SETUP
+#line 129 "d2_lexer.ll"
+;
+ YY_BREAK
+case 3:
+YY_RULE_SETUP
+#line 131 "d2_lexer.ll"
+{
+ BEGIN(COMMENT);
+ comment_start_line = driver.loc_.end.line;;
+}
+ YY_BREAK
+case 4:
+YY_RULE_SETUP
+#line 136 "d2_lexer.ll"
+BEGIN(INITIAL);
+ YY_BREAK
+case 5:
+YY_RULE_SETUP
+#line 137 "d2_lexer.ll"
+;
+ YY_BREAK
+case YY_STATE_EOF(COMMENT):
+#line 138 "d2_lexer.ll"
+{
+ isc_throw(D2ParseError, "Comment not closed. (/* in line " << comment_start_line);
+}
+ YY_BREAK
+case 6:
+YY_RULE_SETUP
+#line 142 "d2_lexer.ll"
+BEGIN(DIR_ENTER);
+ YY_BREAK
+case 7:
+YY_RULE_SETUP
+#line 143 "d2_lexer.ll"
+BEGIN(DIR_INCLUDE);
+ YY_BREAK
+case 8:
+YY_RULE_SETUP
+#line 144 "d2_lexer.ll"
+{
+ // Include directive.
+
+ // Extract the filename.
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+
+ driver.includeFile(tmp);
+}
+ YY_BREAK
+case YY_STATE_EOF(DIR_ENTER):
+case YY_STATE_EOF(DIR_INCLUDE):
+case YY_STATE_EOF(DIR_EXIT):
+#line 153 "d2_lexer.ll"
+{
+ isc_throw(D2ParseError, "Directive not closed.");
+}
+ YY_BREAK
+case 9:
+YY_RULE_SETUP
+#line 156 "d2_lexer.ll"
+BEGIN(INITIAL);
+ YY_BREAK
+case 10:
+YY_RULE_SETUP
+#line 159 "d2_lexer.ll"
+{
+ // Ok, we found a with space. Let's ignore it and update loc variable.
+ driver.loc_.step();
+}
+ YY_BREAK
+case 11:
+/* rule 11 can match eol */
+YY_RULE_SETUP
+#line 164 "d2_lexer.ll"
+{
+ // Newline found. Let's update the location and continue.
+ driver.loc_.lines(yyleng);
+ driver.loc_.step();
+}
+ YY_BREAK
+case 12:
+YY_RULE_SETUP
+#line 170 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_DHCPDDNS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("DhcpDdns", driver.loc_);
+ }
+}
+ YY_BREAK
+case 13:
+YY_RULE_SETUP
+#line 179 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ case isc::d2::D2ParserContext::DNS_SERVER:
+ case isc::d2::D2ParserContext::DNS_SERVERS:
+ return isc::d2::D2Parser::make_IP_ADDRESS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ip-address", driver.loc_);
+ }
+}
+ YY_BREAK
+case 14:
+YY_RULE_SETUP
+#line 190 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ case isc::d2::D2ParserContext::DNS_SERVER:
+ case isc::d2::D2ParserContext::DNS_SERVERS:
+ return isc::d2::D2Parser::make_PORT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("port", driver.loc_);
+ }
+}
+ YY_BREAK
+case 15:
+YY_RULE_SETUP
+#line 201 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_DNS_SERVER_TIMEOUT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("dns-server-timeout", driver.loc_);
+ }
+}
+ YY_BREAK
+case 16:
+YY_RULE_SETUP
+#line 210 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_NCR_PROTOCOL(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ncr-protocol", driver.loc_);
+ }
+}
+ YY_BREAK
+case 17:
+YY_RULE_SETUP
+#line 219 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_NCR_FORMAT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ncr-format", driver.loc_);
+ }
+}
+ YY_BREAK
+case 18:
+YY_RULE_SETUP
+#line 228 "d2_lexer.ll"
+{
+ /* dhcp-ddns value keywords are case insensitive */
+ if (driver.ctx_ == isc::d2::D2ParserContext::NCR_PROTOCOL) {
+ return isc::d2::D2Parser::make_UDP(driver.loc_);
+ }
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+ return isc::d2::D2Parser::make_STRING(tmp, driver.loc_);
+}
+ YY_BREAK
+case 19:
+YY_RULE_SETUP
+#line 238 "d2_lexer.ll"
+{
+ /* dhcp-ddns value keywords are case insensitive */
+ if (driver.ctx_ == isc::d2::D2ParserContext::NCR_PROTOCOL) {
+ return isc::d2::D2Parser::make_TCP(driver.loc_);
+ }
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+ return isc::d2::D2Parser::make_STRING(tmp, driver.loc_);
+}
+ YY_BREAK
+case 20:
+YY_RULE_SETUP
+#line 248 "d2_lexer.ll"
+{
+ /* dhcp-ddns value keywords are case insensitive */
+ if (driver.ctx_ == isc::d2::D2ParserContext::NCR_FORMAT) {
+ return isc::d2::D2Parser::make_JSON(driver.loc_);
+ }
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+ return isc::d2::D2Parser::make_STRING(tmp, driver.loc_);
+}
+ YY_BREAK
+case 21:
+YY_RULE_SETUP
+#line 258 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_FORWARD_DDNS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("forward-ddns", driver.loc_);
+ }
+}
+ YY_BREAK
+case 22:
+YY_RULE_SETUP
+#line 267 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_REVERSE_DDNS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("reverse-ddns", driver.loc_);
+ }
+}
+ YY_BREAK
+case 23:
+YY_RULE_SETUP
+#line 276 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::FORWARD_DDNS:
+ case isc::d2::D2ParserContext::REVERSE_DDNS:
+ return isc::d2::D2Parser::make_DDNS_DOMAINS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ddns-domains", driver.loc_);
+ }
+}
+ YY_BREAK
+case 24:
+YY_RULE_SETUP
+#line 286 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DDNS_DOMAIN:
+ case isc::d2::D2ParserContext::DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_KEY_NAME(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("key-name", driver.loc_);
+ }
+}
+ YY_BREAK
+case 25:
+YY_RULE_SETUP
+#line 296 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DDNS_DOMAIN:
+ case isc::d2::D2ParserContext::DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_DNS_SERVERS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("dns-servers", driver.loc_);
+ }
+}
+ YY_BREAK
+case 26:
+YY_RULE_SETUP
+#line 306 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DNS_SERVER:
+ case isc::d2::D2ParserContext::DNS_SERVERS:
+ return isc::d2::D2Parser::make_HOSTNAME(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("hostname", driver.loc_);
+ }
+}
+ YY_BREAK
+case 27:
+YY_RULE_SETUP
+#line 317 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_TSIG_KEYS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("tsig-keys", driver.loc_);
+ }
+}
+ YY_BREAK
+case 28:
+YY_RULE_SETUP
+#line 326 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ return isc::d2::D2Parser::make_ALGORITHM(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("algorithm", driver.loc_);
+ }
+}
+ YY_BREAK
+case 29:
+YY_RULE_SETUP
+#line 336 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ return isc::d2::D2Parser::make_DIGEST_BITS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("digest-bits", driver.loc_);
+ }
+}
+ YY_BREAK
+case 30:
+YY_RULE_SETUP
+#line 346 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ return isc::d2::D2Parser::make_SECRET(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("secret", driver.loc_);
+ }
+}
+ YY_BREAK
+case 31:
+YY_RULE_SETUP
+#line 357 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_LOGGING(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("Logging", driver.loc_);
+ }
+}
+ YY_BREAK
+case 32:
+YY_RULE_SETUP
+#line 366 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGING:
+ return isc::d2::D2Parser::make_LOGGERS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("loggers", driver.loc_);
+ }
+}
+ YY_BREAK
+case 33:
+YY_RULE_SETUP
+#line 375 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ return isc::d2::D2Parser::make_OUTPUT_OPTIONS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("output_options", driver.loc_);
+ }
+}
+ YY_BREAK
+case 34:
+YY_RULE_SETUP
+#line 384 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::OUTPUT_OPTIONS:
+ return isc::d2::D2Parser::make_OUTPUT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("output", driver.loc_);
+ }
+}
+ YY_BREAK
+case 35:
+YY_RULE_SETUP
+#line 393 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ case isc::d2::D2ParserContext::DDNS_DOMAIN:
+ case isc::d2::D2ParserContext::DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_NAME(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("name", driver.loc_);
+ }
+}
+ YY_BREAK
+case 36:
+YY_RULE_SETUP
+#line 406 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ return isc::d2::D2Parser::make_DEBUGLEVEL(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("debuglevel", driver.loc_);
+ }
+}
+ YY_BREAK
+case 37:
+YY_RULE_SETUP
+#line 415 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ return isc::d2::D2Parser::make_SEVERITY(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("severity", driver.loc_);
+ }
+}
+ YY_BREAK
+case 38:
+YY_RULE_SETUP
+#line 424 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_DHCP4(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("Dhcp4", driver.loc_);
+ }
+}
+ YY_BREAK
+case 39:
+YY_RULE_SETUP
+#line 433 "d2_lexer.ll"
+{
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_DHCP6(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("Dhcp6", driver.loc_);
+ }
+}
+ YY_BREAK
+case 40:
+YY_RULE_SETUP
+#line 443 "d2_lexer.ll"
+{
+ // A string has been matched. It contains the actual string and single quotes.
+ // We need to get those quotes out of the way and just use its content, e.g.
+ // for 'foo' we should get foo
+ std::string raw(yytext+1);
+ size_t len = raw.size() - 1;
+ raw.resize(len);
+ std::string decoded;
+ decoded.reserve(len);
+ for (size_t pos = 0; pos < len; ++pos) {
+ int b = 0;
+ char c = raw[pos];
+ switch (c) {
+ case '"':
+ // impossible condition
+ driver.error(driver.loc_, "Bad quote in \"" + raw + "\"");
+ case '\\':
+ ++pos;
+ if (pos >= len) {
+ // impossible condition
+ driver.error(driver.loc_, "Overflow escape in \"" + raw + "\"");
+ }
+ c = raw[pos];
+ switch (c) {
+ case '"':
+ case '\\':
+ case '/':
+ decoded.push_back(c);
+ break;
+ case 'b':
+ decoded.push_back('\b');
+ break;
+ case 'f':
+ decoded.push_back('\f');
+ break;
+ case 'n':
+ decoded.push_back('\n');
+ break;
+ case 'r':
+ decoded.push_back('\r');
+ break;
+ case 't':
+ decoded.push_back('\t');
+ break;
+ case 'u':
+ // support only \u0000 to \u00ff
+ ++pos;
+ if (pos + 4 > len) {
+ // impossible condition
+ driver.error(driver.loc_,
+ "Overflow unicode escape in \"" + raw + "\"");
+ }
+ if ((raw[pos] != '0') || (raw[pos + 1] != '0')) {
+ driver.error(driver.loc_, "Unsupported unicode escape in \"" + raw + "\"");
+ }
+ pos += 2;
+ c = raw[pos];
+ if ((c >= '0') && (c <= '9')) {
+ b = (c - '0') << 4;
+ } else if ((c >= 'A') && (c <= 'F')) {
+ b = (c - 'A' + 10) << 4;
+ } else if ((c >= 'a') && (c <= 'f')) {
+ b = (c - 'a' + 10) << 4;
+ } else {
+ // impossible condition
+ driver.error(driver.loc_, "Not hexadecimal in unicode escape in \"" + raw + "\"");
+ }
+ pos++;
+ c = raw[pos];
+ if ((c >= '0') && (c <= '9')) {
+ b |= c - '0';
+ } else if ((c >= 'A') && (c <= 'F')) {
+ b |= c - 'A' + 10;
+ } else if ((c >= 'a') && (c <= 'f')) {
+ b |= c - 'a' + 10;
+ } else {
+ // impossible condition
+ driver.error(driver.loc_, "Not hexadecimal in unicode escape in \"" + raw + "\"");
+ }
+ decoded.push_back(static_cast<char>(b & 0xff));
+ break;
+ default:
+ // impossible condition
+ driver.error(driver.loc_, "Bad escape in \"" + raw + "\"");
+ }
+ break;
+ default:
+ if ((c >= 0) && (c < 0x20)) {
+ // impossible condition
+ driver.error(driver.loc_, "Invalid control in \"" + raw + "\"");
+ }
+ decoded.push_back(c);
+ }
+ }
+
+ return isc::d2::D2Parser::make_STRING(decoded, driver.loc_);
+}
+ YY_BREAK
+case 41:
+/* rule 41 can match eol */
+YY_RULE_SETUP
+#line 541 "d2_lexer.ll"
+{
+ // Bad string with a forbidden control character inside
+ driver.error(driver.loc_, "Invalid control in " + std::string(yytext));
+}
+ YY_BREAK
+case 42:
+/* rule 42 can match eol */
+YY_RULE_SETUP
+#line 546 "d2_lexer.ll"
+{
+ // Bad string with a bad escape inside
+ driver.error(driver.loc_, "Bad escape in " + std::string(yytext));
+}
+ YY_BREAK
+case 43:
+YY_RULE_SETUP
+#line 551 "d2_lexer.ll"
+{
+ // Bad string with an open escape at the end
+ driver.error(driver.loc_, "Overflow escape in " + std::string(yytext));
+}
+ YY_BREAK
+case 44:
+YY_RULE_SETUP
+#line 556 "d2_lexer.ll"
+{ return isc::d2::D2Parser::make_LSQUARE_BRACKET(driver.loc_); }
+ YY_BREAK
+case 45:
+YY_RULE_SETUP
+#line 557 "d2_lexer.ll"
+{ return isc::d2::D2Parser::make_RSQUARE_BRACKET(driver.loc_); }
+ YY_BREAK
+case 46:
+YY_RULE_SETUP
+#line 558 "d2_lexer.ll"
+{ return isc::d2::D2Parser::make_LCURLY_BRACKET(driver.loc_); }
+ YY_BREAK
+case 47:
+YY_RULE_SETUP
+#line 559 "d2_lexer.ll"
+{ return isc::d2::D2Parser::make_RCURLY_BRACKET(driver.loc_); }
+ YY_BREAK
+case 48:
+YY_RULE_SETUP
+#line 560 "d2_lexer.ll"
+{ return isc::d2::D2Parser::make_COMMA(driver.loc_); }
+ YY_BREAK
+case 49:
+YY_RULE_SETUP
+#line 561 "d2_lexer.ll"
+{ return isc::d2::D2Parser::make_COLON(driver.loc_); }
+ YY_BREAK
+case 50:
+YY_RULE_SETUP
+#line 563 "d2_lexer.ll"
+{
+ // An integer was found.
+ std::string tmp(yytext);
+ int64_t integer = 0;
+ try {
+ // In substring we want to use negative values (e.g. -1).
+ // In enterprise-id we need to use values up to 0xffffffff.
+ // To cover both of those use cases, we need at least
+ // int64_t.
+ integer = boost::lexical_cast<int64_t>(tmp);
+ } catch (const boost::bad_lexical_cast &) {
+ driver.error(driver.loc_, "Failed to convert " + tmp + " to an integer.");
+ }
+
+ // The parser needs the string form as double conversion is no lossless
+ return isc::d2::D2Parser::make_INTEGER(integer, driver.loc_);
+}
+ YY_BREAK
+case 51:
+YY_RULE_SETUP
+#line 581 "d2_lexer.ll"
+{
+ // A floating point was found.
+ std::string tmp(yytext);
+ double fp = 0.0;
+ try {
+ fp = boost::lexical_cast<double>(tmp);
+ } catch (const boost::bad_lexical_cast &) {
+ driver.error(driver.loc_, "Failed to convert " + tmp + " to a floating point.");
+ }
+
+ return isc::d2::D2Parser::make_FLOAT(fp, driver.loc_);
+}
+ YY_BREAK
+case 52:
+YY_RULE_SETUP
+#line 594 "d2_lexer.ll"
+{
+ string tmp(yytext);
+ return isc::d2::D2Parser::make_BOOLEAN(tmp == "true", driver.loc_);
+}
+ YY_BREAK
+case 53:
+YY_RULE_SETUP
+#line 599 "d2_lexer.ll"
+{
+ return isc::d2::D2Parser::make_NULL_TYPE(driver.loc_);
+}
+ YY_BREAK
+case 54:
+YY_RULE_SETUP
+#line 603 "d2_lexer.ll"
+driver.error (driver.loc_, "JSON true reserved keyword is lower case only");
+ YY_BREAK
+case 55:
+YY_RULE_SETUP
+#line 605 "d2_lexer.ll"
+driver.error (driver.loc_, "JSON false reserved keyword is lower case only");
+ YY_BREAK
+case 56:
+YY_RULE_SETUP
+#line 607 "d2_lexer.ll"
+driver.error (driver.loc_, "JSON null reserved keyword is lower case only");
+ YY_BREAK
+case 57:
+YY_RULE_SETUP
+#line 609 "d2_lexer.ll"
+driver.error (driver.loc_, "Invalid character: " + std::string(yytext));
+ YY_BREAK
+case YY_STATE_EOF(INITIAL):
+#line 611 "d2_lexer.ll"
+{
+ if (driver.states_.empty()) {
+ return isc::d2::D2Parser::make_END(driver.loc_);
+ }
+ driver.loc_ = driver.locs_.back();
+ driver.locs_.pop_back();
+ driver.file_ = driver.files_.back();
+ driver.files_.pop_back();
+ if (driver.sfile_) {
+ fclose(driver.sfile_);
+ driver.sfile_ = 0;
+ }
+ if (!driver.sfiles_.empty()) {
+ driver.sfile_ = driver.sfiles_.back();
+ driver.sfiles_.pop_back();
+ }
+ d2_parser__delete_buffer(YY_CURRENT_BUFFER);
+ d2_parser__switch_to_buffer(driver.states_.back());
+ driver.states_.pop_back();
+
+ BEGIN(DIR_EXIT);
+}
+ YY_BREAK
+case 58:
+YY_RULE_SETUP
+#line 634 "d2_lexer.ll"
+ECHO;
+ YY_BREAK
+#line 2404 "d2_lexer.cc"
+
+ case YY_END_OF_BUFFER:
+ {
+ /* Amount of text matched not including the EOB char. */
+ int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
+
+ /* Undo the effects of YY_DO_BEFORE_ACTION. */
+ *yy_cp = (yy_hold_char);
+ YY_RESTORE_YY_MORE_OFFSET
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
+ {
+ /* We're scanning a new file or input source. It's
+ * possible that this happened because the user
+ * just pointed d2_parser_in at a new source and called
+ * d2_parser_lex(). If so, then we have to assure
+ * consistency between YY_CURRENT_BUFFER and our
+ * globals. Here is the right place to do so, because
+ * this is the first action (other than possibly a
+ * back-up) that will match for the new input source.
+ */
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+/* %if-c-only */
+ YY_CURRENT_BUFFER_LVALUE->yy_input_file = d2_parser_in;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
+ }
+
+ /* Note that here we test for yy_c_buf_p "<=" to the position
+ * of the first EOB in the buffer, since yy_c_buf_p will
+ * already have been incremented past the NUL character
+ * (since all states make transitions on EOB to the
+ * end-of-buffer state). Contrast this with the test
+ * in input().
+ */
+ if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ { /* This was really a NUL. */
+ yy_state_type yy_next_state;
+
+ (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ /* Okay, we're now positioned to make the NUL
+ * transition. We couldn't have
+ * yy_get_previous_state() go ahead and do it
+ * for us because it doesn't know how to deal
+ * with the possibility of jamming (and we don't
+ * want to build jamming into it because then it
+ * will run more slowly).
+ */
+
+ yy_next_state = yy_try_NUL_trans( yy_current_state );
+
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+
+ if ( yy_next_state )
+ {
+ /* Consume the NUL. */
+ yy_cp = ++(yy_c_buf_p);
+ yy_current_state = yy_next_state;
+ goto yy_match;
+ }
+
+ else
+ {
+/* %% [14.0] code to do back-up for compressed tables and set up yy_cp goes here */
+ yy_cp = (yy_last_accepting_cpos);
+ yy_current_state = (yy_last_accepting_state);
+ goto yy_find_action;
+ }
+ }
+
+ else switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_END_OF_FILE:
+ {
+ (yy_did_buffer_switch_on_eof) = 0;
+
+ if ( d2_parser_wrap( ) )
+ {
+ /* Note: because we've taken care in
+ * yy_get_next_buffer() to have set up
+ * d2_parser_text, we can now set up
+ * yy_c_buf_p so that if some total
+ * hoser (like flex itself) wants to
+ * call the scanner after we return the
+ * YY_NULL, it'll still work - another
+ * YY_NULL will get returned.
+ */
+ (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
+
+ yy_act = YY_STATE_EOF(YY_START);
+ goto do_action;
+ }
+
+ else
+ {
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+ }
+ break;
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) =
+ (yytext_ptr) + yy_amount_of_matched_text;
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_match;
+
+ case EOB_ACT_LAST_MATCH:
+ (yy_c_buf_p) =
+ &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
+
+ yy_current_state = yy_get_previous_state( );
+
+ yy_cp = (yy_c_buf_p);
+ yy_bp = (yytext_ptr) + YY_MORE_ADJ;
+ goto yy_find_action;
+ }
+ break;
+ }
+
+ default:
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--no action found" );
+ } /* end of action switch */
+ } /* end of scanning one token */
+ } /* end of user's declarations */
+} /* end of d2_parser_lex */
+/* %ok-for-header */
+
+/* %if-c++-only */
+/* %not-for-header */
+/* %ok-for-header */
+
+/* %endif */
+
+/* yy_get_next_buffer - try to read in a new buffer
+ *
+ * Returns a code representing an action:
+ * EOB_ACT_LAST_MATCH -
+ * EOB_ACT_CONTINUE_SCAN - continue scanning from current position
+ * EOB_ACT_END_OF_FILE - end of file
+ */
+/* %if-c-only */
+static int yy_get_next_buffer (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
+ char *source = (yytext_ptr);
+ int number_to_move, i;
+ int ret_val;
+
+ if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
+ YY_FATAL_ERROR(
+ "fatal flex scanner internal error--end of buffer missed" );
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
+ { /* Don't try to fill the buffer, so this is an EOF. */
+ if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
+ {
+ /* We matched a single character, the EOB, so
+ * treat this as a final EOF.
+ */
+ return EOB_ACT_END_OF_FILE;
+ }
+
+ else
+ {
+ /* We matched some text prior to the EOB, first
+ * process it.
+ */
+ return EOB_ACT_LAST_MATCH;
+ }
+ }
+
+ /* Try to read more data. */
+
+ /* First move last chars to start of buffer. */
+ number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
+
+ for ( i = 0; i < number_to_move; ++i )
+ *(dest++) = *(source++);
+
+ if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
+ /* don't do the read, it's not guaranteed to return an EOF,
+ * just force an EOF
+ */
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
+
+ else
+ {
+ int num_to_read =
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
+
+ while ( num_to_read <= 0 )
+ { /* Not enough room in the buffer - grow it. */
+
+ /* just a shorter name for the current buffer */
+ YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
+
+ int yy_c_buf_p_offset =
+ (int) ((yy_c_buf_p) - b->yy_ch_buf);
+
+ if ( b->yy_is_our_buffer )
+ {
+ int new_size = b->yy_buf_size * 2;
+
+ if ( new_size <= 0 )
+ b->yy_buf_size += b->yy_buf_size / 8;
+ else
+ b->yy_buf_size *= 2;
+
+ b->yy_ch_buf = (char *)
+ /* Include room in for 2 EOB chars. */
+ d2_parser_realloc((void *) b->yy_ch_buf,(yy_size_t) (b->yy_buf_size + 2) );
+ }
+ else
+ /* Can't grow it, we don't own it. */
+ b->yy_ch_buf = NULL;
+
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR(
+ "fatal error - scanner input buffer overflow" );
+
+ (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
+
+ num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
+ number_to_move - 1;
+
+ }
+
+ if ( num_to_read > YY_READ_BUF_SIZE )
+ num_to_read = YY_READ_BUF_SIZE;
+
+ /* Read in more data. */
+ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
+ (yy_n_chars), num_to_read );
+
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ if ( (yy_n_chars) == 0 )
+ {
+ if ( number_to_move == YY_MORE_ADJ )
+ {
+ ret_val = EOB_ACT_END_OF_FILE;
+ d2_parser_restart(d2_parser_in );
+ }
+
+ else
+ {
+ ret_val = EOB_ACT_LAST_MATCH;
+ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
+ YY_BUFFER_EOF_PENDING;
+ }
+ }
+
+ else
+ ret_val = EOB_ACT_CONTINUE_SCAN;
+
+ if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
+ /* Extend the array by 50%, plus the number we really need. */
+ int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) d2_parser_realloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,(yy_size_t) new_size );
+ if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
+ }
+
+ (yy_n_chars) += number_to_move;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
+ YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
+
+ (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
+
+ return ret_val;
+}
+
+/* yy_get_previous_state - get the state just before the EOB char was reached */
+
+/* %if-c-only */
+/* %not-for-header */
+ static yy_state_type yy_get_previous_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ yy_state_type yy_current_state;
+ char *yy_cp;
+
+/* %% [15.0] code to get the start state into yy_current_state goes here */
+ yy_current_state = (yy_start);
+
+ for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
+ {
+/* %% [16.0] code to find the next state goes here */
+ YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 336 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ }
+
+ return yy_current_state;
+}
+
+/* yy_try_NUL_trans - try to make a transition on the NUL character
+ *
+ * synopsis
+ * next_state = yy_try_NUL_trans( current_state );
+ */
+/* %if-c-only */
+ static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ int yy_is_jam;
+ /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */
+ char *yy_cp = (yy_c_buf_p);
+
+ YY_CHAR yy_c = 1;
+ if ( yy_accept[yy_current_state] )
+ {
+ (yy_last_accepting_state) = yy_current_state;
+ (yy_last_accepting_cpos) = yy_cp;
+ }
+ while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
+ {
+ yy_current_state = (int) yy_def[yy_current_state];
+ if ( yy_current_state >= 336 )
+ yy_c = yy_meta[yy_c];
+ }
+ yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
+ yy_is_jam = (yy_current_state == 335);
+
+ return yy_is_jam ? 0 : yy_current_state;
+}
+
+#ifndef YY_NO_UNPUT
+/* %if-c-only */
+
+/* %endif */
+#endif
+
+/* %if-c-only */
+#ifndef YY_NO_INPUT
+#ifdef __cplusplus
+ static int yyinput (void)
+#else
+ static int input (void)
+#endif
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ int c;
+
+ *(yy_c_buf_p) = (yy_hold_char);
+
+ if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
+ {
+ /* yy_c_buf_p now points to the character we want to return.
+ * If this occurs *before* the EOB characters, then it's a
+ * valid NUL; if not, then we've hit the end of the buffer.
+ */
+ if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
+ /* This was really a NUL. */
+ *(yy_c_buf_p) = '\0';
+
+ else
+ { /* need more input */
+ int offset = (int) ((yy_c_buf_p) - (yytext_ptr));
+ ++(yy_c_buf_p);
+
+ switch ( yy_get_next_buffer( ) )
+ {
+ case EOB_ACT_LAST_MATCH:
+ /* This happens because yy_g_n_b()
+ * sees that we've accumulated a
+ * token and flags that we need to
+ * try matching the token before
+ * proceeding. But for input(),
+ * there's no matching to consider.
+ * So convert the EOB_ACT_LAST_MATCH
+ * to EOB_ACT_END_OF_FILE.
+ */
+
+ /* Reset buffer status. */
+ d2_parser_restart(d2_parser_in );
+
+ /*FALLTHROUGH*/
+
+ case EOB_ACT_END_OF_FILE:
+ {
+ if ( d2_parser_wrap( ) )
+ return 0;
+
+ if ( ! (yy_did_buffer_switch_on_eof) )
+ YY_NEW_FILE;
+#ifdef __cplusplus
+ return yyinput();
+#else
+ return input();
+#endif
+ }
+
+ case EOB_ACT_CONTINUE_SCAN:
+ (yy_c_buf_p) = (yytext_ptr) + offset;
+ break;
+ }
+ }
+ }
+
+ c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
+ *(yy_c_buf_p) = '\0'; /* preserve d2_parser_text */
+ (yy_hold_char) = *++(yy_c_buf_p);
+
+/* %% [19.0] update BOL and d2_parser_lineno */
+
+ return c;
+}
+/* %if-c-only */
+#endif /* ifndef YY_NO_INPUT */
+/* %endif */
+
+/** Immediately switch to a different input stream.
+ * @param input_file A readable stream.
+ *
+ * @note This function does not reset the start condition to @c INITIAL .
+ */
+/* %if-c-only */
+ void d2_parser_restart (FILE * input_file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! YY_CURRENT_BUFFER ){
+ d2_parser_ensure_buffer_stack ();
+ YY_CURRENT_BUFFER_LVALUE =
+ d2_parser__create_buffer(d2_parser_in,YY_BUF_SIZE );
+ }
+
+ d2_parser__init_buffer(YY_CURRENT_BUFFER,input_file );
+ d2_parser__load_buffer_state( );
+}
+
+/* %if-c++-only */
+/* %endif */
+
+/** Switch to a different input buffer.
+ * @param new_buffer The new input buffer.
+ *
+ */
+/* %if-c-only */
+ void d2_parser__switch_to_buffer (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ /* TODO. We should be able to replace this entire function body
+ * with
+ * d2_parser_pop_buffer_state();
+ * d2_parser_push_buffer_state(new_buffer);
+ */
+ d2_parser_ensure_buffer_stack ();
+ if ( YY_CURRENT_BUFFER == new_buffer )
+ return;
+
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+ d2_parser__load_buffer_state( );
+
+ /* We don't actually know whether we did this switch during
+ * EOF (d2_parser_wrap()) processing, but the only time this flag
+ * is looked at is after d2_parser_wrap() is called, so it's safe
+ * to go ahead and always set it.
+ */
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+
+/* %if-c-only */
+static void d2_parser__load_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
+ (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
+/* %if-c-only */
+ d2_parser_in = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ (yy_hold_char) = *(yy_c_buf_p);
+}
+
+/** Allocate and initialize an input buffer state.
+ * @param file A readable stream.
+ * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
+ *
+ * @return the allocated buffer state.
+ */
+/* %if-c-only */
+ YY_BUFFER_STATE d2_parser__create_buffer (FILE * file, int size )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ YY_BUFFER_STATE b;
+
+ b = (YY_BUFFER_STATE) d2_parser_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in d2_parser__create_buffer()" );
+
+ b->yy_buf_size = size;
+
+ /* yy_ch_buf has to be 2 characters longer than the size given because
+ * we need to put in 2 end-of-buffer characters.
+ */
+ b->yy_ch_buf = (char *) d2_parser_alloc((yy_size_t) (b->yy_buf_size + 2) );
+ if ( ! b->yy_ch_buf )
+ YY_FATAL_ERROR( "out of dynamic memory in d2_parser__create_buffer()" );
+
+ b->yy_is_our_buffer = 1;
+
+ d2_parser__init_buffer(b,file );
+
+ return b;
+}
+
+/* %if-c++-only */
+/* %endif */
+
+/** Destroy the buffer.
+ * @param b a buffer created with d2_parser__create_buffer()
+ *
+ */
+/* %if-c-only */
+ void d2_parser__delete_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+
+ if ( ! b )
+ return;
+
+ if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
+ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
+
+ if ( b->yy_is_our_buffer )
+ d2_parser_free((void *) b->yy_ch_buf );
+
+ d2_parser_free((void *) b );
+}
+
+/* Initializes or reinitializes a buffer.
+ * This function is sometimes called more than once on the same buffer,
+ * such as during a d2_parser_restart() or at EOF.
+ */
+/* %if-c-only */
+ static void d2_parser__init_buffer (YY_BUFFER_STATE b, FILE * file )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+{
+ int oerrno = errno;
+
+ d2_parser__flush_buffer(b );
+
+/* %if-c-only */
+ b->yy_input_file = file;
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ b->yy_fill_buffer = 1;
+
+ /* If b is the current buffer, then d2_parser__init_buffer was _probably_
+ * called from d2_parser_restart() or through yy_get_next_buffer.
+ * In that case, we don't want to reset the lineno or column.
+ */
+ if (b != YY_CURRENT_BUFFER){
+ b->yy_bs_lineno = 1;
+ b->yy_bs_column = 0;
+ }
+
+/* %if-c-only */
+
+ b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
+
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+ errno = oerrno;
+}
+
+/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
+ * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
+ *
+ */
+/* %if-c-only */
+ void d2_parser__flush_buffer (YY_BUFFER_STATE b )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if ( ! b )
+ return;
+
+ b->yy_n_chars = 0;
+
+ /* We always need two end-of-buffer characters. The first causes
+ * a transition to the end-of-buffer state. The second causes
+ * a jam in that state.
+ */
+ b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
+ b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
+
+ b->yy_buf_pos = &b->yy_ch_buf[0];
+
+ b->yy_at_bol = 1;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ if ( b == YY_CURRENT_BUFFER )
+ d2_parser__load_buffer_state( );
+}
+
+/* %if-c-or-c++ */
+/** Pushes the new state onto the stack. The new state becomes
+ * the current state. This function will allocate the stack
+ * if necessary.
+ * @param new_buffer The new state.
+ *
+ */
+/* %if-c-only */
+void d2_parser_push_buffer_state (YY_BUFFER_STATE new_buffer )
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (new_buffer == NULL)
+ return;
+
+ d2_parser_ensure_buffer_stack();
+
+ /* This block is copied from d2_parser__switch_to_buffer. */
+ if ( YY_CURRENT_BUFFER )
+ {
+ /* Flush out information for old buffer. */
+ *(yy_c_buf_p) = (yy_hold_char);
+ YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
+ YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
+ }
+
+ /* Only push if top exists. Otherwise, replace top. */
+ if (YY_CURRENT_BUFFER)
+ (yy_buffer_stack_top)++;
+ YY_CURRENT_BUFFER_LVALUE = new_buffer;
+
+ /* copied from d2_parser__switch_to_buffer. */
+ d2_parser__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/** Removes and deletes the top of the stack, if present.
+ * The next element becomes the new top.
+ *
+ */
+/* %if-c-only */
+void d2_parser_pop_buffer_state (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ if (!YY_CURRENT_BUFFER)
+ return;
+
+ d2_parser__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ if ((yy_buffer_stack_top) > 0)
+ --(yy_buffer_stack_top);
+
+ if (YY_CURRENT_BUFFER) {
+ d2_parser__load_buffer_state( );
+ (yy_did_buffer_switch_on_eof) = 1;
+ }
+}
+/* %endif */
+
+/* %if-c-or-c++ */
+/* Allocates the stack if it does not exist.
+ * Guarantees space for at least one push.
+ */
+/* %if-c-only */
+static void d2_parser_ensure_buffer_stack (void)
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+{
+ yy_size_t num_to_alloc;
+
+ if (!(yy_buffer_stack)) {
+
+ /* First allocation is just for 2 elements, since we don't know if this
+ * scanner will even need a stack. We use 2 instead of 1 to avoid an
+ * immediate realloc on the next call.
+ */
+ num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
+ (yy_buffer_stack) = (struct yy_buffer_state**)d2_parser_alloc
+ (num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in d2_parser_ensure_buffer_stack()" );
+
+ memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
+
+ (yy_buffer_stack_max) = num_to_alloc;
+ (yy_buffer_stack_top) = 0;
+ return;
+ }
+
+ if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
+
+ /* Increase the buffer to prepare for a possible push. */
+ yy_size_t grow_size = 8 /* arbitrary grow size */;
+
+ num_to_alloc = (yy_buffer_stack_max) + grow_size;
+ (yy_buffer_stack) = (struct yy_buffer_state**)d2_parser_realloc
+ ((yy_buffer_stack),
+ num_to_alloc * sizeof(struct yy_buffer_state*)
+ );
+ if ( ! (yy_buffer_stack) )
+ YY_FATAL_ERROR( "out of dynamic memory in d2_parser_ensure_buffer_stack()" );
+
+ /* zero only the new slots.*/
+ memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
+ (yy_buffer_stack_max) = num_to_alloc;
+ }
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan directly from a user-specified character buffer.
+ * @param base the character buffer
+ * @param size the size in bytes of the character buffer
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE d2_parser__scan_buffer (char * base, yy_size_t size )
+{
+ YY_BUFFER_STATE b;
+
+ if ( size < 2 ||
+ base[size-2] != YY_END_OF_BUFFER_CHAR ||
+ base[size-1] != YY_END_OF_BUFFER_CHAR )
+ /* They forgot to leave room for the EOB's. */
+ return NULL;
+
+ b = (YY_BUFFER_STATE) d2_parser_alloc(sizeof( struct yy_buffer_state ) );
+ if ( ! b )
+ YY_FATAL_ERROR( "out of dynamic memory in d2_parser__scan_buffer()" );
+
+ b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
+ b->yy_buf_pos = b->yy_ch_buf = base;
+ b->yy_is_our_buffer = 0;
+ b->yy_input_file = NULL;
+ b->yy_n_chars = b->yy_buf_size;
+ b->yy_is_interactive = 0;
+ b->yy_at_bol = 1;
+ b->yy_fill_buffer = 0;
+ b->yy_buffer_status = YY_BUFFER_NEW;
+
+ d2_parser__switch_to_buffer(b );
+
+ return b;
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan a string. The next call to d2_parser_lex() will
+ * scan from a @e copy of @a str.
+ * @param yystr a NUL-terminated string to scan
+ *
+ * @return the newly allocated buffer state object.
+ * @note If you want to scan bytes that may contain NUL values, then use
+ * d2_parser__scan_bytes() instead.
+ */
+YY_BUFFER_STATE d2_parser__scan_string (const char * yystr )
+{
+
+ return d2_parser__scan_bytes(yystr,(int) strlen(yystr) );
+}
+/* %endif */
+
+/* %if-c-only */
+/** Setup the input buffer state to scan the given bytes. The next call to d2_parser_lex() will
+ * scan from a @e copy of @a bytes.
+ * @param yybytes the byte buffer to scan
+ * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
+ *
+ * @return the newly allocated buffer state object.
+ */
+YY_BUFFER_STATE d2_parser__scan_bytes (const char * yybytes, int _yybytes_len )
+{
+ YY_BUFFER_STATE b;
+ char *buf;
+ yy_size_t n;
+ int i;
+
+ /* Get memory for full buffer, including space for trailing EOB's. */
+ n = (yy_size_t) (_yybytes_len + 2);
+ buf = (char *) d2_parser_alloc(n );
+ if ( ! buf )
+ YY_FATAL_ERROR( "out of dynamic memory in d2_parser__scan_bytes()" );
+
+ for ( i = 0; i < _yybytes_len; ++i )
+ buf[i] = yybytes[i];
+
+ buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
+
+ b = d2_parser__scan_buffer(buf,n );
+ if ( ! b )
+ YY_FATAL_ERROR( "bad buffer in d2_parser__scan_bytes()" );
+
+ /* It's okay to grow etc. this buffer, and we should throw it
+ * away when we're done.
+ */
+ b->yy_is_our_buffer = 1;
+
+ return b;
+}
+/* %endif */
+
+#ifndef YY_EXIT_FAILURE
+#define YY_EXIT_FAILURE 2
+#endif
+
+/* %if-c-only */
+static void yynoreturn yy_fatal_error (const char* msg )
+{
+ (void) fprintf( stderr, "%s\n", msg );
+ exit( YY_EXIT_FAILURE );
+}
+/* %endif */
+/* %if-c++-only */
+/* %endif */
+
+/* Redefine yyless() so it works in section 3 code. */
+
+#undef yyless
+#define yyless(n) \
+ do \
+ { \
+ /* Undo effects of setting up d2_parser_text. */ \
+ int yyless_macro_arg = (n); \
+ YY_LESS_LINENO(yyless_macro_arg);\
+ d2_parser_text[d2_parser_leng] = (yy_hold_char); \
+ (yy_c_buf_p) = d2_parser_text + yyless_macro_arg; \
+ (yy_hold_char) = *(yy_c_buf_p); \
+ *(yy_c_buf_p) = '\0'; \
+ d2_parser_leng = yyless_macro_arg; \
+ } \
+ while ( 0 )
+
+/* Accessor methods (get/set functions) to struct members. */
+
+/* %if-c-only */
+/* %if-reentrant */
+/* %endif */
+
+/** Get the current line number.
+ *
+ */
+int d2_parser_get_lineno (void)
+{
+
+ return d2_parser_lineno;
+}
+
+/** Get the input stream.
+ *
+ */
+FILE *d2_parser_get_in (void)
+{
+ return d2_parser_in;
+}
+
+/** Get the output stream.
+ *
+ */
+FILE *d2_parser_get_out (void)
+{
+ return d2_parser_out;
+}
+
+/** Get the length of the current token.
+ *
+ */
+int d2_parser_get_leng (void)
+{
+ return d2_parser_leng;
+}
+
+/** Get the current token.
+ *
+ */
+
+char *d2_parser_get_text (void)
+{
+ return d2_parser_text;
+}
+
+/* %if-reentrant */
+/* %endif */
+
+/** Set the current line number.
+ * @param _line_number line number
+ *
+ */
+void d2_parser_set_lineno (int _line_number )
+{
+
+ d2_parser_lineno = _line_number;
+}
+
+/** Set the input stream. This does not discard the current
+ * input buffer.
+ * @param _in_str A readable stream.
+ *
+ * @see d2_parser__switch_to_buffer
+ */
+void d2_parser_set_in (FILE * _in_str )
+{
+ d2_parser_in = _in_str ;
+}
+
+void d2_parser_set_out (FILE * _out_str )
+{
+ d2_parser_out = _out_str ;
+}
+
+int d2_parser_get_debug (void)
+{
+ return d2_parser__flex_debug;
+}
+
+void d2_parser_set_debug (int _bdebug )
+{
+ d2_parser__flex_debug = _bdebug ;
+}
+
+/* %endif */
+
+/* %if-reentrant */
+/* %if-bison-bridge */
+/* %endif */
+/* %endif if-c-only */
+
+/* %if-c-only */
+static int yy_init_globals (void)
+{
+ /* Initialization is the same as for the non-reentrant scanner.
+ * This function is called from d2_parser_lex_destroy(), so don't allocate here.
+ */
+
+ (yy_buffer_stack) = NULL;
+ (yy_buffer_stack_top) = 0;
+ (yy_buffer_stack_max) = 0;
+ (yy_c_buf_p) = NULL;
+ (yy_init) = 0;
+ (yy_start) = 0;
+
+/* Defined in main.c */
+#ifdef YY_STDINIT
+ d2_parser_in = stdin;
+ d2_parser_out = stdout;
+#else
+ d2_parser_in = NULL;
+ d2_parser_out = NULL;
+#endif
+
+ /* For future reference: Set errno on error, since we are called by
+ * d2_parser_lex_init()
+ */
+ return 0;
+}
+/* %endif */
+
+/* %if-c-only SNIP! this currently causes conflicts with the c++ scanner */
+/* d2_parser_lex_destroy is for both reentrant and non-reentrant scanners. */
+int d2_parser_lex_destroy (void)
+{
+
+ /* Pop the buffer stack, destroying each element. */
+ while(YY_CURRENT_BUFFER){
+ d2_parser__delete_buffer(YY_CURRENT_BUFFER );
+ YY_CURRENT_BUFFER_LVALUE = NULL;
+ d2_parser_pop_buffer_state();
+ }
+
+ /* Destroy the stack itself. */
+ d2_parser_free((yy_buffer_stack) );
+ (yy_buffer_stack) = NULL;
+
+ /* Reset the globals. This is important in a non-reentrant scanner so the next time
+ * d2_parser_lex() is called, initialization will occur. */
+ yy_init_globals( );
+
+/* %if-reentrant */
+/* %endif */
+ return 0;
+}
+/* %endif */
+
+/*
+ * Internal utility routines.
+ */
+
+#ifndef yytext_ptr
+static void yy_flex_strncpy (char* s1, const char * s2, int n )
+{
+
+ int i;
+ for ( i = 0; i < n; ++i )
+ s1[i] = s2[i];
+}
+#endif
+
+#ifdef YY_NEED_STRLEN
+static int yy_flex_strlen (const char * s )
+{
+ int n;
+ for ( n = 0; s[n]; ++n )
+ ;
+
+ return n;
+}
+#endif
+
+void *d2_parser_alloc (yy_size_t size )
+{
+ return malloc(size);
+}
+
+void *d2_parser_realloc (void * ptr, yy_size_t size )
+{
+
+ /* The cast to (char *) in the following accommodates both
+ * implementations that use char* generic pointers, and those
+ * that use void* generic pointers. It works with the latter
+ * because both ANSI C and C++ allow castless assignment from
+ * any pointer type to void*, and deal with argument conversions
+ * as though doing an assignment.
+ */
+ return realloc(ptr, size);
+}
+
+void d2_parser_free (void * ptr )
+{
+ free( (char *) ptr ); /* see d2_parser_realloc() for (char *) cast */
+}
+
+/* %if-tables-serialization definitions */
+/* %define-yytables The name for this specific scanner's tables. */
+#define YYTABLES_NAME "yytables"
+/* %endif */
+
+/* %ok-for-header */
+
+#line 634 "d2_lexer.ll"
+
+
+using namespace isc::dhcp;
+
+void
+D2ParserContext::scanStringBegin(const std::string& str, ParserType parser_type)
+{
+ start_token_flag = true;
+ start_token_value = parser_type;
+
+ file_ = "<string>";
+ sfile_ = 0;
+ loc_.initialize(&file_);
+ yy_flex_debug = trace_scanning_;
+ YY_BUFFER_STATE buffer;
+ buffer = d2_parser__scan_bytes(str.c_str(), str.size());
+ if (!buffer) {
+ fatal("cannot scan string");
+ // fatal() throws an exception so this can't be reached
+ }
+}
+
+void
+D2ParserContext::scanFileBegin(FILE * f,
+ const std::string& filename,
+ ParserType parser_type)
+{
+ start_token_flag = true;
+ start_token_value = parser_type;
+
+ file_ = filename;
+ sfile_ = f;
+ loc_.initialize(&file_);
+ yy_flex_debug = trace_scanning_;
+ YY_BUFFER_STATE buffer;
+
+ // See d2_lexer.cc header for available definitions
+ buffer = d2_parser__create_buffer(f, 65536 /*buffer size*/);
+ if (!buffer) {
+ fatal("cannot scan file " + filename);
+ }
+ d2_parser__switch_to_buffer(buffer);
+}
+
+void
+D2ParserContext::scanEnd() {
+ if (sfile_)
+ fclose(sfile_);
+ sfile_ = 0;
+ static_cast<void>(d2_parser_lex_destroy());
+ // Close files
+ while (!sfiles_.empty()) {
+ FILE* f = sfiles_.back();
+ if (f) {
+ fclose(f);
+ }
+ sfiles_.pop_back();
+ }
+ // Delete states
+ while (!states_.empty()) {
+ d2_parser__delete_buffer(states_.back());
+ states_.pop_back();
+ }
+}
+
+void
+D2ParserContext::includeFile(const std::string& filename) {
+ if (states_.size() > 10) {
+ fatal("Too many nested include.");
+ }
+
+ FILE* f = fopen(filename.c_str(), "r");
+ if (!f) {
+ fatal("Can't open include file " + filename);
+ }
+ if (sfile_) {
+ sfiles_.push_back(sfile_);
+ }
+ sfile_ = f;
+ states_.push_back(YY_CURRENT_BUFFER);
+ YY_BUFFER_STATE buffer;
+ buffer = d2_parser__create_buffer(f, 65536 /*buffer size*/);
+ if (!buffer) {
+ fatal( "Can't scan include file " + filename);
+ }
+ d2_parser__switch_to_buffer(buffer);
+ files_.push_back(file_);
+ file_ = filename;
+ locs_.push_back(loc_);
+ loc_.initialize(&file_);
+
+ BEGIN(INITIAL);
+}
+
+namespace {
+/// To avoid unused function error
+class Dummy {
+ // cppcheck-suppress unusedPrivateFunction
+ void dummy() { yy_fatal_error("Fix me: how to disable its definition?"); }
+};
+}
+
--- /dev/null
+/* Copyright (C) 2017 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
+ file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+%{ /* -*- C++ -*- */
+#include <cerrno>
+#include <climits>
+#include <cstdlib>
+#include <string>
+#include <d2/parser_context.h>
+#include <asiolink/io_address.h>
+#include <boost/lexical_cast.hpp>
+#include <exceptions/exceptions.h>
+
+// Work around an incompatibility in flex (at least versions
+// 2.5.31 through 2.5.33): it generates code that does
+// not conform to C89. See Debian bug 333231
+// <http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=333231>.
+# undef yywrap
+# define yywrap() 1
+
+namespace {
+
+bool start_token_flag = false;
+
+isc::d2::D2ParserContext::ParserType start_token_value;
+unsigned int comment_start_line = 0;
+
+};
+
+// To avoid the call to exit... oops!
+#define YY_FATAL_ERROR(msg) isc::d2::D2ParserContext::fatal(msg)
+%}
+
+/* noyywrap disables automatic rewinding for the next file to parse. Since we
+ always parse only a single string, there's no need to do any wraps. And
+ using yywrap requires linking with -lfl, which provides the default yywrap
+ implementation that always returns 1 anyway. */
+%option noyywrap
+
+/* nounput simplifies the lexer, by removing support for putting a character
+ back into the input stream. We never use such capability anyway. */
+%option nounput
+
+/* batch means that we'll never use the generated lexer interactively. */
+%option batch
+
+/* avoid to get static global variables to remain with C++. */
+/* in last resort %option reentrant */
+
+/* Enables debug mode. To see the debug messages, one needs to also set
+ yy_flex_debug to 1, then the debug messages will be printed on stderr. */
+%option debug
+
+/* I have no idea what this option does, except it was specified in the bison
+ examples and Postgres folks added it to remove gcc 4.3 warnings. Let's
+ be on the safe side and keep it. */
+%option noinput
+
+%x COMMENT
+%x DIR_ENTER DIR_INCLUDE DIR_EXIT
+
+/* These are not token expressions yet, just convenience expressions that
+ can be used during actual token definitions. Note some can match
+ incorrect inputs (e.g., IP addresses) which must be checked. */
+int \-?[0-9]+
+blank [ \t\r]
+
+UnicodeEscapeSequence u[0-9A-Fa-f]{4}
+JSONEscapeCharacter ["\\/bfnrt]
+JSONEscapeSequence {JSONEscapeCharacter}|{UnicodeEscapeSequence}
+JSONStandardCharacter [^\x00-\x1f"\\]
+JSONStringCharacter {JSONStandardCharacter}|\\{JSONEscapeSequence}
+JSONString \"{JSONStringCharacter}*\"
+
+/* for errors */
+
+BadUnicodeEscapeSequence u[0-9A-Fa-f]{0,3}[^0-9A-Fa-f]
+BadJSONEscapeSequence [^"\\/bfnrtu]|{BadUnicodeEscapeSequence}
+ControlCharacter [\x00-\x1f]
+ControlCharacterFill [^"\\]|\\{JSONEscapeSequence}
+
+%{
+// This code run each time a pattern is matched. It updates the location
+// by moving it ahead by yyleng bytes. yyleng specifies the length of the
+// currently matched token.
+#define YY_USER_ACTION driver.loc_.columns(yyleng);
+%}
+
+%%
+
+%{
+ // This part of the code is copied over to the verbatim to the top
+ // of the generated yylex function. Explanation:
+ // http://www.gnu.org/software/bison/manual/html_node/Multiple-start_002dsymbols.html
+
+ // Code run each time yylex is called.
+ driver.loc_.step();
+
+ if (start_token_flag) {
+ start_token_flag = false;
+ switch (start_token_value) {
+ case D2ParserContext::PARSER_JSON:
+ default:
+ return isc::d2::D2Parser::make_TOPLEVEL_JSON(driver.loc_);
+ case D2ParserContext::PARSER_DHCPDDNS:
+ return isc::d2::D2Parser::make_TOPLEVEL_DHCPDDNS(driver.loc_);
+ case D2ParserContext::PARSER_SUB_DHCPDDNS:
+ return isc::d2::D2Parser::make_SUB_DHCPDDNS(driver.loc_);
+ case D2ParserContext::PARSER_TSIG_KEY:
+ return isc::d2::D2Parser::make_SUB_TSIG_KEY(driver.loc_);
+ case D2ParserContext::PARSER_TSIG_KEYS:
+ return isc::d2::D2Parser::make_SUB_TSIG_KEYS(driver.loc_);
+ case D2ParserContext::PARSER_DDNS_DOMAIN:
+ return isc::d2::D2Parser::make_SUB_DDNS_DOMAIN(driver.loc_);
+ case D2ParserContext::PARSER_DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_SUB_DDNS_DOMAINS(driver.loc_);
+ case D2ParserContext::PARSER_DNS_SERVER:
+ return isc::d2::D2Parser::make_SUB_DNS_SERVER(driver.loc_);
+ }
+ }
+%}
+
+#.* ;
+
+"//"(.*) ;
+
+"/*" {
+ BEGIN(COMMENT);
+ comment_start_line = driver.loc_.end.line;;
+}
+
+<COMMENT>"*/" BEGIN(INITIAL);
+<COMMENT>. ;
+<COMMENT><<EOF>> {
+ isc_throw(D2ParseError, "Comment not closed. (/* in line " << comment_start_line);
+}
+
+"<?" BEGIN(DIR_ENTER);
+<DIR_ENTER>"include" BEGIN(DIR_INCLUDE);
+<DIR_INCLUDE>\"([^\"\n])+\" {
+ // Include directive.
+
+ // Extract the filename.
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+
+ driver.includeFile(tmp);
+}
+<DIR_ENTER,DIR_INCLUDE,DIR_EXIT><<EOF>> {
+ isc_throw(D2ParseError, "Directive not closed.");
+}
+<DIR_EXIT>"?>" BEGIN(INITIAL);
+
+
+<*>{blank}+ {
+ // Ok, we found a with space. Let's ignore it and update loc variable.
+ driver.loc_.step();
+}
+
+<*>[\n]+ {
+ // Newline found. Let's update the location and continue.
+ driver.loc_.lines(yyleng);
+ driver.loc_.step();
+}
+
+\"DhcpDdns\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_DHCPDDNS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("DhcpDdns", driver.loc_);
+ }
+}
+
+\"ip-address\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ case isc::d2::D2ParserContext::DNS_SERVER:
+ case isc::d2::D2ParserContext::DNS_SERVERS:
+ return isc::d2::D2Parser::make_IP_ADDRESS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ip-address", driver.loc_);
+ }
+}
+
+\"port\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ case isc::d2::D2ParserContext::DNS_SERVER:
+ case isc::d2::D2ParserContext::DNS_SERVERS:
+ return isc::d2::D2Parser::make_PORT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("port", driver.loc_);
+ }
+}
+
+\"dns-server-timeout\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_DNS_SERVER_TIMEOUT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("dns-server-timeout", driver.loc_);
+ }
+}
+
+\"ncr-protocol\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_NCR_PROTOCOL(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ncr-protocol", driver.loc_);
+ }
+}
+
+\"ncr-format\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_NCR_FORMAT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ncr-format", driver.loc_);
+ }
+}
+
+(?i:\"UDP\") {
+ /* dhcp-ddns value keywords are case insensitive */
+ if (driver.ctx_ == isc::d2::D2ParserContext::NCR_PROTOCOL) {
+ return isc::d2::D2Parser::make_UDP(driver.loc_);
+ }
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+ return isc::d2::D2Parser::make_STRING(tmp, driver.loc_);
+}
+
+(?i:\"TCP\") {
+ /* dhcp-ddns value keywords are case insensitive */
+ if (driver.ctx_ == isc::d2::D2ParserContext::NCR_PROTOCOL) {
+ return isc::d2::D2Parser::make_TCP(driver.loc_);
+ }
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+ return isc::d2::D2Parser::make_STRING(tmp, driver.loc_);
+}
+
+(?i:\"JSON\") {
+ /* dhcp-ddns value keywords are case insensitive */
+ if (driver.ctx_ == isc::d2::D2ParserContext::NCR_FORMAT) {
+ return isc::d2::D2Parser::make_JSON(driver.loc_);
+ }
+ std::string tmp(yytext+1);
+ tmp.resize(tmp.size() - 1);
+ return isc::d2::D2Parser::make_STRING(tmp, driver.loc_);
+}
+
+\"forward-ddns\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_FORWARD_DDNS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("forward-ddns", driver.loc_);
+ }
+}
+
+\"reverse-ddns\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_REVERSE_DDNS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("reverse-ddns", driver.loc_);
+ }
+}
+
+\"ddns-domains\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::FORWARD_DDNS:
+ case isc::d2::D2ParserContext::REVERSE_DDNS:
+ return isc::d2::D2Parser::make_DDNS_DOMAINS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("ddns-domains", driver.loc_);
+ }
+}
+
+\"key-name\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DDNS_DOMAIN:
+ case isc::d2::D2ParserContext::DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_KEY_NAME(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("key-name", driver.loc_);
+ }
+}
+
+\"dns-servers\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DDNS_DOMAIN:
+ case isc::d2::D2ParserContext::DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_DNS_SERVERS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("dns-servers", driver.loc_);
+ }
+}
+
+\"hostname\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DNS_SERVER:
+ case isc::d2::D2ParserContext::DNS_SERVERS:
+ return isc::d2::D2Parser::make_HOSTNAME(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("hostname", driver.loc_);
+ }
+}
+
+
+\"tsig-keys\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::DHCPDDNS:
+ return isc::d2::D2Parser::make_TSIG_KEYS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("tsig-keys", driver.loc_);
+ }
+}
+
+\"algorithm\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ return isc::d2::D2Parser::make_ALGORITHM(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("algorithm", driver.loc_);
+ }
+}
+
+\"digest-bits\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ return isc::d2::D2Parser::make_DIGEST_BITS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("digest-bits", driver.loc_);
+ }
+}
+
+\"secret\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ return isc::d2::D2Parser::make_SECRET(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("secret", driver.loc_);
+ }
+}
+
+
+\"Logging\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_LOGGING(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("Logging", driver.loc_);
+ }
+}
+
+\"loggers\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGING:
+ return isc::d2::D2Parser::make_LOGGERS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("loggers", driver.loc_);
+ }
+}
+
+\"output_options\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ return isc::d2::D2Parser::make_OUTPUT_OPTIONS(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("output_options", driver.loc_);
+ }
+}
+
+\"output\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::OUTPUT_OPTIONS:
+ return isc::d2::D2Parser::make_OUTPUT(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("output", driver.loc_);
+ }
+}
+
+\"name\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ case isc::d2::D2ParserContext::TSIG_KEY:
+ case isc::d2::D2ParserContext::TSIG_KEYS:
+ case isc::d2::D2ParserContext::DDNS_DOMAIN:
+ case isc::d2::D2ParserContext::DDNS_DOMAINS:
+ return isc::d2::D2Parser::make_NAME(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("name", driver.loc_);
+ }
+}
+
+\"debuglevel\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ return isc::d2::D2Parser::make_DEBUGLEVEL(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("debuglevel", driver.loc_);
+ }
+}
+
+\"severity\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::LOGGERS:
+ return isc::d2::D2Parser::make_SEVERITY(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("severity", driver.loc_);
+ }
+}
+
+\"Dhcp4\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_DHCP4(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("Dhcp4", driver.loc_);
+ }
+}
+
+\"Dhcp6\" {
+ switch(driver.ctx_) {
+ case isc::d2::D2ParserContext::CONFIG:
+ return isc::d2::D2Parser::make_DHCP6(driver.loc_);
+ default:
+ return isc::d2::D2Parser::make_STRING("Dhcp6", driver.loc_);
+ }
+}
+
+
+{JSONString} {
+ // A string has been matched. It contains the actual string and single quotes.
+ // We need to get those quotes out of the way and just use its content, e.g.
+ // for 'foo' we should get foo
+ std::string raw(yytext+1);
+ size_t len = raw.size() - 1;
+ raw.resize(len);
+ std::string decoded;
+ decoded.reserve(len);
+ for (size_t pos = 0; pos < len; ++pos) {
+ int b = 0;
+ char c = raw[pos];
+ switch (c) {
+ case '"':
+ // impossible condition
+ driver.error(driver.loc_, "Bad quote in \"" + raw + "\"");
+ case '\\':
+ ++pos;
+ if (pos >= len) {
+ // impossible condition
+ driver.error(driver.loc_, "Overflow escape in \"" + raw + "\"");
+ }
+ c = raw[pos];
+ switch (c) {
+ case '"':
+ case '\\':
+ case '/':
+ decoded.push_back(c);
+ break;
+ case 'b':
+ decoded.push_back('\b');
+ break;
+ case 'f':
+ decoded.push_back('\f');
+ break;
+ case 'n':
+ decoded.push_back('\n');
+ break;
+ case 'r':
+ decoded.push_back('\r');
+ break;
+ case 't':
+ decoded.push_back('\t');
+ break;
+ case 'u':
+ // support only \u0000 to \u00ff
+ ++pos;
+ if (pos + 4 > len) {
+ // impossible condition
+ driver.error(driver.loc_,
+ "Overflow unicode escape in \"" + raw + "\"");
+ }
+ if ((raw[pos] != '0') || (raw[pos + 1] != '0')) {
+ driver.error(driver.loc_, "Unsupported unicode escape in \"" + raw + "\"");
+ }
+ pos += 2;
+ c = raw[pos];
+ if ((c >= '0') && (c <= '9')) {
+ b = (c - '0') << 4;
+ } else if ((c >= 'A') && (c <= 'F')) {
+ b = (c - 'A' + 10) << 4;
+ } else if ((c >= 'a') && (c <= 'f')) {
+ b = (c - 'a' + 10) << 4;
+ } else {
+ // impossible condition
+ driver.error(driver.loc_, "Not hexadecimal in unicode escape in \"" + raw + "\"");
+ }
+ pos++;
+ c = raw[pos];
+ if ((c >= '0') && (c <= '9')) {
+ b |= c - '0';
+ } else if ((c >= 'A') && (c <= 'F')) {
+ b |= c - 'A' + 10;
+ } else if ((c >= 'a') && (c <= 'f')) {
+ b |= c - 'a' + 10;
+ } else {
+ // impossible condition
+ driver.error(driver.loc_, "Not hexadecimal in unicode escape in \"" + raw + "\"");
+ }
+ decoded.push_back(static_cast<char>(b & 0xff));
+ break;
+ default:
+ // impossible condition
+ driver.error(driver.loc_, "Bad escape in \"" + raw + "\"");
+ }
+ break;
+ default:
+ if ((c >= 0) && (c < 0x20)) {
+ // impossible condition
+ driver.error(driver.loc_, "Invalid control in \"" + raw + "\"");
+ }
+ decoded.push_back(c);
+ }
+ }
+
+ return isc::d2::D2Parser::make_STRING(decoded, driver.loc_);
+}
+
+\"{JSONStringCharacter}*{ControlCharacter}{ControlCharacterFill}*\" {
+ // Bad string with a forbidden control character inside
+ driver.error(driver.loc_, "Invalid control in " + std::string(yytext));
+}
+
+\"{JSONStringCharacter}*\\{BadJSONEscapeSequence}[^\x00-\x1f"]*\" {
+ // Bad string with a bad escape inside
+ driver.error(driver.loc_, "Bad escape in " + std::string(yytext));
+}
+
+\"{JSONStringCharacter}*\\\" {
+ // Bad string with an open escape at the end
+ driver.error(driver.loc_, "Overflow escape in " + std::string(yytext));
+}
+
+"[" { return isc::d2::D2Parser::make_LSQUARE_BRACKET(driver.loc_); }
+"]" { return isc::d2::D2Parser::make_RSQUARE_BRACKET(driver.loc_); }
+"{" { return isc::d2::D2Parser::make_LCURLY_BRACKET(driver.loc_); }
+"}" { return isc::d2::D2Parser::make_RCURLY_BRACKET(driver.loc_); }
+"," { return isc::d2::D2Parser::make_COMMA(driver.loc_); }
+":" { return isc::d2::D2Parser::make_COLON(driver.loc_); }
+
+{int} {
+ // An integer was found.
+ std::string tmp(yytext);
+ int64_t integer = 0;
+ try {
+ // In substring we want to use negative values (e.g. -1).
+ // In enterprise-id we need to use values up to 0xffffffff.
+ // To cover both of those use cases, we need at least
+ // int64_t.
+ integer = boost::lexical_cast<int64_t>(tmp);
+ } catch (const boost::bad_lexical_cast &) {
+ driver.error(driver.loc_, "Failed to convert " + tmp + " to an integer.");
+ }
+
+ // The parser needs the string form as double conversion is no lossless
+ return isc::d2::D2Parser::make_INTEGER(integer, driver.loc_);
+}
+
+[-+]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)? {
+ // A floating point was found.
+ std::string tmp(yytext);
+ double fp = 0.0;
+ try {
+ fp = boost::lexical_cast<double>(tmp);
+ } catch (const boost::bad_lexical_cast &) {
+ driver.error(driver.loc_, "Failed to convert " + tmp + " to a floating point.");
+ }
+
+ return isc::d2::D2Parser::make_FLOAT(fp, driver.loc_);
+}
+
+true|false {
+ string tmp(yytext);
+ return isc::d2::D2Parser::make_BOOLEAN(tmp == "true", driver.loc_);
+}
+
+null {
+ return isc::d2::D2Parser::make_NULL_TYPE(driver.loc_);
+}
+
+(?i:true) driver.error (driver.loc_, "JSON true reserved keyword is lower case only");
+
+(?i:false) driver.error (driver.loc_, "JSON false reserved keyword is lower case only");
+
+(?i:null) driver.error (driver.loc_, "JSON null reserved keyword is lower case only");
+
+<*>. driver.error (driver.loc_, "Invalid character: " + std::string(yytext));
+
+<<EOF>> {
+ if (driver.states_.empty()) {
+ return isc::d2::D2Parser::make_END(driver.loc_);
+ }
+ driver.loc_ = driver.locs_.back();
+ driver.locs_.pop_back();
+ driver.file_ = driver.files_.back();
+ driver.files_.pop_back();
+ if (driver.sfile_) {
+ fclose(driver.sfile_);
+ driver.sfile_ = 0;
+ }
+ if (!driver.sfiles_.empty()) {
+ driver.sfile_ = driver.sfiles_.back();
+ driver.sfiles_.pop_back();
+ }
+ d2_parser__delete_buffer(YY_CURRENT_BUFFER);
+ d2_parser__switch_to_buffer(driver.states_.back());
+ driver.states_.pop_back();
+
+ BEGIN(DIR_EXIT);
+}
+
+%%
+
+using namespace isc::dhcp;
+
+void
+D2ParserContext::scanStringBegin(const std::string& str, ParserType parser_type)
+{
+ start_token_flag = true;
+ start_token_value = parser_type;
+
+ file_ = "<string>";
+ sfile_ = 0;
+ loc_.initialize(&file_);
+ yy_flex_debug = trace_scanning_;
+ YY_BUFFER_STATE buffer;
+ buffer = d2_parser__scan_bytes(str.c_str(), str.size());
+ if (!buffer) {
+ fatal("cannot scan string");
+ // fatal() throws an exception so this can't be reached
+ }
+}
+
+void
+D2ParserContext::scanFileBegin(FILE * f,
+ const std::string& filename,
+ ParserType parser_type)
+{
+ start_token_flag = true;
+ start_token_value = parser_type;
+
+ file_ = filename;
+ sfile_ = f;
+ loc_.initialize(&file_);
+ yy_flex_debug = trace_scanning_;
+ YY_BUFFER_STATE buffer;
+
+ // See d2_lexer.cc header for available definitions
+ buffer = d2_parser__create_buffer(f, 65536 /*buffer size*/);
+ if (!buffer) {
+ fatal("cannot scan file " + filename);
+ }
+ d2_parser__switch_to_buffer(buffer);
+}
+
+void
+D2ParserContext::scanEnd() {
+ if (sfile_)
+ fclose(sfile_);
+ sfile_ = 0;
+ static_cast<void>(d2_parser_lex_destroy());
+ // Close files
+ while (!sfiles_.empty()) {
+ FILE* f = sfiles_.back();
+ if (f) {
+ fclose(f);
+ }
+ sfiles_.pop_back();
+ }
+ // Delete states
+ while (!states_.empty()) {
+ d2_parser__delete_buffer(states_.back());
+ states_.pop_back();
+ }
+}
+
+void
+D2ParserContext::includeFile(const std::string& filename) {
+ if (states_.size() > 10) {
+ fatal("Too many nested include.");
+ }
+
+ FILE* f = fopen(filename.c_str(), "r");
+ if (!f) {
+ fatal("Can't open include file " + filename);
+ }
+ if (sfile_) {
+ sfiles_.push_back(sfile_);
+ }
+ sfile_ = f;
+ states_.push_back(YY_CURRENT_BUFFER);
+ YY_BUFFER_STATE buffer;
+ buffer = d2_parser__create_buffer(f, 65536 /*buffer size*/);
+ if (!buffer) {
+ fatal( "Can't scan include file " + filename);
+ }
+ d2_parser__switch_to_buffer(buffer);
+ files_.push_back(file_);
+ file_ = filename;
+ locs_.push_back(loc_);
+ loc_.initialize(&file_);
+
+ BEGIN(INITIAL);
+}
+
+namespace {
+/// To avoid unused function error
+class Dummy {
+ // cppcheck-suppress unusedPrivateFunction
+ void dummy() { yy_fatal_error("Fix me: how to disable its definition?"); }
+};
+}
--- /dev/null
+// A Bison parser, made by GNU Bison 3.0.4.
+
+// Skeleton implementation for Bison LALR(1) parsers in C++
+
+// Copyright (C) 2002-2015 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton. Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+// Take the name prefix into account.
+#define yylex d2_parser_lex
+
+// First part of user declarations.
+
+#line 39 "d2_parser.cc" // lalr1.cc:404
+
+# ifndef YY_NULLPTR
+# if defined __cplusplus && 201103L <= __cplusplus
+# define YY_NULLPTR nullptr
+# else
+# define YY_NULLPTR 0
+# endif
+# endif
+
+#include "d2_parser.h"
+
+// User implementation prologue.
+
+#line 53 "d2_parser.cc" // lalr1.cc:412
+// Unqualified %code blocks.
+#line 34 "d2_parser.yy" // lalr1.cc:413
+
+#include <d2/parser_context.h>
+
+#line 59 "d2_parser.cc" // lalr1.cc:413
+
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> // FIXME: INFRINGES ON USER NAME SPACE.
+# define YY_(msgid) dgettext ("bison-runtime", msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(msgid) msgid
+# endif
+#endif
+
+#define YYRHSLOC(Rhs, K) ((Rhs)[K].location)
+/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
+ If N is 0, then set CURRENT to the empty location which ends
+ the previous symbol: RHS[0] (always defined). */
+
+# ifndef YYLLOC_DEFAULT
+# define YYLLOC_DEFAULT(Current, Rhs, N) \
+ do \
+ if (N) \
+ { \
+ (Current).begin = YYRHSLOC (Rhs, 1).begin; \
+ (Current).end = YYRHSLOC (Rhs, N).end; \
+ } \
+ else \
+ { \
+ (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
+ } \
+ while (/*CONSTCOND*/ false)
+# endif
+
+
+// Suppress unused-variable warnings by "using" E.
+#define YYUSE(E) ((void) (E))
+
+// Enable debugging if requested.
+#if D2_PARSER_DEBUG
+
+// A pseudo ostream that takes yydebug_ into account.
+# define YYCDEBUG if (yydebug_) (*yycdebug_)
+
+# define YY_SYMBOL_PRINT(Title, Symbol) \
+ do { \
+ if (yydebug_) \
+ { \
+ *yycdebug_ << Title << ' '; \
+ yy_print_ (*yycdebug_, Symbol); \
+ *yycdebug_ << std::endl; \
+ } \
+ } while (false)
+
+# define YY_REDUCE_PRINT(Rule) \
+ do { \
+ if (yydebug_) \
+ yy_reduce_print_ (Rule); \
+ } while (false)
+
+# define YY_STACK_PRINT() \
+ do { \
+ if (yydebug_) \
+ yystack_print_ (); \
+ } while (false)
+
+#else // !D2_PARSER_DEBUG
+
+# define YYCDEBUG if (false) std::cerr
+# define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol)
+# define YY_REDUCE_PRINT(Rule) static_cast<void>(0)
+# define YY_STACK_PRINT() static_cast<void>(0)
+
+#endif // !D2_PARSER_DEBUG
+
+#define yyerrok (yyerrstatus_ = 0)
+#define yyclearin (yyla.clear ())
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+#define YYRECOVERING() (!!yyerrstatus_)
+
+#line 14 "d2_parser.yy" // lalr1.cc:479
+namespace isc { namespace d2 {
+#line 145 "d2_parser.cc" // lalr1.cc:479
+
+ /* Return YYSTR after stripping away unnecessary quotes and
+ backslashes, so that it's suitable for yyerror. The heuristic is
+ that double-quoting is unnecessary unless the string contains an
+ apostrophe, a comma, or backslash (other than backslash-backslash).
+ YYSTR is taken from yytname. */
+ std::string
+ D2Parser::yytnamerr_ (const char *yystr)
+ {
+ if (*yystr == '"')
+ {
+ std::string yyr = "";
+ char const *yyp = yystr;
+
+ for (;;)
+ switch (*++yyp)
+ {
+ case '\'':
+ case ',':
+ goto do_not_strip_quotes;
+
+ case '\\':
+ if (*++yyp != '\\')
+ goto do_not_strip_quotes;
+ // Fall through.
+ default:
+ yyr += *yyp;
+ break;
+
+ case '"':
+ return yyr;
+ }
+ do_not_strip_quotes: ;
+ }
+
+ return yystr;
+ }
+
+
+ /// Build a parser object.
+ D2Parser::D2Parser (isc::d2::D2ParserContext& ctx_yyarg)
+ :
+#if D2_PARSER_DEBUG
+ yydebug_ (false),
+ yycdebug_ (&std::cerr),
+#endif
+ ctx (ctx_yyarg)
+ {}
+
+ D2Parser::~D2Parser ()
+ {}
+
+
+ /*---------------.
+ | Symbol types. |
+ `---------------*/
+
+
+
+ // by_state.
+ inline
+ D2Parser::by_state::by_state ()
+ : state (empty_state)
+ {}
+
+ inline
+ D2Parser::by_state::by_state (const by_state& other)
+ : state (other.state)
+ {}
+
+ inline
+ void
+ D2Parser::by_state::clear ()
+ {
+ state = empty_state;
+ }
+
+ inline
+ void
+ D2Parser::by_state::move (by_state& that)
+ {
+ state = that.state;
+ that.clear ();
+ }
+
+ inline
+ D2Parser::by_state::by_state (state_type s)
+ : state (s)
+ {}
+
+ inline
+ D2Parser::symbol_number_type
+ D2Parser::by_state::type_get () const
+ {
+ if (state == empty_state)
+ return empty_symbol;
+ else
+ return yystos_[state];
+ }
+
+ inline
+ D2Parser::stack_symbol_type::stack_symbol_type ()
+ {}
+
+
+ inline
+ D2Parser::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that)
+ : super_type (s, that.location)
+ {
+ switch (that.type_get ())
+ {
+ case 62: // value
+ case 89: // ncr_protocol_value
+ value.move< ElementPtr > (that.value);
+ break;
+
+ case 50: // "boolean"
+ value.move< bool > (that.value);
+ break;
+
+ case 49: // "floating point"
+ value.move< double > (that.value);
+ break;
+
+ case 48: // "integer"
+ value.move< int64_t > (that.value);
+ break;
+
+ case 47: // "constant string"
+ value.move< std::string > (that.value);
+ break;
+
+ default:
+ break;
+ }
+
+ // that is emptied.
+ that.type = empty_symbol;
+ }
+
+ inline
+ D2Parser::stack_symbol_type&
+ D2Parser::stack_symbol_type::operator= (const stack_symbol_type& that)
+ {
+ state = that.state;
+ switch (that.type_get ())
+ {
+ case 62: // value
+ case 89: // ncr_protocol_value
+ value.copy< ElementPtr > (that.value);
+ break;
+
+ case 50: // "boolean"
+ value.copy< bool > (that.value);
+ break;
+
+ case 49: // "floating point"
+ value.copy< double > (that.value);
+ break;
+
+ case 48: // "integer"
+ value.copy< int64_t > (that.value);
+ break;
+
+ case 47: // "constant string"
+ value.copy< std::string > (that.value);
+ break;
+
+ default:
+ break;
+ }
+
+ location = that.location;
+ return *this;
+ }
+
+
+ template <typename Base>
+ inline
+ void
+ D2Parser::yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const
+ {
+ if (yymsg)
+ YY_SYMBOL_PRINT (yymsg, yysym);
+ }
+
+#if D2_PARSER_DEBUG
+ template <typename Base>
+ void
+ D2Parser::yy_print_ (std::ostream& yyo,
+ const basic_symbol<Base>& yysym) const
+ {
+ std::ostream& yyoutput = yyo;
+ YYUSE (yyoutput);
+ symbol_number_type yytype = yysym.type_get ();
+ // Avoid a (spurious) G++ 4.8 warning about "array subscript is
+ // below array bounds".
+ if (yysym.empty ())
+ std::abort ();
+ yyo << (yytype < yyntokens_ ? "token" : "nterm")
+ << ' ' << yytname_[yytype] << " ("
+ << yysym.location << ": ";
+ switch (yytype)
+ {
+ case 47: // "constant string"
+
+#line 104 "d2_parser.yy" // lalr1.cc:636
+ { yyoutput << yysym.value.template as< std::string > (); }
+#line 354 "d2_parser.cc" // lalr1.cc:636
+ break;
+
+ case 48: // "integer"
+
+#line 104 "d2_parser.yy" // lalr1.cc:636
+ { yyoutput << yysym.value.template as< int64_t > (); }
+#line 361 "d2_parser.cc" // lalr1.cc:636
+ break;
+
+ case 49: // "floating point"
+
+#line 104 "d2_parser.yy" // lalr1.cc:636
+ { yyoutput << yysym.value.template as< double > (); }
+#line 368 "d2_parser.cc" // lalr1.cc:636
+ break;
+
+ case 50: // "boolean"
+
+#line 104 "d2_parser.yy" // lalr1.cc:636
+ { yyoutput << yysym.value.template as< bool > (); }
+#line 375 "d2_parser.cc" // lalr1.cc:636
+ break;
+
+ case 62: // value
+
+#line 104 "d2_parser.yy" // lalr1.cc:636
+ { yyoutput << yysym.value.template as< ElementPtr > (); }
+#line 382 "d2_parser.cc" // lalr1.cc:636
+ break;
+
+ case 89: // ncr_protocol_value
+
+#line 104 "d2_parser.yy" // lalr1.cc:636
+ { yyoutput << yysym.value.template as< ElementPtr > (); }
+#line 389 "d2_parser.cc" // lalr1.cc:636
+ break;
+
+
+ default:
+ break;
+ }
+ yyo << ')';
+ }
+#endif
+
+ inline
+ void
+ D2Parser::yypush_ (const char* m, state_type s, symbol_type& sym)
+ {
+ stack_symbol_type t (s, sym);
+ yypush_ (m, t);
+ }
+
+ inline
+ void
+ D2Parser::yypush_ (const char* m, stack_symbol_type& s)
+ {
+ if (m)
+ YY_SYMBOL_PRINT (m, s);
+ yystack_.push (s);
+ }
+
+ inline
+ void
+ D2Parser::yypop_ (unsigned int n)
+ {
+ yystack_.pop (n);
+ }
+
+#if D2_PARSER_DEBUG
+ std::ostream&
+ D2Parser::debug_stream () const
+ {
+ return *yycdebug_;
+ }
+
+ void
+ D2Parser::set_debug_stream (std::ostream& o)
+ {
+ yycdebug_ = &o;
+ }
+
+
+ D2Parser::debug_level_type
+ D2Parser::debug_level () const
+ {
+ return yydebug_;
+ }
+
+ void
+ D2Parser::set_debug_level (debug_level_type l)
+ {
+ yydebug_ = l;
+ }
+#endif // D2_PARSER_DEBUG
+
+ inline D2Parser::state_type
+ D2Parser::yy_lr_goto_state_ (state_type yystate, int yysym)
+ {
+ int yyr = yypgoto_[yysym - yyntokens_] + yystate;
+ if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate)
+ return yytable_[yyr];
+ else
+ return yydefgoto_[yysym - yyntokens_];
+ }
+
+ inline bool
+ D2Parser::yy_pact_value_is_default_ (int yyvalue)
+ {
+ return yyvalue == yypact_ninf_;
+ }
+
+ inline bool
+ D2Parser::yy_table_value_is_error_ (int yyvalue)
+ {
+ return yyvalue == yytable_ninf_;
+ }
+
+ int
+ D2Parser::parse ()
+ {
+ // State.
+ int yyn;
+ /// Length of the RHS of the rule being reduced.
+ int yylen = 0;
+
+ // Error handling.
+ int yynerrs_ = 0;
+ int yyerrstatus_ = 0;
+
+ /// The lookahead symbol.
+ symbol_type yyla;
+
+ /// The locations where the error started and ended.
+ stack_symbol_type yyerror_range[3];
+
+ /// The return value of parse ().
+ int yyresult;
+
+ // FIXME: This shoud be completely indented. It is not yet to
+ // avoid gratuitous conflicts when merging into the master branch.
+ try
+ {
+ YYCDEBUG << "Starting parse" << std::endl;
+
+
+ /* Initialize the stack. The initial state will be set in
+ yynewstate, since the latter expects the semantical and the
+ location values to have been already stored, initialize these
+ stacks with a primary value. */
+ yystack_.clear ();
+ yypush_ (YY_NULLPTR, 0, yyla);
+
+ // A new symbol was pushed on the stack.
+ yynewstate:
+ YYCDEBUG << "Entering state " << yystack_[0].state << std::endl;
+
+ // Accept?
+ if (yystack_[0].state == yyfinal_)
+ goto yyacceptlab;
+
+ goto yybackup;
+
+ // Backup.
+ yybackup:
+
+ // Try to take a decision without lookahead.
+ yyn = yypact_[yystack_[0].state];
+ if (yy_pact_value_is_default_ (yyn))
+ goto yydefault;
+
+ // Read a lookahead token.
+ if (yyla.empty ())
+ {
+ YYCDEBUG << "Reading a token: ";
+ try
+ {
+ symbol_type yylookahead (yylex (ctx));
+ yyla.move (yylookahead);
+ }
+ catch (const syntax_error& yyexc)
+ {
+ error (yyexc);
+ goto yyerrlab1;
+ }
+ }
+ YY_SYMBOL_PRINT ("Next token is", yyla);
+
+ /* If the proper action on seeing token YYLA.TYPE is to reduce or
+ to detect an error, take that action. */
+ yyn += yyla.type_get ();
+ if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ())
+ goto yydefault;
+
+ // Reduce or error.
+ yyn = yytable_[yyn];
+ if (yyn <= 0)
+ {
+ if (yy_table_value_is_error_ (yyn))
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ // Count tokens shifted since error; after three, turn off error status.
+ if (yyerrstatus_)
+ --yyerrstatus_;
+
+ // Shift the lookahead token.
+ yypush_ ("Shifting", yyn, yyla);
+ goto yynewstate;
+
+ /*-----------------------------------------------------------.
+ | yydefault -- do the default action for the current state. |
+ `-----------------------------------------------------------*/
+ yydefault:
+ yyn = yydefact_[yystack_[0].state];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+ /*-----------------------------.
+ | yyreduce -- Do a reduction. |
+ `-----------------------------*/
+ yyreduce:
+ yylen = yyr2_[yyn];
+ {
+ stack_symbol_type yylhs;
+ yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]);
+ /* Variants are always initialized to an empty instance of the
+ correct type. The default '$$ = $1' action is NOT applied
+ when using variants. */
+ switch (yyr1_[yyn])
+ {
+ case 62: // value
+ case 89: // ncr_protocol_value
+ yylhs.value.build< ElementPtr > ();
+ break;
+
+ case 50: // "boolean"
+ yylhs.value.build< bool > ();
+ break;
+
+ case 49: // "floating point"
+ yylhs.value.build< double > ();
+ break;
+
+ case 48: // "integer"
+ yylhs.value.build< int64_t > ();
+ break;
+
+ case 47: // "constant string"
+ yylhs.value.build< std::string > ();
+ break;
+
+ default:
+ break;
+ }
+
+
+ // Compute the default @$.
+ {
+ slice<stack_symbol_type, stack_type> slice (yystack_, yylen);
+ YYLLOC_DEFAULT (yylhs.location, slice, yylen);
+ }
+
+ // Perform the reduction.
+ YY_REDUCE_PRINT (yyn);
+ try
+ {
+ switch (yyn)
+ {
+ case 2:
+#line 113 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.NO_KEYWORD; }
+#line 630 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 4:
+#line 114 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.CONFIG; }
+#line 636 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 6:
+#line 115 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.DHCPDDNS; }
+#line 642 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 8:
+#line 116 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.TSIG_KEY; }
+#line 648 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 10:
+#line 117 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.TSIG_KEYS; }
+#line 654 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 12:
+#line 118 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.DDNS_DOMAIN; }
+#line 660 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 14:
+#line 119 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.DDNS_DOMAINS; }
+#line 666 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 16:
+#line 120 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.DNS_SERVERS; }
+#line 672 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 18:
+#line 121 "d2_parser.yy" // lalr1.cc:859
+ { ctx.ctx_ = ctx.DNS_SERVERS; }
+#line 678 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 20:
+#line 129 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ElementPtr(new IntElement(yystack_[0].value.as< int64_t > (), ctx.loc2pos(yystack_[0].location))); }
+#line 684 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 21:
+#line 130 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ElementPtr(new DoubleElement(yystack_[0].value.as< double > (), ctx.loc2pos(yystack_[0].location))); }
+#line 690 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 22:
+#line 131 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ElementPtr(new BoolElement(yystack_[0].value.as< bool > (), ctx.loc2pos(yystack_[0].location))); }
+#line 696 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 23:
+#line 132 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ElementPtr(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location))); }
+#line 702 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 24:
+#line 133 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ElementPtr(new NullElement(ctx.loc2pos(yystack_[0].location))); }
+#line 708 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 25:
+#line 134 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ctx.stack_.back(); ctx.stack_.pop_back(); }
+#line 714 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 26:
+#line 135 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ctx.stack_.back(); ctx.stack_.pop_back(); }
+#line 720 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 27:
+#line 138 "d2_parser.yy" // lalr1.cc:859
+ {
+ // Push back the JSON value on the stack
+ ctx.stack_.push_back(yystack_[0].value.as< ElementPtr > ());
+}
+#line 729 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 28:
+#line 143 "d2_parser.yy" // lalr1.cc:859
+ {
+ // This code is executed when we're about to start parsing
+ // the content of the map
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(m);
+}
+#line 740 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 29:
+#line 148 "d2_parser.yy" // lalr1.cc:859
+ {
+ // map parsing completed. If we ever want to do any wrap up
+ // (maybe some sanity checking), this would be the best place
+ // for it.
+}
+#line 750 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 32:
+#line 159 "d2_parser.yy" // lalr1.cc:859
+ {
+ // map containing a single entry
+ ctx.stack_.back()->set(yystack_[2].value.as< std::string > (), yystack_[0].value.as< ElementPtr > ());
+ }
+#line 759 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 33:
+#line 163 "d2_parser.yy" // lalr1.cc:859
+ {
+ // map consisting of a shorter map followed by
+ // comma and string:value
+ ctx.stack_.back()->set(yystack_[2].value.as< std::string > (), yystack_[0].value.as< ElementPtr > ());
+ }
+#line 769 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 34:
+#line 170 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(l);
+}
+#line 778 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 35:
+#line 173 "d2_parser.yy" // lalr1.cc:859
+ {
+ // list parsing complete. Put any sanity checking here
+}
+#line 786 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 38:
+#line 181 "d2_parser.yy" // lalr1.cc:859
+ {
+ // List consisting of a single element.
+ ctx.stack_.back()->add(yystack_[0].value.as< ElementPtr > ());
+ }
+#line 795 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 39:
+#line 185 "d2_parser.yy" // lalr1.cc:859
+ {
+ // List ending with , and a value.
+ ctx.stack_.back()->add(yystack_[0].value.as< ElementPtr > ());
+ }
+#line 804 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 40:
+#line 196 "d2_parser.yy" // lalr1.cc:859
+ {
+ const std::string& where = ctx.contextName();
+ const std::string& keyword = yystack_[1].value.as< std::string > ();
+ error(yystack_[1].location,
+ "got unexpected keyword \"" + keyword + "\" in " + where + " map.");
+}
+#line 815 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 41:
+#line 206 "d2_parser.yy" // lalr1.cc:859
+ {
+ // This code is executed when we're about to start parsing
+ // the content of the map
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(m);
+}
+#line 826 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 42:
+#line 211 "d2_parser.yy" // lalr1.cc:859
+ {
+ // map parsing completed. If we ever want to do any wrap up
+ // (maybe some sanity checking), this would be the best place
+ // for it.
+}
+#line 836 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 50:
+#line 232 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("DhcpDdns", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.DHCPDDNS);
+}
+#line 847 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 51:
+#line 237 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 856 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 52:
+#line 242 "d2_parser.yy" // lalr1.cc:859
+ {
+ // Parse the dhcpddns map
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(m);
+}
+#line 866 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 53:
+#line 246 "d2_parser.yy" // lalr1.cc:859
+ {
+ // parsing completed
+}
+#line 874 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 65:
+#line 266 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 882 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 66:
+#line 268 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr s(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("ip-address", s);
+ ctx.leave();
+}
+#line 892 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 67:
+#line 274 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< int64_t > () <= 0 || yystack_[0].value.as< int64_t > () >= 65536 ) {
+ error(yystack_[0].location, "port must be greater than zero but less than 65536");
+ }
+ ElementPtr i(new IntElement(yystack_[0].value.as< int64_t > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("port", i);
+}
+#line 904 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 68:
+#line 282 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< int64_t > () <= 0) {
+ error(yystack_[0].location, "dns-server-timeout must be greater than zero");
+ } else {
+ ElementPtr i(new IntElement(yystack_[0].value.as< int64_t > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("dns-server-timeout", i);
+ }
+}
+#line 917 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 69:
+#line 291 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NCR_PROTOCOL);
+}
+#line 925 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 70:
+#line 293 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.back()->set("ncr-protocol", yystack_[0].value.as< ElementPtr > ());
+ ctx.leave();
+}
+#line 934 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 71:
+#line 299 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ElementPtr(new StringElement("UDP", ctx.loc2pos(yystack_[0].location))); }
+#line 940 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 72:
+#line 300 "d2_parser.yy" // lalr1.cc:859
+ { yylhs.value.as< ElementPtr > () = ElementPtr(new StringElement("TCP", ctx.loc2pos(yystack_[0].location))); }
+#line 946 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 73:
+#line 303 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NCR_FORMAT);
+}
+#line 954 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 74:
+#line 305 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr json(new StringElement("JSON", ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("ncr-format", json);
+ ctx.leave();
+}
+#line 964 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 75:
+#line 311 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("forward-ddns", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.FORWARD_DDNS);
+}
+#line 975 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 76:
+#line 316 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 984 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 77:
+#line 321 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("reverse-ddns", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.REVERSE_DDNS);
+}
+#line 995 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 78:
+#line 326 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 1004 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 85:
+#line 345 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("ddns-domains", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.DDNS_DOMAINS);
+}
+#line 1015 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 86:
+#line 350 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 1024 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 87:
+#line 355 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(l);
+}
+#line 1033 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 88:
+#line 358 "d2_parser.yy" // lalr1.cc:859
+ {
+ // parsing completed
+}
+#line 1041 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 93:
+#line 370 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+}
+#line 1051 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 94:
+#line 374 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+}
+#line 1059 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 95:
+#line 378 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(m);
+}
+#line 1068 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 96:
+#line 381 "d2_parser.yy" // lalr1.cc:859
+ {
+ // parsing completed
+}
+#line 1076 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 103:
+#line 396 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1084 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 104:
+#line 398 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< std::string > () == "") {
+ error(yystack_[1].location, "Ddns domain name cannot be blank");
+ }
+ ElementPtr elem(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ElementPtr name(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("name", name);
+ ctx.leave();
+}
+#line 1098 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 105:
+#line 408 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1106 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 106:
+#line 410 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr elem(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ElementPtr name(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("key-name", name);
+ ctx.leave();
+}
+#line 1117 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 107:
+#line 420 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("dns-servers", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.DNS_SERVERS);
+}
+#line 1128 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 108:
+#line 425 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 1137 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 109:
+#line 430 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(l);
+}
+#line 1146 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 110:
+#line 433 "d2_parser.yy" // lalr1.cc:859
+ {
+ // parsing completed
+}
+#line 1154 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 113:
+#line 441 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+}
+#line 1164 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 114:
+#line 445 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+}
+#line 1172 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 115:
+#line 449 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(m);
+}
+#line 1181 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 116:
+#line 452 "d2_parser.yy" // lalr1.cc:859
+ {
+ // parsing completed
+}
+#line 1189 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 123:
+#line 466 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1197 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 124:
+#line 468 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< std::string > () != "") {
+ error(yystack_[1].location, "hostname is not yet supported");
+ }
+ ElementPtr elem(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ElementPtr name(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("hostname", name);
+ ctx.leave();
+}
+#line 1211 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 125:
+#line 478 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1219 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 126:
+#line 480 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr s(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("ip-address", s);
+ ctx.leave();
+}
+#line 1229 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 127:
+#line 486 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< int64_t > () <= 0 || yystack_[0].value.as< int64_t > () >= 65536 ) {
+ error(yystack_[0].location, "port must be greater than zero but less than 65536");
+ }
+ ElementPtr i(new IntElement(yystack_[0].value.as< int64_t > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("port", i);
+}
+#line 1241 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 128:
+#line 500 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("tsig-keys", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.TSIG_KEYS);
+}
+#line 1252 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 129:
+#line 505 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 1261 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 130:
+#line 510 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(l);
+}
+#line 1270 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 131:
+#line 513 "d2_parser.yy" // lalr1.cc:859
+ {
+ // parsing completed
+}
+#line 1278 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 136:
+#line 525 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+}
+#line 1288 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 137:
+#line 529 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+}
+#line 1296 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 138:
+#line 533 "d2_parser.yy" // lalr1.cc:859
+ {
+ // Parse tsig key list entry map
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.push_back(m);
+}
+#line 1306 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 139:
+#line 537 "d2_parser.yy" // lalr1.cc:859
+ {
+ // parsing completed
+}
+#line 1314 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 147:
+#line 553 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1322 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 148:
+#line 555 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< std::string > () == "") {
+ error(yystack_[1].location, "TSIG key name cannot be blank");
+ }
+ ElementPtr elem(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ElementPtr name(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("name", name);
+ ctx.leave();
+}
+#line 1336 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 149:
+#line 565 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1344 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 150:
+#line 567 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< std::string > () == "") {
+ error(yystack_[1].location, "TSIG key algorithm cannot be blank");
+ }
+ ElementPtr elem(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("algorithm", elem);
+ ctx.leave();
+}
+#line 1357 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 151:
+#line 576 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< int64_t > () < 0 || (yystack_[0].value.as< int64_t > () > 0 && (yystack_[0].value.as< int64_t > () % 8 != 0))) {
+ error(yystack_[0].location, "TSIG key digest-bits must either be zero or a positive, multiple of eight");
+ }
+ ElementPtr elem(new IntElement(yystack_[0].value.as< int64_t > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("digest-bits", elem);
+}
+#line 1369 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 152:
+#line 584 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1377 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 153:
+#line 586 "d2_parser.yy" // lalr1.cc:859
+ {
+ if (yystack_[0].value.as< std::string > () == "") {
+ error(yystack_[1].location, "TSIG key secret cannot be blank");
+ }
+ ElementPtr elem(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("secret", elem);
+ ctx.leave();
+}
+#line 1390 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 154:
+#line 599 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1398 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 155:
+#line 601 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.back()->set("Dhcp6", yystack_[0].value.as< ElementPtr > ());
+ ctx.leave();
+}
+#line 1407 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 156:
+#line 606 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1415 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 157:
+#line 608 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.back()->set("Dhcp4", yystack_[0].value.as< ElementPtr > ());
+ ctx.leave();
+}
+#line 1424 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 158:
+#line 618 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("Logging", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.LOGGING);
+}
+#line 1435 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 159:
+#line 623 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 1444 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 163:
+#line 640 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("loggers", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.LOGGERS);
+}
+#line 1455 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 164:
+#line 645 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 1464 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 167:
+#line 657 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->add(l);
+ ctx.stack_.push_back(l);
+}
+#line 1474 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 168:
+#line 661 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+}
+#line 1482 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 176:
+#line 676 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1490 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 177:
+#line 678 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr name(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("name", name);
+ ctx.leave();
+}
+#line 1500 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 178:
+#line 684 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr dl(new IntElement(yystack_[0].value.as< int64_t > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("debuglevel", dl);
+}
+#line 1509 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 179:
+#line 688 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1517 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 180:
+#line 690 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr sev(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("severity", sev);
+ ctx.leave();
+}
+#line 1527 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 181:
+#line 696 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr l(new ListElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("output_options", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.OUTPUT_OPTIONS);
+}
+#line 1538 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 182:
+#line 701 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+ ctx.leave();
+}
+#line 1547 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 185:
+#line 710 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr m(new MapElement(ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+}
+#line 1557 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 186:
+#line 714 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.stack_.pop_back();
+}
+#line 1565 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 189:
+#line 722 "d2_parser.yy" // lalr1.cc:859
+ {
+ ctx.enter(ctx.NO_KEYWORD);
+}
+#line 1573 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+ case 190:
+#line 724 "d2_parser.yy" // lalr1.cc:859
+ {
+ ElementPtr sev(new StringElement(yystack_[0].value.as< std::string > (), ctx.loc2pos(yystack_[0].location)));
+ ctx.stack_.back()->set("output", sev);
+ ctx.leave();
+}
+#line 1583 "d2_parser.cc" // lalr1.cc:859
+ break;
+
+
+#line 1587 "d2_parser.cc" // lalr1.cc:859
+ default:
+ break;
+ }
+ }
+ catch (const syntax_error& yyexc)
+ {
+ error (yyexc);
+ YYERROR;
+ }
+ YY_SYMBOL_PRINT ("-> $$ =", yylhs);
+ yypop_ (yylen);
+ yylen = 0;
+ YY_STACK_PRINT ();
+
+ // Shift the result of the reduction.
+ yypush_ (YY_NULLPTR, yylhs);
+ }
+ goto yynewstate;
+
+ /*--------------------------------------.
+ | yyerrlab -- here on detecting error. |
+ `--------------------------------------*/
+ yyerrlab:
+ // If not already recovering from an error, report this error.
+ if (!yyerrstatus_)
+ {
+ ++yynerrs_;
+ error (yyla.location, yysyntax_error_ (yystack_[0].state, yyla));
+ }
+
+
+ yyerror_range[1].location = yyla.location;
+ if (yyerrstatus_ == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ // Return failure if at end of input.
+ if (yyla.type_get () == yyeof_)
+ YYABORT;
+ else if (!yyla.empty ())
+ {
+ yy_destroy_ ("Error: discarding", yyla);
+ yyla.clear ();
+ }
+ }
+
+ // Else will try to reuse lookahead token after shifting the error token.
+ goto yyerrlab1;
+
+
+ /*---------------------------------------------------.
+ | yyerrorlab -- error raised explicitly by YYERROR. |
+ `---------------------------------------------------*/
+ yyerrorlab:
+
+ /* Pacify compilers like GCC when the user code never invokes
+ YYERROR and the label yyerrorlab therefore never appears in user
+ code. */
+ if (false)
+ goto yyerrorlab;
+ yyerror_range[1].location = yystack_[yylen - 1].location;
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYERROR. */
+ yypop_ (yylen);
+ yylen = 0;
+ goto yyerrlab1;
+
+ /*-------------------------------------------------------------.
+ | yyerrlab1 -- common code for both syntax error and YYERROR. |
+ `-------------------------------------------------------------*/
+ yyerrlab1:
+ yyerrstatus_ = 3; // Each real token shifted decrements this.
+ {
+ stack_symbol_type error_token;
+ for (;;)
+ {
+ yyn = yypact_[yystack_[0].state];
+ if (!yy_pact_value_is_default_ (yyn))
+ {
+ yyn += yyterror_;
+ if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
+ {
+ yyn = yytable_[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ // Pop the current state because it cannot handle the error token.
+ if (yystack_.size () == 1)
+ YYABORT;
+
+ yyerror_range[1].location = yystack_[0].location;
+ yy_destroy_ ("Error: popping", yystack_[0]);
+ yypop_ ();
+ YY_STACK_PRINT ();
+ }
+
+ yyerror_range[2].location = yyla.location;
+ YYLLOC_DEFAULT (error_token.location, yyerror_range, 2);
+
+ // Shift the error token.
+ error_token.state = yyn;
+ yypush_ ("Shifting", error_token);
+ }
+ goto yynewstate;
+
+ // Accept.
+ yyacceptlab:
+ yyresult = 0;
+ goto yyreturn;
+
+ // Abort.
+ yyabortlab:
+ yyresult = 1;
+ goto yyreturn;
+
+ yyreturn:
+ if (!yyla.empty ())
+ yy_destroy_ ("Cleanup: discarding lookahead", yyla);
+
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYABORT or YYACCEPT. */
+ yypop_ (yylen);
+ while (1 < yystack_.size ())
+ {
+ yy_destroy_ ("Cleanup: popping", yystack_[0]);
+ yypop_ ();
+ }
+
+ return yyresult;
+ }
+ catch (...)
+ {
+ YYCDEBUG << "Exception caught: cleaning lookahead and stack"
+ << std::endl;
+ // Do not try to display the values of the reclaimed symbols,
+ // as their printer might throw an exception.
+ if (!yyla.empty ())
+ yy_destroy_ (YY_NULLPTR, yyla);
+
+ while (1 < yystack_.size ())
+ {
+ yy_destroy_ (YY_NULLPTR, yystack_[0]);
+ yypop_ ();
+ }
+ throw;
+ }
+ }
+
+ void
+ D2Parser::error (const syntax_error& yyexc)
+ {
+ error (yyexc.location, yyexc.what());
+ }
+
+ // Generate an error message.
+ std::string
+ D2Parser::yysyntax_error_ (state_type yystate, const symbol_type& yyla) const
+ {
+ // Number of reported tokens (one for the "unexpected", one per
+ // "expected").
+ size_t yycount = 0;
+ // Its maximum.
+ enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
+ // Arguments of yyformat.
+ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
+
+ /* There are many possibilities here to consider:
+ - If this state is a consistent state with a default action, then
+ the only way this function was invoked is if the default action
+ is an error action. In that case, don't check for expected
+ tokens because there are none.
+ - The only way there can be no lookahead present (in yyla) is
+ if this state is a consistent state with a default action.
+ Thus, detecting the absence of a lookahead is sufficient to
+ determine that there is no unexpected or expected token to
+ report. In that case, just report a simple "syntax error".
+ - Don't assume there isn't a lookahead just because this state is
+ a consistent state with a default action. There might have
+ been a previous inconsistent state, consistent state with a
+ non-default action, or user semantic action that manipulated
+ yyla. (However, yyla is currently not documented for users.)
+ - Of course, the expected token list depends on states to have
+ correct lookahead information, and it depends on the parser not
+ to perform extra reductions after fetching a lookahead from the
+ scanner and before detecting a syntax error. Thus, state
+ merging (from LALR or IELR) and default reductions corrupt the
+ expected token list. However, the list is correct for
+ canonical LR with one exception: it will still contain any
+ token that will not be accepted due to an error action in a
+ later state.
+ */
+ if (!yyla.empty ())
+ {
+ int yytoken = yyla.type_get ();
+ yyarg[yycount++] = yytname_[yytoken];
+ int yyn = yypact_[yystate];
+ if (!yy_pact_value_is_default_ (yyn))
+ {
+ /* Start YYX at -YYN if negative to avoid negative indexes in
+ YYCHECK. In other words, skip the first -YYN actions for
+ this state because they are default actions. */
+ int yyxbegin = yyn < 0 ? -yyn : 0;
+ // Stay within bounds of both yycheck and yytname.
+ int yychecklim = yylast_ - yyn + 1;
+ int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
+ for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
+ if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
+ && !yy_table_value_is_error_ (yytable_[yyx + yyn]))
+ {
+ if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
+ {
+ yycount = 1;
+ break;
+ }
+ else
+ yyarg[yycount++] = yytname_[yyx];
+ }
+ }
+ }
+
+ char const* yyformat = YY_NULLPTR;
+ switch (yycount)
+ {
+#define YYCASE_(N, S) \
+ case N: \
+ yyformat = S; \
+ break
+ YYCASE_(0, YY_("syntax error"));
+ YYCASE_(1, YY_("syntax error, unexpected %s"));
+ YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
+ YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
+ YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
+ YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
+#undef YYCASE_
+ }
+
+ std::string yyres;
+ // Argument number.
+ size_t yyi = 0;
+ for (char const* yyp = yyformat; *yyp; ++yyp)
+ if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
+ {
+ yyres += yytnamerr_ (yyarg[yyi++]);
+ ++yyp;
+ }
+ else
+ yyres += *yyp;
+ return yyres;
+ }
+
+
+ const signed char D2Parser::yypact_ninf_ = -104;
+
+ const signed char D2Parser::yytable_ninf_ = -1;
+
+ const short int
+ D2Parser::yypact_[] =
+ {
+ 29, -104, -104, -104, -104, -104, -104, -104, -104, -104,
+ 11, -2, 16, 28, 37, 97, 81, 98, 99, 100,
+ -104, -104, -104, -104, -104, -104, -104, -104, -104, -104,
+ -104, -104, -104, -104, -104, -104, -104, -104, -104, -104,
+ -104, -104, -104, -104, -104, -104, -104, -104, -2, 15,
+ 2, 3, 10, 101, 4, 102, -5, 103, -104, 106,
+ 104, 110, 96, 112, -104, -104, -104, -104, 113, -104,
+ 12, -104, -104, -104, -104, -104, -104, 114, 116, -104,
+ -104, -104, -104, -104, -104, 23, -104, -104, -104, -104,
+ -104, -104, -104, -104, -104, -104, 118, -104, -104, -104,
+ 24, -104, -104, -104, -104, -104, -104, 117, 121, -104,
+ -104, -104, -104, -104, 33, -104, -104, -104, -104, -104,
+ 119, 123, -104, -104, 124, -104, -104, 51, -104, -104,
+ -104, -104, -104, 58, -104, -104, -2, -2, -104, 69,
+ 126, 127, 128, 129, -104, 2, -104, 130, 87, 88,
+ 133, 136, 137, 138, 139, 3, -104, 140, 105, 141,
+ 142, 10, -104, 10, -104, 101, 143, 144, 145, 4,
+ -104, 4, -104, 102, 146, 107, 147, -5, -104, -5,
+ 103, -104, -104, -104, 148, -2, -2, 149, 150, -104,
+ 111, -104, -104, 82, 134, 152, 153, 156, -104, 115,
+ -104, 120, 122, -104, 55, -104, 125, 158, 135, -104,
+ 57, -104, 151, -104, 154, -104, 73, -104, -2, -104,
+ -104, 3, 132, -104, -104, -104, -104, -104, -13, -13,
+ 101, -104, -104, -104, -104, -104, 103, -104, -104, -104,
+ -104, -104, -104, 74, -104, 75, -104, -104, -104, -104,
+ 76, -104, -104, -104, 77, 159, 90, -104, 162, 132,
+ -104, 164, -13, -104, -104, -104, -104, 165, -104, 168,
+ -104, 167, 102, -104, 91, -104, 169, 19, 167, -104,
+ -104, -104, -104, 172, -104, -104, 83, -104, -104, -104,
+ -104, -104, -104, 173, 176, 155, 177, 19, -104, 157,
+ 178, -104, 160, -104, -104, 179, -104, -104, 95, -104,
+ 161, 179, -104, -104, 84, -104, -104, 180, 161, -104,
+ 163, -104, -104
+ };
+
+ const unsigned char
+ D2Parser::yydefact_[] =
+ {
+ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 34, 28, 24, 23, 20, 21, 22, 27, 3,
+ 25, 26, 41, 5, 52, 7, 138, 9, 130, 11,
+ 95, 13, 87, 15, 115, 17, 109, 19, 36, 30,
+ 0, 0, 0, 132, 0, 89, 0, 0, 38, 0,
+ 37, 0, 0, 31, 154, 156, 50, 158, 0, 49,
+ 0, 43, 48, 45, 47, 46, 65, 0, 0, 69,
+ 73, 75, 77, 128, 64, 0, 54, 56, 57, 58,
+ 59, 60, 61, 62, 63, 149, 0, 152, 147, 146,
+ 0, 140, 142, 143, 144, 145, 136, 0, 133, 134,
+ 105, 107, 103, 102, 0, 97, 99, 100, 101, 93,
+ 0, 90, 91, 125, 0, 123, 122, 0, 117, 119,
+ 120, 121, 113, 0, 111, 35, 0, 0, 29, 0,
+ 0, 0, 0, 0, 40, 0, 42, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 53, 0, 0, 0,
+ 0, 0, 139, 0, 131, 0, 0, 0, 0, 0,
+ 96, 0, 88, 0, 0, 0, 0, 0, 116, 0,
+ 0, 110, 39, 32, 0, 0, 0, 0, 0, 44,
+ 0, 67, 68, 0, 0, 0, 0, 0, 55, 0,
+ 151, 0, 0, 141, 0, 135, 0, 0, 0, 98,
+ 0, 92, 0, 127, 0, 118, 0, 112, 0, 155,
+ 157, 0, 0, 66, 71, 72, 70, 74, 79, 79,
+ 132, 150, 153, 148, 137, 106, 0, 104, 94, 126,
+ 124, 114, 33, 0, 163, 0, 160, 162, 85, 84,
+ 0, 80, 81, 83, 0, 0, 0, 51, 0, 0,
+ 159, 0, 0, 76, 78, 129, 108, 0, 161, 0,
+ 82, 0, 89, 167, 0, 165, 0, 0, 0, 164,
+ 86, 176, 181, 0, 179, 175, 0, 169, 171, 173,
+ 174, 172, 166, 0, 0, 0, 0, 0, 168, 0,
+ 0, 178, 0, 170, 177, 0, 180, 185, 0, 183,
+ 0, 0, 182, 189, 0, 187, 184, 0, 0, 186,
+ 0, 188, 190
+ };
+
+ const signed char
+ D2Parser::yypgoto_[] =
+ {
+ -104, -104, -104, -104, -104, -104, -104, -104, -104, -104,
+ -104, -47, -104, -104, -104, -104, -104, -104, -104, -104,
+ -104, -50, -104, -104, -104, 40, -104, -104, -104, -104,
+ -34, 34, -104, -104, -104, -104, -104, -104, -104, -104,
+ -104, -104, -104, -104, -104, -41, -104, -72, -104, -104,
+ -104, -104, -81, -104, 20, -104, -104, -104, 21, 25,
+ -104, -104, -104, -104, -104, -104, -104, -104, -39, 22,
+ -104, -104, -104, 26, 18, -104, -104, -104, -104, -104,
+ -104, -104, -104, -104, -31, -104, 35, -104, -104, -104,
+ 43, 47, -104, -104, -104, -104, -104, -104, -104, -104,
+ -104, -104, -104, -104, -104, -104, -48, -104, -104, -104,
+ -69, -104, -104, -84, -104, -104, -104, -104, -104, -104,
+ -104, -104, -97, -104, -104, -103, -104
+ };
+
+ const short int
+ D2Parser::yydefgoto_[] =
+ {
+ -1, 10, 11, 12, 13, 14, 15, 16, 17, 18,
+ 19, 28, 29, 30, 49, 62, 63, 31, 48, 59,
+ 60, 84, 33, 50, 70, 71, 72, 142, 35, 51,
+ 85, 86, 87, 147, 88, 89, 90, 150, 226, 91,
+ 151, 92, 152, 93, 153, 250, 251, 252, 253, 261,
+ 43, 55, 120, 121, 122, 171, 41, 54, 114, 115,
+ 116, 168, 117, 166, 118, 167, 47, 57, 133, 134,
+ 179, 45, 56, 127, 128, 129, 176, 130, 174, 131,
+ 94, 154, 39, 53, 107, 108, 109, 163, 37, 52,
+ 100, 101, 102, 160, 103, 157, 104, 105, 159, 73,
+ 140, 74, 141, 75, 143, 245, 246, 247, 258, 274,
+ 275, 277, 286, 287, 288, 293, 289, 290, 296, 291,
+ 294, 308, 309, 310, 314, 315, 317
+ };
+
+ const unsigned short int
+ D2Parser::yytable_[] =
+ {
+ 69, 58, 99, 21, 113, 22, 126, 23, 123, 124,
+ 248, 20, 64, 65, 66, 145, 76, 77, 78, 79,
+ 146, 125, 80, 32, 81, 82, 155, 161, 110, 111,
+ 83, 156, 162, 67, 68, 34, 169, 112, 95, 96,
+ 97, 170, 68, 98, 36, 24, 25, 26, 27, 68,
+ 68, 68, 281, 282, 177, 283, 284, 68, 161, 178,
+ 169, 180, 61, 234, 181, 238, 68, 1, 2, 3,
+ 4, 5, 6, 7, 8, 9, 177, 155, 259, 262,
+ 262, 241, 257, 260, 263, 264, 297, 318, 40, 182,
+ 183, 298, 319, 180, 278, 69, 266, 279, 311, 224,
+ 225, 312, 38, 42, 138, 46, 44, 136, 106, 119,
+ 132, 99, 135, 99, 137, 139, 184, 144, 148, 113,
+ 149, 113, 158, 164, 165, 172, 173, 126, 175, 126,
+ 185, 186, 187, 188, 190, 191, 192, 193, 219, 220,
+ 194, 195, 196, 197, 199, 201, 202, 206, 207, 208,
+ 212, 214, 218, 200, 227, 213, 221, 222, 223, 228,
+ 229, 230, 231, 236, 244, 265, 267, 232, 269, 233,
+ 271, 242, 235, 272, 273, 280, 295, 299, 249, 249,
+ 300, 302, 237, 305, 320, 189, 307, 243, 254, 198,
+ 270, 276, 210, 211, 209, 215, 313, 256, 239, 255,
+ 205, 240, 217, 301, 304, 216, 204, 306, 203, 292,
+ 322, 268, 249, 303, 316, 321, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 285, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 285
+ };
+
+ const short int
+ D2Parser::yycheck_[] =
+ {
+ 50, 48, 52, 5, 54, 7, 56, 9, 13, 14,
+ 23, 0, 10, 11, 12, 3, 13, 14, 15, 16,
+ 8, 26, 19, 7, 21, 22, 3, 3, 24, 25,
+ 27, 8, 8, 31, 47, 7, 3, 33, 28, 29,
+ 30, 8, 47, 33, 7, 47, 48, 49, 50, 47,
+ 47, 47, 33, 34, 3, 36, 37, 47, 3, 8,
+ 3, 3, 47, 8, 6, 8, 47, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 3, 3, 3, 3,
+ 3, 8, 8, 8, 8, 8, 3, 3, 7, 136,
+ 137, 8, 8, 3, 3, 145, 6, 6, 3, 17,
+ 18, 6, 5, 5, 8, 5, 7, 3, 7, 7,
+ 7, 161, 6, 163, 4, 3, 47, 4, 4, 169,
+ 4, 171, 4, 6, 3, 6, 3, 177, 4, 179,
+ 4, 4, 4, 4, 4, 48, 48, 4, 185, 186,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 4, 4, 4, 48, 20, 48, 7, 7, 47, 7,
+ 7, 5, 47, 5, 32, 6, 4, 47, 4, 47,
+ 5, 218, 47, 5, 7, 6, 4, 4, 228, 229,
+ 4, 4, 47, 5, 4, 145, 7, 221, 229, 155,
+ 262, 272, 171, 173, 169, 177, 35, 236, 47, 230,
+ 165, 47, 180, 48, 47, 179, 163, 47, 161, 278,
+ 47, 259, 262, 297, 311, 318, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 277, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, 297
+ };
+
+ const unsigned char
+ D2Parser::yystos_[] =
+ {
+ 0, 38, 39, 40, 41, 42, 43, 44, 45, 46,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
+ 0, 5, 7, 9, 47, 48, 49, 50, 62, 63,
+ 64, 68, 7, 73, 7, 79, 7, 139, 5, 133,
+ 7, 107, 5, 101, 7, 122, 5, 117, 69, 65,
+ 74, 80, 140, 134, 108, 102, 123, 118, 62, 70,
+ 71, 47, 66, 67, 10, 11, 12, 31, 47, 72,
+ 75, 76, 77, 150, 152, 154, 13, 14, 15, 16,
+ 19, 21, 22, 27, 72, 81, 82, 83, 85, 86,
+ 87, 90, 92, 94, 131, 28, 29, 30, 33, 72,
+ 141, 142, 143, 145, 147, 148, 7, 135, 136, 137,
+ 24, 25, 33, 72, 109, 110, 111, 113, 115, 7,
+ 103, 104, 105, 13, 14, 26, 72, 124, 125, 126,
+ 128, 130, 7, 119, 120, 6, 3, 4, 8, 3,
+ 151, 153, 78, 155, 4, 3, 8, 84, 4, 4,
+ 88, 91, 93, 95, 132, 3, 8, 146, 4, 149,
+ 144, 3, 8, 138, 6, 3, 114, 116, 112, 3,
+ 8, 106, 6, 3, 129, 4, 127, 3, 8, 121,
+ 3, 6, 62, 62, 47, 4, 4, 4, 4, 76,
+ 4, 48, 48, 4, 4, 4, 4, 4, 82, 4,
+ 48, 4, 4, 142, 141, 137, 4, 4, 4, 110,
+ 109, 105, 4, 48, 4, 125, 124, 120, 4, 62,
+ 62, 7, 7, 47, 17, 18, 89, 20, 7, 7,
+ 5, 47, 47, 47, 8, 47, 5, 47, 8, 47,
+ 47, 8, 62, 81, 32, 156, 157, 158, 23, 72,
+ 96, 97, 98, 99, 96, 135, 119, 8, 159, 3,
+ 8, 100, 3, 8, 8, 6, 6, 4, 157, 4,
+ 98, 5, 5, 7, 160, 161, 103, 162, 3, 6,
+ 6, 33, 34, 36, 37, 72, 163, 164, 165, 167,
+ 168, 170, 161, 166, 171, 4, 169, 3, 8, 4,
+ 4, 48, 4, 164, 47, 5, 47, 7, 172, 173,
+ 174, 3, 6, 35, 175, 176, 173, 177, 3, 8,
+ 4, 176, 47
+ };
+
+ const unsigned char
+ D2Parser::yyr1_[] =
+ {
+ 0, 51, 53, 52, 54, 52, 55, 52, 56, 52,
+ 57, 52, 58, 52, 59, 52, 60, 52, 61, 52,
+ 62, 62, 62, 62, 62, 62, 62, 63, 65, 64,
+ 66, 66, 67, 67, 69, 68, 70, 70, 71, 71,
+ 72, 74, 73, 75, 75, 76, 76, 76, 76, 76,
+ 78, 77, 80, 79, 81, 81, 82, 82, 82, 82,
+ 82, 82, 82, 82, 82, 84, 83, 85, 86, 88,
+ 87, 89, 89, 91, 90, 93, 92, 95, 94, 96,
+ 96, 97, 97, 98, 98, 100, 99, 102, 101, 103,
+ 103, 104, 104, 106, 105, 108, 107, 109, 109, 110,
+ 110, 110, 110, 112, 111, 114, 113, 116, 115, 118,
+ 117, 119, 119, 121, 120, 123, 122, 124, 124, 125,
+ 125, 125, 125, 127, 126, 129, 128, 130, 132, 131,
+ 134, 133, 135, 135, 136, 136, 138, 137, 140, 139,
+ 141, 141, 142, 142, 142, 142, 142, 144, 143, 146,
+ 145, 147, 149, 148, 151, 150, 153, 152, 155, 154,
+ 156, 156, 157, 159, 158, 160, 160, 162, 161, 163,
+ 163, 164, 164, 164, 164, 164, 166, 165, 167, 169,
+ 168, 171, 170, 172, 172, 174, 173, 175, 175, 177,
+ 176
+ };
+
+ const unsigned char
+ D2Parser::yyr2_[] =
+ {
+ 0, 2, 0, 3, 0, 3, 0, 3, 0, 3,
+ 0, 3, 0, 3, 0, 3, 0, 3, 0, 3,
+ 1, 1, 1, 1, 1, 1, 1, 1, 0, 4,
+ 0, 1, 3, 5, 0, 4, 0, 1, 1, 3,
+ 2, 0, 4, 1, 3, 1, 1, 1, 1, 1,
+ 0, 6, 0, 4, 1, 3, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 0, 4, 3, 3, 0,
+ 4, 1, 1, 0, 4, 0, 6, 0, 6, 0,
+ 1, 1, 3, 1, 1, 0, 6, 0, 4, 0,
+ 1, 1, 3, 0, 4, 0, 4, 1, 3, 1,
+ 1, 1, 1, 0, 4, 0, 4, 0, 6, 0,
+ 4, 1, 3, 0, 4, 0, 4, 1, 3, 1,
+ 1, 1, 1, 0, 4, 0, 4, 3, 0, 6,
+ 0, 4, 0, 1, 1, 3, 0, 4, 0, 4,
+ 1, 3, 1, 1, 1, 1, 1, 0, 4, 0,
+ 4, 3, 0, 4, 0, 4, 0, 4, 0, 6,
+ 1, 3, 1, 0, 6, 1, 3, 0, 4, 1,
+ 3, 1, 1, 1, 1, 1, 0, 4, 3, 0,
+ 4, 0, 6, 1, 3, 0, 4, 1, 3, 0,
+ 4
+ };
+
+
+
+ // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ // First, the terminals, then, starting at \a yyntokens_, nonterminals.
+ const char*
+ const D2Parser::yytname_[] =
+ {
+ "\"end of file\"", "error", "$undefined", "\",\"", "\":\"", "\"[\"",
+ "\"]\"", "\"{\"", "\"}\"", "\"null\"", "\"Dhcp6\"", "\"Dhcp4\"",
+ "\"DhcpDdns\"", "\"ip-address\"", "\"port\"", "\"dns-server-timeout\"",
+ "\"ncr-protocol\"", "\"UDP\"", "\"TCP\"", "\"ncr-format\"", "\"JSON\"",
+ "\"forward-ddns\"", "\"reverse-ddns\"", "\"ddns-domains\"",
+ "\"key-name\"", "\"dns-servers\"", "\"hostname\"", "\"tsig-keys\"",
+ "\"algorithm\"", "\"digest-bits\"", "\"secret\"", "\"Logging\"",
+ "\"loggers\"", "\"name\"", "\"output_options\"", "\"output\"",
+ "\"debuglevel\"", "\"severity\"", "TOPLEVEL_JSON", "TOPLEVEL_DHCPDDNS",
+ "SUB_DHCPDDNS", "SUB_TSIG_KEY", "SUB_TSIG_KEYS", "SUB_DDNS_DOMAIN",
+ "SUB_DDNS_DOMAINS", "SUB_DNS_SERVER", "SUB_DNS_SERVERS",
+ "\"constant string\"", "\"integer\"", "\"floating point\"",
+ "\"boolean\"", "$accept", "start", "$@1", "$@2", "$@3", "$@4", "$@5",
+ "$@6", "$@7", "$@8", "$@9", "value", "sub_json", "map2", "$@10",
+ "map_content", "not_empty_map", "list_generic", "$@11", "list_content",
+ "not_empty_list", "unknown_map_entry", "syntax_map", "$@12",
+ "global_objects", "global_object", "dhcpddns_object", "$@13",
+ "sub_dhcpddns", "$@14", "dhcpddns_params", "dhcpddns_param",
+ "ip_address", "$@15", "port", "dns_server_timeout", "ncr_protocol",
+ "$@16", "ncr_protocol_value", "ncr_format", "$@17", "forward_ddns",
+ "$@18", "reverse_ddns", "$@19", "ddns_mgr_params",
+ "not_empty_ddns_mgr_params", "ddns_mgr_param", "ddns_domains", "$@20",
+ "sub_ddns_domains", "$@21", "ddns_domain_list",
+ "not_empty_ddns_domain_list", "ddns_domain", "$@22", "sub_ddns_domain",
+ "$@23", "ddns_domain_params", "ddns_domain_param", "ddns_domain_name",
+ "$@24", "ddns_domain_key_name", "$@25", "dns_servers", "$@26",
+ "sub_dns_servers", "$@27", "dns_server_list", "dns_server", "$@28",
+ "sub_dns_server", "$@29", "dns_server_params", "dns_server_param",
+ "dns_server_hostname", "$@30", "dns_server_ip_address", "$@31",
+ "dns_server_port", "tsig_keys", "$@32", "sub_tsig_keys", "$@33",
+ "tsig_keys_list", "not_empty_tsig_keys_list", "tsig_key", "$@34",
+ "sub_tsig_key", "$@35", "tsig_key_params", "tsig_key_param",
+ "tsig_key_name", "$@36", "tsig_key_algorithm", "$@37",
+ "tsig_key_digest_bits", "tsig_key_secret", "$@38", "dhcp6_json_object",
+ "$@39", "dhcp4_json_object", "$@40", "logging_object", "$@41",
+ "logging_params", "logging_param", "loggers", "$@42", "loggers_entries",
+ "logger_entry", "$@43", "logger_params", "logger_param", "name", "$@44",
+ "debuglevel", "severity", "$@45", "output_options_list", "$@46",
+ "output_options_list_content", "output_entry", "$@47", "output_params",
+ "output_param", "$@48", YY_NULLPTR
+ };
+
+#if D2_PARSER_DEBUG
+ const unsigned short int
+ D2Parser::yyrline_[] =
+ {
+ 0, 113, 113, 113, 114, 114, 115, 115, 116, 116,
+ 117, 117, 118, 118, 119, 119, 120, 120, 121, 121,
+ 129, 130, 131, 132, 133, 134, 135, 138, 143, 143,
+ 155, 156, 159, 163, 170, 170, 177, 178, 181, 185,
+ 196, 206, 206, 218, 219, 223, 224, 225, 226, 227,
+ 232, 232, 242, 242, 250, 251, 255, 256, 257, 258,
+ 259, 260, 261, 262, 263, 266, 266, 274, 282, 291,
+ 291, 299, 300, 303, 303, 311, 311, 321, 321, 331,
+ 332, 335, 336, 339, 340, 345, 345, 355, 355, 362,
+ 363, 366, 367, 370, 370, 378, 378, 385, 386, 389,
+ 390, 391, 392, 396, 396, 408, 408, 420, 420, 430,
+ 430, 437, 438, 441, 441, 449, 449, 456, 457, 460,
+ 461, 462, 463, 466, 466, 478, 478, 486, 500, 500,
+ 510, 510, 517, 518, 521, 522, 525, 525, 533, 533,
+ 542, 543, 546, 547, 548, 549, 550, 553, 553, 565,
+ 565, 576, 584, 584, 599, 599, 606, 606, 618, 618,
+ 631, 632, 636, 640, 640, 652, 653, 657, 657, 665,
+ 666, 669, 670, 671, 672, 673, 676, 676, 684, 688,
+ 688, 696, 696, 706, 707, 710, 710, 718, 719, 722,
+ 722
+ };
+
+ // Print the state stack on the debug stream.
+ void
+ D2Parser::yystack_print_ ()
+ {
+ *yycdebug_ << "Stack now";
+ for (stack_type::const_iterator
+ i = yystack_.begin (),
+ i_end = yystack_.end ();
+ i != i_end; ++i)
+ *yycdebug_ << ' ' << i->state;
+ *yycdebug_ << std::endl;
+ }
+
+ // Report on the debug stream that the rule \a yyrule is going to be reduced.
+ void
+ D2Parser::yy_reduce_print_ (int yyrule)
+ {
+ unsigned int yylno = yyrline_[yyrule];
+ int yynrhs = yyr2_[yyrule];
+ // Print the symbols being reduced, and their result.
+ *yycdebug_ << "Reducing stack by rule " << yyrule - 1
+ << " (line " << yylno << "):" << std::endl;
+ // The symbols being reduced.
+ for (int yyi = 0; yyi < yynrhs; yyi++)
+ YY_SYMBOL_PRINT (" $" << yyi + 1 << " =",
+ yystack_[(yynrhs) - (yyi + 1)]);
+ }
+#endif // D2_PARSER_DEBUG
+
+
+#line 14 "d2_parser.yy" // lalr1.cc:1167
+} } // isc::d2
+#line 2213 "d2_parser.cc" // lalr1.cc:1167
+#line 730 "d2_parser.yy" // lalr1.cc:1168
+
+
+void
+isc::d2::D2Parser::error(const location_type& loc,
+ const std::string& what)
+{
+ ctx.error(loc, what);
+}
--- /dev/null
+// A Bison parser, made by GNU Bison 3.0.4.
+
+// Skeleton interface for Bison LALR(1) parsers in C++
+
+// Copyright (C) 2002-2015 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton. Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+/**
+ ** \file d2_parser.h
+ ** Define the isc::d2::parser class.
+ */
+
+// C++ LALR(1) parser skeleton written by Akim Demaille.
+
+#ifndef YY_D2_PARSER_D2_PARSER_H_INCLUDED
+# define YY_D2_PARSER_D2_PARSER_H_INCLUDED
+// // "%code requires" blocks.
+#line 17 "d2_parser.yy" // lalr1.cc:377
+
+#include <string>
+#include <cc/data.h>
+#include <d2/d2_config.h>
+#include <boost/lexical_cast.hpp>
+#include <d2/parser_context_decl.h>
+
+using namespace isc::d2;
+using namespace isc::data;
+using namespace std;
+
+#line 56 "d2_parser.h" // lalr1.cc:377
+
+# include <cassert>
+# include <cstdlib> // std::abort
+# include <iostream>
+# include <stdexcept>
+# include <string>
+# include <vector>
+# include "stack.hh"
+# include "location.hh"
+#include <typeinfo>
+#ifndef YYASSERT
+# include <cassert>
+# define YYASSERT assert
+#endif
+
+
+#ifndef YY_ATTRIBUTE
+# if (defined __GNUC__ \
+ && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
+ || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
+# define YY_ATTRIBUTE(Spec) __attribute__(Spec)
+# else
+# define YY_ATTRIBUTE(Spec) /* empty */
+# endif
+#endif
+
+#ifndef YY_ATTRIBUTE_PURE
+# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
+#endif
+
+#ifndef YY_ATTRIBUTE_UNUSED
+# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
+#endif
+
+#if !defined _Noreturn \
+ && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112)
+# if defined _MSC_VER && 1200 <= _MSC_VER
+# define _Noreturn __declspec (noreturn)
+# else
+# define _Noreturn YY_ATTRIBUTE ((__noreturn__))
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YYUSE(E) ((void) (E))
+#else
+# define YYUSE(E) /* empty */
+#endif
+
+#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
+/* Suppress an incorrect diagnostic about yylval being uninitialized. */
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define YY_INITIAL_VALUE(Value) Value
+#endif
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+
+/* Debug traces. */
+#ifndef D2_PARSER_DEBUG
+# if defined YYDEBUG
+#if YYDEBUG
+# define D2_PARSER_DEBUG 1
+# else
+# define D2_PARSER_DEBUG 0
+# endif
+# else /* ! defined YYDEBUG */
+# define D2_PARSER_DEBUG 1
+# endif /* ! defined YYDEBUG */
+#endif /* ! defined D2_PARSER_DEBUG */
+
+#line 14 "d2_parser.yy" // lalr1.cc:377
+namespace isc { namespace d2 {
+#line 141 "d2_parser.h" // lalr1.cc:377
+
+
+
+ /// A char[S] buffer to store and retrieve objects.
+ ///
+ /// Sort of a variant, but does not keep track of the nature
+ /// of the stored data, since that knowledge is available
+ /// via the current state.
+ template <size_t S>
+ struct variant
+ {
+ /// Type of *this.
+ typedef variant<S> self_type;
+
+ /// Empty construction.
+ variant ()
+ : yytypeid_ (YY_NULLPTR)
+ {}
+
+ /// Construct and fill.
+ template <typename T>
+ variant (const T& t)
+ : yytypeid_ (&typeid (T))
+ {
+ YYASSERT (sizeof (T) <= S);
+ new (yyas_<T> ()) T (t);
+ }
+
+ /// Destruction, allowed only if empty.
+ ~variant ()
+ {
+ YYASSERT (!yytypeid_);
+ }
+
+ /// Instantiate an empty \a T in here.
+ template <typename T>
+ T&
+ build ()
+ {
+ YYASSERT (!yytypeid_);
+ YYASSERT (sizeof (T) <= S);
+ yytypeid_ = & typeid (T);
+ return *new (yyas_<T> ()) T;
+ }
+
+ /// Instantiate a \a T in here from \a t.
+ template <typename T>
+ T&
+ build (const T& t)
+ {
+ YYASSERT (!yytypeid_);
+ YYASSERT (sizeof (T) <= S);
+ yytypeid_ = & typeid (T);
+ return *new (yyas_<T> ()) T (t);
+ }
+
+ /// Accessor to a built \a T.
+ template <typename T>
+ T&
+ as ()
+ {
+ YYASSERT (*yytypeid_ == typeid (T));
+ YYASSERT (sizeof (T) <= S);
+ return *yyas_<T> ();
+ }
+
+ /// Const accessor to a built \a T (for %printer).
+ template <typename T>
+ const T&
+ as () const
+ {
+ YYASSERT (*yytypeid_ == typeid (T));
+ YYASSERT (sizeof (T) <= S);
+ return *yyas_<T> ();
+ }
+
+ /// Swap the content with \a other, of same type.
+ ///
+ /// Both variants must be built beforehand, because swapping the actual
+ /// data requires reading it (with as()), and this is not possible on
+ /// unconstructed variants: it would require some dynamic testing, which
+ /// should not be the variant's responsability.
+ /// Swapping between built and (possibly) non-built is done with
+ /// variant::move ().
+ template <typename T>
+ void
+ swap (self_type& other)
+ {
+ YYASSERT (yytypeid_);
+ YYASSERT (*yytypeid_ == *other.yytypeid_);
+ std::swap (as<T> (), other.as<T> ());
+ }
+
+ /// Move the content of \a other to this.
+ ///
+ /// Destroys \a other.
+ template <typename T>
+ void
+ move (self_type& other)
+ {
+ build<T> ();
+ swap<T> (other);
+ other.destroy<T> ();
+ }
+
+ /// Copy the content of \a other to this.
+ template <typename T>
+ void
+ copy (const self_type& other)
+ {
+ build<T> (other.as<T> ());
+ }
+
+ /// Destroy the stored \a T.
+ template <typename T>
+ void
+ destroy ()
+ {
+ as<T> ().~T ();
+ yytypeid_ = YY_NULLPTR;
+ }
+
+ private:
+ /// Prohibit blind copies.
+ self_type& operator=(const self_type&);
+ variant (const self_type&);
+
+ /// Accessor to raw memory as \a T.
+ template <typename T>
+ T*
+ yyas_ ()
+ {
+ void *yyp = yybuffer_.yyraw;
+ return static_cast<T*> (yyp);
+ }
+
+ /// Const accessor to raw memory as \a T.
+ template <typename T>
+ const T*
+ yyas_ () const
+ {
+ const void *yyp = yybuffer_.yyraw;
+ return static_cast<const T*> (yyp);
+ }
+
+ union
+ {
+ /// Strongest alignment constraints.
+ long double yyalign_me;
+ /// A buffer large enough to store any of the semantic values.
+ char yyraw[S];
+ } yybuffer_;
+
+ /// Whether the content is built: if defined, the name of the stored type.
+ const std::type_info *yytypeid_;
+ };
+
+
+ /// A Bison parser.
+ class D2Parser
+ {
+ public:
+#ifndef D2_PARSER_STYPE
+ /// An auxiliary type to compute the largest semantic type.
+ union union_type
+ {
+ // value
+ // ncr_protocol_value
+ char dummy1[sizeof(ElementPtr)];
+
+ // "boolean"
+ char dummy2[sizeof(bool)];
+
+ // "floating point"
+ char dummy3[sizeof(double)];
+
+ // "integer"
+ char dummy4[sizeof(int64_t)];
+
+ // "constant string"
+ char dummy5[sizeof(std::string)];
+};
+
+ /// Symbol semantic values.
+ typedef variant<sizeof(union_type)> semantic_type;
+#else
+ typedef D2_PARSER_STYPE semantic_type;
+#endif
+ /// Symbol locations.
+ typedef location location_type;
+
+ /// Syntax errors thrown from user actions.
+ struct syntax_error : std::runtime_error
+ {
+ syntax_error (const location_type& l, const std::string& m);
+ location_type location;
+ };
+
+ /// Tokens.
+ struct token
+ {
+ enum yytokentype
+ {
+ TOKEN_END = 0,
+ TOKEN_COMMA = 258,
+ TOKEN_COLON = 259,
+ TOKEN_LSQUARE_BRACKET = 260,
+ TOKEN_RSQUARE_BRACKET = 261,
+ TOKEN_LCURLY_BRACKET = 262,
+ TOKEN_RCURLY_BRACKET = 263,
+ TOKEN_NULL_TYPE = 264,
+ TOKEN_DHCP6 = 265,
+ TOKEN_DHCP4 = 266,
+ TOKEN_DHCPDDNS = 267,
+ TOKEN_IP_ADDRESS = 268,
+ TOKEN_PORT = 269,
+ TOKEN_DNS_SERVER_TIMEOUT = 270,
+ TOKEN_NCR_PROTOCOL = 271,
+ TOKEN_UDP = 272,
+ TOKEN_TCP = 273,
+ TOKEN_NCR_FORMAT = 274,
+ TOKEN_JSON = 275,
+ TOKEN_FORWARD_DDNS = 276,
+ TOKEN_REVERSE_DDNS = 277,
+ TOKEN_DDNS_DOMAINS = 278,
+ TOKEN_KEY_NAME = 279,
+ TOKEN_DNS_SERVERS = 280,
+ TOKEN_HOSTNAME = 281,
+ TOKEN_TSIG_KEYS = 282,
+ TOKEN_ALGORITHM = 283,
+ TOKEN_DIGEST_BITS = 284,
+ TOKEN_SECRET = 285,
+ TOKEN_LOGGING = 286,
+ TOKEN_LOGGERS = 287,
+ TOKEN_NAME = 288,
+ TOKEN_OUTPUT_OPTIONS = 289,
+ TOKEN_OUTPUT = 290,
+ TOKEN_DEBUGLEVEL = 291,
+ TOKEN_SEVERITY = 292,
+ TOKEN_TOPLEVEL_JSON = 293,
+ TOKEN_TOPLEVEL_DHCPDDNS = 294,
+ TOKEN_SUB_DHCPDDNS = 295,
+ TOKEN_SUB_TSIG_KEY = 296,
+ TOKEN_SUB_TSIG_KEYS = 297,
+ TOKEN_SUB_DDNS_DOMAIN = 298,
+ TOKEN_SUB_DDNS_DOMAINS = 299,
+ TOKEN_SUB_DNS_SERVER = 300,
+ TOKEN_SUB_DNS_SERVERS = 301,
+ TOKEN_STRING = 302,
+ TOKEN_INTEGER = 303,
+ TOKEN_FLOAT = 304,
+ TOKEN_BOOLEAN = 305
+ };
+ };
+
+ /// (External) token type, as returned by yylex.
+ typedef token::yytokentype token_type;
+
+ /// Symbol type: an internal symbol number.
+ typedef int symbol_number_type;
+
+ /// The symbol type number to denote an empty symbol.
+ enum { empty_symbol = -2 };
+
+ /// Internal symbol number for tokens (subsumed by symbol_number_type).
+ typedef unsigned char token_number_type;
+
+ /// A complete symbol.
+ ///
+ /// Expects its Base type to provide access to the symbol type
+ /// via type_get().
+ ///
+ /// Provide access to semantic value and location.
+ template <typename Base>
+ struct basic_symbol : Base
+ {
+ /// Alias to Base.
+ typedef Base super_type;
+
+ /// Default constructor.
+ basic_symbol ();
+
+ /// Copy constructor.
+ basic_symbol (const basic_symbol& other);
+
+ /// Constructor for valueless symbols, and symbols from each type.
+
+ basic_symbol (typename Base::kind_type t, const location_type& l);
+
+ basic_symbol (typename Base::kind_type t, const ElementPtr v, const location_type& l);
+
+ basic_symbol (typename Base::kind_type t, const bool v, const location_type& l);
+
+ basic_symbol (typename Base::kind_type t, const double v, const location_type& l);
+
+ basic_symbol (typename Base::kind_type t, const int64_t v, const location_type& l);
+
+ basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l);
+
+
+ /// Constructor for symbols with semantic value.
+ basic_symbol (typename Base::kind_type t,
+ const semantic_type& v,
+ const location_type& l);
+
+ /// Destroy the symbol.
+ ~basic_symbol ();
+
+ /// Destroy contents, and record that is empty.
+ void clear ();
+
+ /// Whether empty.
+ bool empty () const;
+
+ /// Destructive move, \a s is emptied into this.
+ void move (basic_symbol& s);
+
+ /// The semantic value.
+ semantic_type value;
+
+ /// The location.
+ location_type location;
+
+ private:
+ /// Assignment operator.
+ basic_symbol& operator= (const basic_symbol& other);
+ };
+
+ /// Type access provider for token (enum) based symbols.
+ struct by_type
+ {
+ /// Default constructor.
+ by_type ();
+
+ /// Copy constructor.
+ by_type (const by_type& other);
+
+ /// The symbol type as needed by the constructor.
+ typedef token_type kind_type;
+
+ /// Constructor from (external) token numbers.
+ by_type (kind_type t);
+
+ /// Record that this symbol is empty.
+ void clear ();
+
+ /// Steal the symbol type from \a that.
+ void move (by_type& that);
+
+ /// The (internal) type number (corresponding to \a type).
+ /// \a empty when empty.
+ symbol_number_type type_get () const;
+
+ /// The token.
+ token_type token () const;
+
+ /// The symbol type.
+ /// \a empty_symbol when empty.
+ /// An int, not token_number_type, to be able to store empty_symbol.
+ int type;
+ };
+
+ /// "External" symbols: returned by the scanner.
+ typedef basic_symbol<by_type> symbol_type;
+
+ // Symbol constructors declarations.
+ static inline
+ symbol_type
+ make_END (const location_type& l);
+
+ static inline
+ symbol_type
+ make_COMMA (const location_type& l);
+
+ static inline
+ symbol_type
+ make_COLON (const location_type& l);
+
+ static inline
+ symbol_type
+ make_LSQUARE_BRACKET (const location_type& l);
+
+ static inline
+ symbol_type
+ make_RSQUARE_BRACKET (const location_type& l);
+
+ static inline
+ symbol_type
+ make_LCURLY_BRACKET (const location_type& l);
+
+ static inline
+ symbol_type
+ make_RCURLY_BRACKET (const location_type& l);
+
+ static inline
+ symbol_type
+ make_NULL_TYPE (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DHCP6 (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DHCP4 (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DHCPDDNS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_IP_ADDRESS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_PORT (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DNS_SERVER_TIMEOUT (const location_type& l);
+
+ static inline
+ symbol_type
+ make_NCR_PROTOCOL (const location_type& l);
+
+ static inline
+ symbol_type
+ make_UDP (const location_type& l);
+
+ static inline
+ symbol_type
+ make_TCP (const location_type& l);
+
+ static inline
+ symbol_type
+ make_NCR_FORMAT (const location_type& l);
+
+ static inline
+ symbol_type
+ make_JSON (const location_type& l);
+
+ static inline
+ symbol_type
+ make_FORWARD_DDNS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_REVERSE_DDNS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DDNS_DOMAINS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_KEY_NAME (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DNS_SERVERS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_HOSTNAME (const location_type& l);
+
+ static inline
+ symbol_type
+ make_TSIG_KEYS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_ALGORITHM (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DIGEST_BITS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SECRET (const location_type& l);
+
+ static inline
+ symbol_type
+ make_LOGGING (const location_type& l);
+
+ static inline
+ symbol_type
+ make_LOGGERS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_NAME (const location_type& l);
+
+ static inline
+ symbol_type
+ make_OUTPUT_OPTIONS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_OUTPUT (const location_type& l);
+
+ static inline
+ symbol_type
+ make_DEBUGLEVEL (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SEVERITY (const location_type& l);
+
+ static inline
+ symbol_type
+ make_TOPLEVEL_JSON (const location_type& l);
+
+ static inline
+ symbol_type
+ make_TOPLEVEL_DHCPDDNS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SUB_DHCPDDNS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SUB_TSIG_KEY (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SUB_TSIG_KEYS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SUB_DDNS_DOMAIN (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SUB_DDNS_DOMAINS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SUB_DNS_SERVER (const location_type& l);
+
+ static inline
+ symbol_type
+ make_SUB_DNS_SERVERS (const location_type& l);
+
+ static inline
+ symbol_type
+ make_STRING (const std::string& v, const location_type& l);
+
+ static inline
+ symbol_type
+ make_INTEGER (const int64_t& v, const location_type& l);
+
+ static inline
+ symbol_type
+ make_FLOAT (const double& v, const location_type& l);
+
+ static inline
+ symbol_type
+ make_BOOLEAN (const bool& v, const location_type& l);
+
+
+ /// Build a parser object.
+ D2Parser (isc::d2::D2ParserContext& ctx_yyarg);
+ virtual ~D2Parser ();
+
+ /// Parse.
+ /// \returns 0 iff parsing succeeded.
+ virtual int parse ();
+
+#if D2_PARSER_DEBUG
+ /// The current debugging stream.
+ std::ostream& debug_stream () const YY_ATTRIBUTE_PURE;
+ /// Set the current debugging stream.
+ void set_debug_stream (std::ostream &);
+
+ /// Type for debugging levels.
+ typedef int debug_level_type;
+ /// The current debugging level.
+ debug_level_type debug_level () const YY_ATTRIBUTE_PURE;
+ /// Set the current debugging level.
+ void set_debug_level (debug_level_type l);
+#endif
+
+ /// Report a syntax error.
+ /// \param loc where the syntax error is found.
+ /// \param msg a description of the syntax error.
+ virtual void error (const location_type& loc, const std::string& msg);
+
+ /// Report a syntax error.
+ void error (const syntax_error& err);
+
+ private:
+ /// This class is not copyable.
+ D2Parser (const D2Parser&);
+ D2Parser& operator= (const D2Parser&);
+
+ /// State numbers.
+ typedef int state_type;
+
+ /// Generate an error message.
+ /// \param yystate the state where the error occurred.
+ /// \param yyla the lookahead token.
+ virtual std::string yysyntax_error_ (state_type yystate,
+ const symbol_type& yyla) const;
+
+ /// Compute post-reduction state.
+ /// \param yystate the current state
+ /// \param yysym the nonterminal to push on the stack
+ state_type yy_lr_goto_state_ (state_type yystate, int yysym);
+
+ /// Whether the given \c yypact_ value indicates a defaulted state.
+ /// \param yyvalue the value to check
+ static bool yy_pact_value_is_default_ (int yyvalue);
+
+ /// Whether the given \c yytable_ value indicates a syntax error.
+ /// \param yyvalue the value to check
+ static bool yy_table_value_is_error_ (int yyvalue);
+
+ static const signed char yypact_ninf_;
+ static const signed char yytable_ninf_;
+
+ /// Convert a scanner token number \a t to a symbol number.
+ static token_number_type yytranslate_ (token_type t);
+
+ // Tables.
+ // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ // STATE-NUM.
+ static const short int yypact_[];
+
+ // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
+ // Performed when YYTABLE does not specify something else to do. Zero
+ // means the default is an error.
+ static const unsigned char yydefact_[];
+
+ // YYPGOTO[NTERM-NUM].
+ static const signed char yypgoto_[];
+
+ // YYDEFGOTO[NTERM-NUM].
+ static const short int yydefgoto_[];
+
+ // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
+ // positive, shift that token. If negative, reduce the rule whose
+ // number is the opposite. If YYTABLE_NINF, syntax error.
+ static const unsigned short int yytable_[];
+
+ static const short int yycheck_[];
+
+ // YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ // symbol of state STATE-NUM.
+ static const unsigned char yystos_[];
+
+ // YYR1[YYN] -- Symbol number of symbol that rule YYN derives.
+ static const unsigned char yyr1_[];
+
+ // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN.
+ static const unsigned char yyr2_[];
+
+
+ /// Convert the symbol name \a n to a form suitable for a diagnostic.
+ static std::string yytnamerr_ (const char *n);
+
+
+ /// For a symbol, its name in clear.
+ static const char* const yytname_[];
+#if D2_PARSER_DEBUG
+ // YYRLINE[YYN] -- Source line where rule number YYN was defined.
+ static const unsigned short int yyrline_[];
+ /// Report on the debug stream that the rule \a r is going to be reduced.
+ virtual void yy_reduce_print_ (int r);
+ /// Print the state stack on the debug stream.
+ virtual void yystack_print_ ();
+
+ // Debugging.
+ int yydebug_;
+ std::ostream* yycdebug_;
+
+ /// \brief Display a symbol type, value and location.
+ /// \param yyo The output stream.
+ /// \param yysym The symbol.
+ template <typename Base>
+ void yy_print_ (std::ostream& yyo, const basic_symbol<Base>& yysym) const;
+#endif
+
+ /// \brief Reclaim the memory associated to a symbol.
+ /// \param yymsg Why this token is reclaimed.
+ /// If null, print nothing.
+ /// \param yysym The symbol.
+ template <typename Base>
+ void yy_destroy_ (const char* yymsg, basic_symbol<Base>& yysym) const;
+
+ private:
+ /// Type access provider for state based symbols.
+ struct by_state
+ {
+ /// Default constructor.
+ by_state ();
+
+ /// The symbol type as needed by the constructor.
+ typedef state_type kind_type;
+
+ /// Constructor.
+ by_state (kind_type s);
+
+ /// Copy constructor.
+ by_state (const by_state& other);
+
+ /// Record that this symbol is empty.
+ void clear ();
+
+ /// Steal the symbol type from \a that.
+ void move (by_state& that);
+
+ /// The (internal) type number (corresponding to \a state).
+ /// \a empty_symbol when empty.
+ symbol_number_type type_get () const;
+
+ /// The state number used to denote an empty symbol.
+ enum { empty_state = -1 };
+
+ /// The state.
+ /// \a empty when empty.
+ state_type state;
+ };
+
+ /// "Internal" symbol: element of the stack.
+ struct stack_symbol_type : basic_symbol<by_state>
+ {
+ /// Superclass.
+ typedef basic_symbol<by_state> super_type;
+ /// Construct an empty symbol.
+ stack_symbol_type ();
+ /// Steal the contents from \a sym to build this.
+ stack_symbol_type (state_type s, symbol_type& sym);
+ /// Assignment, needed by push_back.
+ stack_symbol_type& operator= (const stack_symbol_type& that);
+ };
+
+ /// Stack type.
+ typedef stack<stack_symbol_type> stack_type;
+
+ /// The stack.
+ stack_type yystack_;
+
+ /// Push a new state on the stack.
+ /// \param m a debug message to display
+ /// if null, no trace is output.
+ /// \param s the symbol
+ /// \warning the contents of \a s.value is stolen.
+ void yypush_ (const char* m, stack_symbol_type& s);
+
+ /// Push a new look ahead token on the state on the stack.
+ /// \param m a debug message to display
+ /// if null, no trace is output.
+ /// \param s the state
+ /// \param sym the symbol (for its value and location).
+ /// \warning the contents of \a s.value is stolen.
+ void yypush_ (const char* m, state_type s, symbol_type& sym);
+
+ /// Pop \a n symbols the three stacks.
+ void yypop_ (unsigned int n = 1);
+
+ /// Constants.
+ enum
+ {
+ yyeof_ = 0,
+ yylast_ = 247, ///< Last index in yytable_.
+ yynnts_ = 127, ///< Number of nonterminal symbols.
+ yyfinal_ = 20, ///< Termination state number.
+ yyterror_ = 1,
+ yyerrcode_ = 256,
+ yyntokens_ = 51 ///< Number of tokens.
+ };
+
+
+ // User arguments.
+ isc::d2::D2ParserContext& ctx;
+ };
+
+ // Symbol number corresponding to token number t.
+ inline
+ D2Parser::token_number_type
+ D2Parser::yytranslate_ (token_type t)
+ {
+ static
+ const token_number_type
+ translate_table[] =
+ {
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50
+ };
+ const unsigned int user_token_number_max_ = 305;
+ const token_number_type undef_token_ = 2;
+
+ if (static_cast<int>(t) <= yyeof_)
+ return yyeof_;
+ else if (static_cast<unsigned int> (t) <= user_token_number_max_)
+ return translate_table[t];
+ else
+ return undef_token_;
+ }
+
+ inline
+ D2Parser::syntax_error::syntax_error (const location_type& l, const std::string& m)
+ : std::runtime_error (m)
+ , location (l)
+ {}
+
+ // basic_symbol.
+ template <typename Base>
+ inline
+ D2Parser::basic_symbol<Base>::basic_symbol ()
+ : value ()
+ {}
+
+ template <typename Base>
+ inline
+ D2Parser::basic_symbol<Base>::basic_symbol (const basic_symbol& other)
+ : Base (other)
+ , value ()
+ , location (other.location)
+ {
+ switch (other.type_get ())
+ {
+ case 62: // value
+ case 89: // ncr_protocol_value
+ value.copy< ElementPtr > (other.value);
+ break;
+
+ case 50: // "boolean"
+ value.copy< bool > (other.value);
+ break;
+
+ case 49: // "floating point"
+ value.copy< double > (other.value);
+ break;
+
+ case 48: // "integer"
+ value.copy< int64_t > (other.value);
+ break;
+
+ case 47: // "constant string"
+ value.copy< std::string > (other.value);
+ break;
+
+ default:
+ break;
+ }
+
+ }
+
+
+ template <typename Base>
+ inline
+ D2Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const semantic_type& v, const location_type& l)
+ : Base (t)
+ , value ()
+ , location (l)
+ {
+ (void) v;
+ switch (this->type_get ())
+ {
+ case 62: // value
+ case 89: // ncr_protocol_value
+ value.copy< ElementPtr > (v);
+ break;
+
+ case 50: // "boolean"
+ value.copy< bool > (v);
+ break;
+
+ case 49: // "floating point"
+ value.copy< double > (v);
+ break;
+
+ case 48: // "integer"
+ value.copy< int64_t > (v);
+ break;
+
+ case 47: // "constant string"
+ value.copy< std::string > (v);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+ // Implementation of basic_symbol constructor for each type.
+
+ template <typename Base>
+ D2Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const location_type& l)
+ : Base (t)
+ , value ()
+ , location (l)
+ {}
+
+ template <typename Base>
+ D2Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const ElementPtr v, const location_type& l)
+ : Base (t)
+ , value (v)
+ , location (l)
+ {}
+
+ template <typename Base>
+ D2Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const bool v, const location_type& l)
+ : Base (t)
+ , value (v)
+ , location (l)
+ {}
+
+ template <typename Base>
+ D2Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const double v, const location_type& l)
+ : Base (t)
+ , value (v)
+ , location (l)
+ {}
+
+ template <typename Base>
+ D2Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const int64_t v, const location_type& l)
+ : Base (t)
+ , value (v)
+ , location (l)
+ {}
+
+ template <typename Base>
+ D2Parser::basic_symbol<Base>::basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l)
+ : Base (t)
+ , value (v)
+ , location (l)
+ {}
+
+
+ template <typename Base>
+ inline
+ D2Parser::basic_symbol<Base>::~basic_symbol ()
+ {
+ clear ();
+ }
+
+ template <typename Base>
+ inline
+ void
+ D2Parser::basic_symbol<Base>::clear ()
+ {
+ // User destructor.
+ symbol_number_type yytype = this->type_get ();
+ basic_symbol<Base>& yysym = *this;
+ (void) yysym;
+ switch (yytype)
+ {
+ default:
+ break;
+ }
+
+ // Type destructor.
+ switch (yytype)
+ {
+ case 62: // value
+ case 89: // ncr_protocol_value
+ value.template destroy< ElementPtr > ();
+ break;
+
+ case 50: // "boolean"
+ value.template destroy< bool > ();
+ break;
+
+ case 49: // "floating point"
+ value.template destroy< double > ();
+ break;
+
+ case 48: // "integer"
+ value.template destroy< int64_t > ();
+ break;
+
+ case 47: // "constant string"
+ value.template destroy< std::string > ();
+ break;
+
+ default:
+ break;
+ }
+
+ Base::clear ();
+ }
+
+ template <typename Base>
+ inline
+ bool
+ D2Parser::basic_symbol<Base>::empty () const
+ {
+ return Base::type_get () == empty_symbol;
+ }
+
+ template <typename Base>
+ inline
+ void
+ D2Parser::basic_symbol<Base>::move (basic_symbol& s)
+ {
+ super_type::move(s);
+ switch (this->type_get ())
+ {
+ case 62: // value
+ case 89: // ncr_protocol_value
+ value.move< ElementPtr > (s.value);
+ break;
+
+ case 50: // "boolean"
+ value.move< bool > (s.value);
+ break;
+
+ case 49: // "floating point"
+ value.move< double > (s.value);
+ break;
+
+ case 48: // "integer"
+ value.move< int64_t > (s.value);
+ break;
+
+ case 47: // "constant string"
+ value.move< std::string > (s.value);
+ break;
+
+ default:
+ break;
+ }
+
+ location = s.location;
+ }
+
+ // by_type.
+ inline
+ D2Parser::by_type::by_type ()
+ : type (empty_symbol)
+ {}
+
+ inline
+ D2Parser::by_type::by_type (const by_type& other)
+ : type (other.type)
+ {}
+
+ inline
+ D2Parser::by_type::by_type (token_type t)
+ : type (yytranslate_ (t))
+ {}
+
+ inline
+ void
+ D2Parser::by_type::clear ()
+ {
+ type = empty_symbol;
+ }
+
+ inline
+ void
+ D2Parser::by_type::move (by_type& that)
+ {
+ type = that.type;
+ that.clear ();
+ }
+
+ inline
+ int
+ D2Parser::by_type::type_get () const
+ {
+ return type;
+ }
+
+ inline
+ D2Parser::token_type
+ D2Parser::by_type::token () const
+ {
+ // YYTOKNUM[NUM] -- (External) token number corresponding to the
+ // (internal) symbol number NUM (which must be that of a token). */
+ static
+ const unsigned short int
+ yytoken_number_[] =
+ {
+ 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
+ 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
+ 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
+ 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
+ 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
+ 305
+ };
+ return static_cast<token_type> (yytoken_number_[type]);
+ }
+ // Implementation of make_symbol for each symbol type.
+ D2Parser::symbol_type
+ D2Parser::make_END (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_END, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_COMMA (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_COMMA, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_COLON (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_COLON, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_LSQUARE_BRACKET (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_LSQUARE_BRACKET, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_RSQUARE_BRACKET (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_RSQUARE_BRACKET, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_LCURLY_BRACKET (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_LCURLY_BRACKET, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_RCURLY_BRACKET (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_RCURLY_BRACKET, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_NULL_TYPE (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_NULL_TYPE, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DHCP6 (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DHCP6, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DHCP4 (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DHCP4, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DHCPDDNS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DHCPDDNS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_IP_ADDRESS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_IP_ADDRESS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_PORT (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_PORT, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DNS_SERVER_TIMEOUT (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DNS_SERVER_TIMEOUT, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_NCR_PROTOCOL (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_NCR_PROTOCOL, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_UDP (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_UDP, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_TCP (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_TCP, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_NCR_FORMAT (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_NCR_FORMAT, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_JSON (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_JSON, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_FORWARD_DDNS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_FORWARD_DDNS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_REVERSE_DDNS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_REVERSE_DDNS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DDNS_DOMAINS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DDNS_DOMAINS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_KEY_NAME (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_KEY_NAME, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DNS_SERVERS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DNS_SERVERS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_HOSTNAME (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_HOSTNAME, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_TSIG_KEYS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_TSIG_KEYS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_ALGORITHM (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_ALGORITHM, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DIGEST_BITS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DIGEST_BITS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SECRET (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SECRET, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_LOGGING (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_LOGGING, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_LOGGERS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_LOGGERS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_NAME (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_NAME, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_OUTPUT_OPTIONS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_OUTPUT_OPTIONS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_OUTPUT (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_OUTPUT, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_DEBUGLEVEL (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_DEBUGLEVEL, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SEVERITY (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SEVERITY, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_TOPLEVEL_JSON (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_TOPLEVEL_JSON, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_TOPLEVEL_DHCPDDNS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_TOPLEVEL_DHCPDDNS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SUB_DHCPDDNS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SUB_DHCPDDNS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SUB_TSIG_KEY (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SUB_TSIG_KEY, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SUB_TSIG_KEYS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SUB_TSIG_KEYS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SUB_DDNS_DOMAIN (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SUB_DDNS_DOMAIN, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SUB_DDNS_DOMAINS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SUB_DDNS_DOMAINS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SUB_DNS_SERVER (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SUB_DNS_SERVER, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_SUB_DNS_SERVERS (const location_type& l)
+ {
+ return symbol_type (token::TOKEN_SUB_DNS_SERVERS, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_STRING (const std::string& v, const location_type& l)
+ {
+ return symbol_type (token::TOKEN_STRING, v, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_INTEGER (const int64_t& v, const location_type& l)
+ {
+ return symbol_type (token::TOKEN_INTEGER, v, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_FLOAT (const double& v, const location_type& l)
+ {
+ return symbol_type (token::TOKEN_FLOAT, v, l);
+ }
+
+ D2Parser::symbol_type
+ D2Parser::make_BOOLEAN (const bool& v, const location_type& l)
+ {
+ return symbol_type (token::TOKEN_BOOLEAN, v, l);
+ }
+
+
+#line 14 "d2_parser.yy" // lalr1.cc:377
+} } // isc::d2
+#line 1558 "d2_parser.h" // lalr1.cc:377
+
+
+
+
+#endif // !YY_D2_PARSER_D2_PARSER_H_INCLUDED
--- /dev/null
+/* Copyright (C) 2017 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
+ file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+%skeleton "lalr1.cc" /* -*- C++ -*- */
+%require "3.0.0"
+%defines
+%define parser_class_name {D2Parser}
+%define api.prefix {d2_parser_}
+%define api.token.constructor
+%define api.value.type variant
+%define api.namespace {isc::d2}
+%define parse.assert
+%code requires
+{
+#include <string>
+#include <cc/data.h>
+#include <d2/d2_config.h>
+#include <boost/lexical_cast.hpp>
+#include <d2/parser_context_decl.h>
+
+using namespace isc::d2;
+using namespace isc::data;
+using namespace std;
+}
+// The parsing context.
+%param { isc::d2::D2ParserContext& ctx }
+%locations
+%define parse.trace
+%define parse.error verbose
+%code
+{
+#include <d2/parser_context.h>
+}
+
+
+%define api.token.prefix {TOKEN_}
+// Tokens in an order which makes sense and related to the intented use.
+// Actual regexps for tokens are defined in d2_lexer.ll.
+%token
+ END 0 "end of file"
+ COMMA ","
+ COLON ":"
+ LSQUARE_BRACKET "["
+ RSQUARE_BRACKET "]"
+ LCURLY_BRACKET "{"
+ RCURLY_BRACKET "}"
+ NULL_TYPE "null"
+
+ DHCP6 "Dhcp6"
+ DHCP4 "Dhcp4"
+
+ DHCPDDNS "DhcpDdns"
+ IP_ADDRESS "ip-address"
+ PORT "port"
+ DNS_SERVER_TIMEOUT "dns-server-timeout"
+ NCR_PROTOCOL "ncr-protocol"
+ UDP "UDP"
+ TCP "TCP"
+ NCR_FORMAT "ncr-format"
+ JSON "JSON"
+ FORWARD_DDNS "forward-ddns"
+ REVERSE_DDNS "reverse-ddns"
+ DDNS_DOMAINS "ddns-domains"
+ KEY_NAME "key-name"
+ DNS_SERVERS "dns-servers"
+ HOSTNAME "hostname"
+ TSIG_KEYS "tsig-keys"
+ ALGORITHM "algorithm"
+ DIGEST_BITS "digest-bits"
+ SECRET "secret"
+
+ LOGGING "Logging"
+ LOGGERS "loggers"
+ NAME "name"
+ OUTPUT_OPTIONS "output_options"
+ OUTPUT "output"
+ DEBUGLEVEL "debuglevel"
+ SEVERITY "severity"
+
+ // Not real tokens, just a way to signal what the parser is expected to
+ // parse.
+ TOPLEVEL_JSON
+ TOPLEVEL_DHCPDDNS
+ SUB_DHCPDDNS
+ SUB_TSIG_KEY
+ SUB_TSIG_KEYS
+ SUB_DDNS_DOMAIN
+ SUB_DDNS_DOMAINS
+ SUB_DNS_SERVER
+ SUB_DNS_SERVERS
+;
+
+%token <std::string> STRING "constant string"
+%token <int64_t> INTEGER "integer"
+%token <double> FLOAT "floating point"
+%token <bool> BOOLEAN "boolean"
+
+%type <ElementPtr> value
+%type <ElementPtr> ncr_protocol_value
+
+%printer { yyoutput << $$; } <*>;
+
+%%
+
+// The whole grammar starts with a map, because the config file
+// constists of Dhcp, Logger and DhcpDdns entries in one big { }.
+// We made the same for subparsers at the exception of the JSON value.
+%start start;
+
+start: TOPLEVEL_JSON { ctx.ctx_ = ctx.NO_KEYWORD; } sub_json
+ | TOPLEVEL_DHCPDDNS { ctx.ctx_ = ctx.CONFIG; } syntax_map
+ | SUB_DHCPDDNS { ctx.ctx_ = ctx.DHCPDDNS; } sub_dhcpddns
+ | SUB_TSIG_KEY { ctx.ctx_ = ctx.TSIG_KEY; } sub_tsig_key
+ | SUB_TSIG_KEYS { ctx.ctx_ = ctx.TSIG_KEYS; } sub_tsig_keys
+ | SUB_DDNS_DOMAIN { ctx.ctx_ = ctx.DDNS_DOMAIN; } sub_ddns_domain
+ | SUB_DDNS_DOMAINS { ctx.ctx_ = ctx.DDNS_DOMAINS; } sub_ddns_domains
+ | SUB_DNS_SERVER { ctx.ctx_ = ctx.DNS_SERVERS; } sub_dns_server
+ | SUB_DNS_SERVERS { ctx.ctx_ = ctx.DNS_SERVERS; } sub_dns_servers
+ ;
+
+// ---- generic JSON parser ---------------------------------
+
+// Note that ctx_ is NO_KEYWORD here
+
+// Values rule
+value: INTEGER { $$ = ElementPtr(new IntElement($1, ctx.loc2pos(@1))); }
+ | FLOAT { $$ = ElementPtr(new DoubleElement($1, ctx.loc2pos(@1))); }
+ | BOOLEAN { $$ = ElementPtr(new BoolElement($1, ctx.loc2pos(@1))); }
+ | STRING { $$ = ElementPtr(new StringElement($1, ctx.loc2pos(@1))); }
+ | NULL_TYPE { $$ = ElementPtr(new NullElement(ctx.loc2pos(@1))); }
+ | map2 { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
+ | list_generic { $$ = ctx.stack_.back(); ctx.stack_.pop_back(); }
+ ;
+
+sub_json: value {
+ // Push back the JSON value on the stack
+ ctx.stack_.push_back($1);
+};
+
+map2: LCURLY_BRACKET {
+ // This code is executed when we're about to start parsing
+ // the content of the map
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(m);
+} map_content RCURLY_BRACKET {
+ // map parsing completed. If we ever want to do any wrap up
+ // (maybe some sanity checking), this would be the best place
+ // for it.
+};
+
+// Assignments rule
+map_content: %empty // empty map
+ | not_empty_map
+ ;
+
+not_empty_map: STRING COLON value {
+ // map containing a single entry
+ ctx.stack_.back()->set($1, $3);
+ }
+ | not_empty_map COMMA STRING COLON value {
+ // map consisting of a shorter map followed by
+ // comma and string:value
+ ctx.stack_.back()->set($3, $5);
+ }
+ ;
+
+list_generic: LSQUARE_BRACKET {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(l);
+} list_content RSQUARE_BRACKET {
+ // list parsing complete. Put any sanity checking here
+};
+
+list_content: %empty // Empty list
+ | not_empty_list
+ ;
+
+not_empty_list: value {
+ // List consisting of a single element.
+ ctx.stack_.back()->add($1);
+ }
+ | not_empty_list COMMA value {
+ // List ending with , and a value.
+ ctx.stack_.back()->add($3);
+ }
+ ;
+
+// ---- generic JSON parser ends here ----------------------------------
+
+// ---- syntax checking parser starts here -----------------------------
+
+// Unknown keyword in a map
+unknown_map_entry: STRING COLON {
+ const std::string& where = ctx.contextName();
+ const std::string& keyword = $1;
+ error(@1,
+ "got unexpected keyword \"" + keyword + "\" in " + where + " map.");
+};
+
+
+// This defines the top-level { } that holds Dhcp6, Dhcp4, DhcpDdns or Logging
+// objects.
+syntax_map: LCURLY_BRACKET {
+ // This code is executed when we're about to start parsing
+ // the content of the map
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(m);
+} global_objects RCURLY_BRACKET {
+ // map parsing completed. If we ever want to do any wrap up
+ // (maybe some sanity checking), this would be the best place
+ // for it.
+};
+
+// This represents top-level entries: Dhcp6, Dhcp4, DhcpDdns, Logging
+global_objects: global_object
+ | global_objects COMMA global_object
+ ;
+
+// This represents a single top level entry, e.g. Dhcp6 or DhcpDdns.
+global_object: dhcp6_json_object
+ | logging_object
+ | dhcp4_json_object
+ | dhcpddns_object
+ | unknown_map_entry
+ ;
+
+// --- dhcp ddns ---------------------------------------------
+
+dhcpddns_object: DHCPDDNS {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("DhcpDdns", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.DHCPDDNS);
+} COLON LCURLY_BRACKET dhcpddns_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+sub_dhcpddns: LCURLY_BRACKET {
+ // Parse the dhcpddns map
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(m);
+} dhcpddns_params RCURLY_BRACKET {
+ // parsing completed
+};
+
+dhcpddns_params: dhcpddns_param
+ | dhcpddns_params COMMA dhcpddns_param
+ ;
+
+// These are the top-level parameters allowed for DhcpDdns
+dhcpddns_param: ip_address
+ | port
+ | dns_server_timeout
+ | ncr_protocol
+ | ncr_format
+ | forward_ddns
+ | reverse_ddns
+ | tsig_keys
+ | unknown_map_entry
+ ;
+
+ip_address: IP_ADDRESS {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ ElementPtr s(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("ip-address", s);
+ ctx.leave();
+};
+
+port: PORT COLON INTEGER {
+ if ($3 <= 0 || $3 >= 65536 ) {
+ error(@3, "port must be greater than zero but less than 65536");
+ }
+ ElementPtr i(new IntElement($3, ctx.loc2pos(@3)));
+ ctx.stack_.back()->set("port", i);
+};
+
+dns_server_timeout: DNS_SERVER_TIMEOUT COLON INTEGER {
+ if ($3 <= 0) {
+ error(@3, "dns-server-timeout must be greater than zero");
+ } else {
+ ElementPtr i(new IntElement($3, ctx.loc2pos(@3)));
+ ctx.stack_.back()->set("dns-server-timeout", i);
+ }
+};
+
+ncr_protocol: NCR_PROTOCOL {
+ ctx.enter(ctx.NCR_PROTOCOL);
+} COLON ncr_protocol_value {
+ ctx.stack_.back()->set("ncr-protocol", $4);
+ ctx.leave();
+};
+
+ncr_protocol_value:
+ UDP { $$ = ElementPtr(new StringElement("UDP", ctx.loc2pos(@1))); }
+ | TCP { $$ = ElementPtr(new StringElement("TCP", ctx.loc2pos(@1))); }
+ ;
+
+ncr_format: NCR_FORMAT {
+ ctx.enter(ctx.NCR_FORMAT);
+} COLON JSON {
+ ElementPtr json(new StringElement("JSON", ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("ncr-format", json);
+ ctx.leave();
+};
+
+forward_ddns : FORWARD_DDNS {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("forward-ddns", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.FORWARD_DDNS);
+} COLON LCURLY_BRACKET ddns_mgr_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+reverse_ddns : REVERSE_DDNS {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("reverse-ddns", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.REVERSE_DDNS);
+} COLON LCURLY_BRACKET ddns_mgr_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+ddns_mgr_params: %empty
+ | not_empty_ddns_mgr_params
+ ;
+
+not_empty_ddns_mgr_params: ddns_mgr_param
+ | ddns_mgr_params COMMA ddns_mgr_param
+ ;
+
+ddns_mgr_param: ddns_domains
+ | unknown_map_entry
+ ;
+
+
+// --- ddns-domains ----------------------------------------
+ddns_domains: DDNS_DOMAINS {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("ddns-domains", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.DDNS_DOMAINS);
+} COLON LSQUARE_BRACKET ddns_domain_list RSQUARE_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+sub_ddns_domains: LSQUARE_BRACKET {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(l);
+} ddns_domain_list RSQUARE_BRACKET {
+ // parsing completed
+}
+
+ddns_domain_list: %empty
+ | not_empty_ddns_domain_list
+ ;
+
+not_empty_ddns_domain_list: ddns_domain
+ | not_empty_ddns_domain_list COMMA ddns_domain
+ ;
+
+ddns_domain: LCURLY_BRACKET {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+} ddns_domain_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+};
+
+sub_ddns_domain: LCURLY_BRACKET {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(m);
+} ddns_domain_params RCURLY_BRACKET {
+ // parsing completed
+};
+
+ddns_domain_params: ddns_domain_param
+ | ddns_domain_params COMMA ddns_domain_param
+ ;
+
+ddns_domain_param: ddns_domain_name
+ | ddns_domain_key_name
+ | dns_servers
+ | unknown_map_entry
+ ;
+
+// @todo NAME needs to be an FQDN sort of thing
+ddns_domain_name: NAME {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ if ($4 == "") {
+ error(@3, "Ddns domain name cannot be blank");
+ }
+ ElementPtr elem(new StringElement($4, ctx.loc2pos(@4)));
+ ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("name", name);
+ ctx.leave();
+};
+
+ddns_domain_key_name: KEY_NAME {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ ElementPtr elem(new StringElement($4, ctx.loc2pos(@4)));
+ ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("key-name", name);
+ ctx.leave();
+};
+
+// --- end ddns-domains ----------------------------------------
+
+// --- dns-servers ----------------------------------------
+dns_servers: DNS_SERVERS {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("dns-servers", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.DNS_SERVERS);
+} COLON LSQUARE_BRACKET dns_server_list RSQUARE_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+sub_dns_servers: LSQUARE_BRACKET {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(l);
+} dns_server_list RSQUARE_BRACKET {
+ // parsing completed
+}
+
+dns_server_list: dns_server
+ | dns_server_list COMMA dns_server
+ ;
+
+dns_server: LCURLY_BRACKET {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+} dns_server_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+};
+
+sub_dns_server: LCURLY_BRACKET {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(m);
+} dns_server_params RCURLY_BRACKET {
+ // parsing completed
+};
+
+dns_server_params: dns_server_param
+ | dns_server_params COMMA dns_server_param
+ ;
+
+dns_server_param: dns_server_hostname
+ | dns_server_ip_address
+ | dns_server_port
+ | unknown_map_entry
+ ;
+
+dns_server_hostname: HOSTNAME {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ if ($4 != "") {
+ error(@3, "hostname is not yet supported");
+ }
+ ElementPtr elem(new StringElement($4, ctx.loc2pos(@4)));
+ ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("hostname", name);
+ ctx.leave();
+};
+
+dns_server_ip_address: IP_ADDRESS {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ ElementPtr s(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("ip-address", s);
+ ctx.leave();
+};
+
+dns_server_port: PORT COLON INTEGER {
+ if ($3 <= 0 || $3 >= 65536 ) {
+ error(@3, "port must be greater than zero but less than 65536");
+ }
+ ElementPtr i(new IntElement($3, ctx.loc2pos(@3)));
+ ctx.stack_.back()->set("port", i);
+};
+
+// --- end of dns-servers ---------------------------------
+
+
+
+// --- tsig-keys ----------------------------------------
+// "tsig-keys" : [ ... ]
+tsig_keys: TSIG_KEYS {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("tsig-keys", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.TSIG_KEYS);
+} COLON LSQUARE_BRACKET tsig_keys_list RSQUARE_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+sub_tsig_keys: LSQUARE_BRACKET {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(l);
+} tsig_keys_list RSQUARE_BRACKET {
+ // parsing completed
+}
+
+tsig_keys_list: %empty
+ | not_empty_tsig_keys_list
+ ;
+
+not_empty_tsig_keys_list: tsig_key
+ | not_empty_tsig_keys_list COMMA tsig_key
+ ;
+
+tsig_key: LCURLY_BRACKET {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+} tsig_key_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+};
+
+sub_tsig_key: LCURLY_BRACKET {
+ // Parse tsig key list entry map
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.push_back(m);
+} tsig_key_params RCURLY_BRACKET {
+ // parsing completed
+};
+
+
+tsig_key_params: tsig_key_param
+ | tsig_key_params COMMA tsig_key_param
+ ;
+
+tsig_key_param: tsig_key_name
+ | tsig_key_algorithm
+ | tsig_key_digest_bits
+ | tsig_key_secret
+ | unknown_map_entry
+ ;
+
+tsig_key_name: NAME {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ if ($4 == "") {
+ error(@3, "TSIG key name cannot be blank");
+ }
+ ElementPtr elem(new StringElement($4, ctx.loc2pos(@4)));
+ ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("name", name);
+ ctx.leave();
+};
+
+tsig_key_algorithm: ALGORITHM {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ if ($4 == "") {
+ error(@3, "TSIG key algorithm cannot be blank");
+ }
+ ElementPtr elem(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("algorithm", elem);
+ ctx.leave();
+};
+
+tsig_key_digest_bits: DIGEST_BITS COLON INTEGER {
+ if ($3 < 0 || ($3 > 0 && ($3 % 8 != 0))) {
+ error(@3, "TSIG key digest-bits must either be zero or a positive, multiple of eight");
+ }
+ ElementPtr elem(new IntElement($3, ctx.loc2pos(@3)));
+ ctx.stack_.back()->set("digest-bits", elem);
+};
+
+tsig_key_secret: SECRET {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ if ($4 == "") {
+ error(@3, "TSIG key secret cannot be blank");
+ }
+ ElementPtr elem(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("secret", elem);
+ ctx.leave();
+};
+
+
+// --- end of tsig-keys ---------------------------------
+
+
+dhcp6_json_object: DHCP6 {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON value {
+ ctx.stack_.back()->set("Dhcp6", $4);
+ ctx.leave();
+};
+
+dhcp4_json_object: DHCP4 {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON value {
+ ctx.stack_.back()->set("Dhcp4", $4);
+ ctx.leave();
+};
+
+// --- logging entry -----------------------------------------
+
+// This defines the top level "Logging" object. It parses
+// the following "Logging": { ... }. The ... is defined
+// by logging_params
+logging_object: LOGGING {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("Logging", m);
+ ctx.stack_.push_back(m);
+ ctx.enter(ctx.LOGGING);
+} COLON LCURLY_BRACKET logging_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+// This defines the list of allowed parameters that may appear
+// in the top-level Logging object. It can either be a single
+// parameter or several parameters separated by commas.
+logging_params: logging_param
+ | logging_params COMMA logging_param
+ ;
+
+// There's currently only one parameter defined, which is "loggers".
+logging_param: loggers;
+
+// "loggers", the only parameter currently defined in "Logging" object,
+// is "Loggers": [ ... ].
+loggers: LOGGERS {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("loggers", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.LOGGERS);
+} COLON LSQUARE_BRACKET loggers_entries RSQUARE_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+// These are the parameters allowed in loggers: either one logger
+// entry or multiple entries separate by commas.
+loggers_entries: logger_entry
+ | loggers_entries COMMA logger_entry
+ ;
+
+// This defines a single entry defined in loggers in Logging.
+logger_entry: LCURLY_BRACKET {
+ ElementPtr l(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->add(l);
+ ctx.stack_.push_back(l);
+} logger_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+};
+
+logger_params: logger_param
+ | logger_params COMMA logger_param
+ ;
+
+logger_param: name
+ | output_options_list
+ | debuglevel
+ | severity
+ | unknown_map_entry
+ ;
+
+name: NAME {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ ElementPtr name(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("name", name);
+ ctx.leave();
+};
+
+debuglevel: DEBUGLEVEL COLON INTEGER {
+ ElementPtr dl(new IntElement($3, ctx.loc2pos(@3)));
+ ctx.stack_.back()->set("debuglevel", dl);
+};
+severity: SEVERITY {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ ElementPtr sev(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("severity", sev);
+ ctx.leave();
+};
+
+output_options_list: OUTPUT_OPTIONS {
+ ElementPtr l(new ListElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->set("output_options", l);
+ ctx.stack_.push_back(l);
+ ctx.enter(ctx.OUTPUT_OPTIONS);
+} COLON LSQUARE_BRACKET output_options_list_content RSQUARE_BRACKET {
+ ctx.stack_.pop_back();
+ ctx.leave();
+};
+
+output_options_list_content: output_entry
+ | output_options_list_content COMMA output_entry
+ ;
+
+output_entry: LCURLY_BRACKET {
+ ElementPtr m(new MapElement(ctx.loc2pos(@1)));
+ ctx.stack_.back()->add(m);
+ ctx.stack_.push_back(m);
+} output_params RCURLY_BRACKET {
+ ctx.stack_.pop_back();
+};
+
+output_params: output_param
+ | output_params COMMA output_param
+ ;
+
+output_param: OUTPUT {
+ ctx.enter(ctx.NO_KEYWORD);
+} COLON STRING {
+ ElementPtr sev(new StringElement($4, ctx.loc2pos(@4)));
+ ctx.stack_.back()->set("output", sev);
+ ctx.leave();
+};
+
+%%
+
+void
+isc::d2::D2Parser::error(const location_type& loc,
+ const std::string& what)
+{
+ ctx.error(loc, what);
+}
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <d2/d2_config.h>
+#include <d2/d2_simple_parser.h>
+#include <cc/data.h>
+#include <boost/foreach.hpp>
+
+using namespace isc::data;
+
+namespace isc {
+namespace d2 {
+/// @brief This sets of arrays define the default values and
+/// values inherited (derived) between various scopes.
+///
+/// Each of those is documented in @file d2_simple_parser.cc. This
+/// is different than most other comments in Kea code. The reason
+/// for placing those in .cc rather than .h file is that it
+/// is expected to be one centralized place to look at for
+/// the default values. This is expected to be looked at also by
+/// people who are not skilled in C or C++, so they may be
+/// confused with the differences between declaration and definition.
+/// As such, there's one file to look at that hopefully is readable
+/// without any C or C++ skills.
+///
+/// @{
+
+/// @brief This table defines default global values for D2
+///
+/// Some of the global parameters defined in the global scope (i.e. directly
+/// in DhcpDdns) are optional. If not defined, the following values will be
+/// used.
+const SimpleDefaults D2SimpleParser::D2_GLOBAL_DEFAULTS = {
+ { "ip-address", Element::string, "127.0.0.1" },
+ { "port", Element::integer, "53001" },
+ { "dns-server-timeout", Element::integer, "100" }, // in seconds
+ { "ncr-protocol", Element::string, "UDP" },
+ { "ncr-format", Element::string, "JSON" }
+};
+
+/// Supplies defaults for ddns-domoains list elements (i.e. DdnsDomains)
+const SimpleDefaults D2SimpleParser::TSIG_KEY_DEFAULTS = {
+ { "digest-bits", Element::integer, "0" }
+};
+
+/// Supplies defaults for optional values in DDNS domain managers
+/// (e.g. "forward-ddns" and "reverse-ddns").
+/// @note While there are none yet defined, it is highly likely
+/// there will be domain manager defaults added in the future.
+/// This code to set defaults already uses this list, so supporting
+/// values will simply require adding them to this list.
+const SimpleDefaults D2SimpleParser::DDNS_DOMAIN_MGR_DEFAULTS = {
+};
+
+/// Supplies defaults for ddns-domoains list elements (i.e. DdnsDomains)
+const SimpleDefaults D2SimpleParser::DDNS_DOMAIN_DEFAULTS = {
+ { "key-name", Element::string, "" }
+};
+
+/// Supplies defaults for optional values DdnsDomain entries.
+const SimpleDefaults D2SimpleParser::DNS_SERVER_DEFAULTS = {
+ { "hostname", Element::string, "" },
+ { "port", Element::integer, "53" },
+};
+
+/// @}
+
+/// ---------------------------------------------------------------------------
+/// --- end of default values -------------------------------------------------
+/// ---------------------------------------------------------------------------
+
+size_t
+D2SimpleParser::setAllDefaults(isc::data::ElementPtr global) {
+ size_t cnt = 0;
+ // Set global defaults first.
+ cnt = setDefaults(global, D2_GLOBAL_DEFAULTS);
+
+ // If the key list is present, set its members' defaults
+ if (global->find("tsig-keys")) {
+ ConstElementPtr keys = global->get("tsig-keys");
+ cnt += setListDefaults(keys, TSIG_KEY_DEFAULTS);
+ } else {
+ // Not present, so add an empty list.
+ ConstElementPtr list(new ListElement());
+ global->set("tsig-keys", list);
+ cnt++;
+ }
+
+ // Set the forward domain manager defaults.
+ cnt += setManagerDefaults(global, "forward-ddns", DDNS_DOMAIN_MGR_DEFAULTS);
+
+ // Set the reverse domain manager defaults.
+ cnt += setManagerDefaults(global, "reverse-ddns", DDNS_DOMAIN_MGR_DEFAULTS);
+ return (cnt);
+}
+
+size_t
+D2SimpleParser::setDdnsDomainDefaults(ElementPtr domain,
+ const SimpleDefaults& domain_defaults) {
+ size_t cnt = 0;
+
+ // Set the domain's scalar defaults
+ cnt += setDefaults(domain, domain_defaults);
+ if (domain->find("dns-servers")) {
+ // Now add the defaults to its server list.
+ ConstElementPtr servers = domain->get("dns-servers");
+ cnt += setListDefaults(servers, DNS_SERVER_DEFAULTS);
+ }
+
+ return (cnt);
+}
+
+
+size_t
+D2SimpleParser::setManagerDefaults(ElementPtr global,
+ const std::string& mgr_name,
+ const SimpleDefaults& mgr_defaults) {
+ size_t cnt = 0;
+
+ if (!global->find(mgr_name)) {
+ // If it's not present, then default is an empty map
+ ConstElementPtr map(new MapElement());
+ global->set(mgr_name, map);
+ ++cnt;
+ } else {
+ // Get a writable copy of the manager element map
+ ElementPtr mgr =
+ boost::const_pointer_cast<Element>(global->get(mgr_name));
+
+ // Set the manager's scalar defaults first
+ cnt += setDefaults(mgr, mgr_defaults);
+
+ // Get the domain list and set defaults for them.
+ // The domain list may not be present ddns for this
+ // manager is disabled.
+ if (mgr->find("ddns-domains")) {
+ ConstElementPtr domains = mgr->get("ddns-domains");
+ BOOST_FOREACH(ElementPtr domain, domains->listValue()) {
+ // Set the domain's defaults. We can't use setListDefaults()
+ // as this does not handle sub-lists or maps, like server list.
+ cnt += setDdnsDomainDefaults(domain, DDNS_DOMAIN_DEFAULTS);
+ }
+ }
+
+ }
+
+ return (cnt);
+}
+
+};
+};
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef D2_SIMPLE_PARSER_H
+#define D2_SIMPLE_PARSER_H
+
+#include <cc/simple_parser.h>
+
+namespace isc {
+namespace d2 {
+
+/// @brief SimpleParser specialized for D2
+///
+/// This class is a @ref isc::data::SimpleParser dedicated to D2.
+/// In particular, it contains all the default values and names of the
+/// parameters that are to be derived (inherited) between scopes.
+/// For the actual values, see @file d2_simple_parser.cc
+class D2SimpleParser : public data::SimpleParser {
+public:
+
+ /// @brief Sets all defaults for D2 configuration
+ ///
+ /// This method sets global and element defaults.
+ ///
+ /// @param global scope to be filled in with defaults.
+ /// @return number of default values added
+ static size_t setAllDefaults(data::ElementPtr global);
+
+ // see d2_simple_parser.cc for comments for those parameters
+ static const data::SimpleDefaults D2_GLOBAL_DEFAULTS;
+
+ // Defaults for tsig-keys list elements, TSIGKeyInfos
+ static const data::SimpleDefaults TSIG_KEY_DEFAULTS;
+
+ // Defaults for <forward|reverse>-ddns elements, DdnsDomainListMgrs
+ static const data::SimpleDefaults DDNS_DOMAIN_MGR_DEFAULTS;
+
+ // Defaults for ddns-domains list elements, DdnsDomains
+ static const data::SimpleDefaults DDNS_DOMAIN_DEFAULTS;
+
+ // Defaults for dns-servers list elements, DnsServerInfos
+ static const data::SimpleDefaults DNS_SERVER_DEFAULTS;
+
+ /// @brief Adds default values to a DDNS Domain element
+ ///
+ /// Adds the scalar default values to the given DDNS domain
+ /// element, and then adds the DNS Server defaults to the domain's
+ /// server list, "dns-servers".
+ ///
+ /// @param domain DDNS domain element to which defaults should be added
+ /// @param domain_defaults list of default values from which to add
+ /// @return returns the number of default values added
+ static size_t setDdnsDomainDefaults(data::ElementPtr domain,
+ const data::SimpleDefaults&
+ domain_defaults);
+
+ /// @brief Adds default values to a DDNS Domain List Manager
+ ///
+ /// This function looks for the named DDNS domain manager element within
+ /// the given element tree. If it is found, it adds the scalar default
+ /// values to the manager element and then adds the DDNS Domain defaults
+ /// to its domain list, "ddns-domains". If the manager element is not
+ /// found, then an empty map entry is added for it, thus defaulting the
+ /// manager to "disabled".
+ ///
+ /// @param global element tree containgin the DDNS domain manager element
+ /// to which defaults should be
+ /// added
+ /// @param mgr_name name of the manager element within the element tree
+ /// (e.g. "forward-ddns", "reverse-ddns")
+ /// @param mgr_defaults list of default values from which to add
+ /// @return returns the number of default values added
+ static size_t setManagerDefaults(data::ElementPtr global,
+ const std::string& mgr_name,
+ const data::SimpleDefaults& mgr_defaults);
+};
+
+};
+};
+
+#endif
--- /dev/null
+// Generated 201702171216
+// A Bison parser, made by GNU Bison 3.0.4.
+
+// Locations for Bison parsers in C++
+
+// Copyright (C) 2002-2015 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton. Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+/**
+ ** \file location.hh
+ ** Define the isc::d2::location class.
+ */
+
+#ifndef YY_D2_PARSER_LOCATION_HH_INCLUDED
+# define YY_D2_PARSER_LOCATION_HH_INCLUDED
+
+# include "position.hh"
+
+#line 14 "d2_parser.yy" // location.cc:296
+namespace isc { namespace d2 {
+#line 46 "location.hh" // location.cc:296
+ /// Abstract a location.
+ class location
+ {
+ public:
+
+ /// Construct a location from \a b to \a e.
+ location (const position& b, const position& e)
+ : begin (b)
+ , end (e)
+ {
+ }
+
+ /// Construct a 0-width location in \a p.
+ explicit location (const position& p = position ())
+ : begin (p)
+ , end (p)
+ {
+ }
+
+ /// Construct a 0-width location in \a f, \a l, \a c.
+ explicit location (std::string* f,
+ unsigned int l = 1u,
+ unsigned int c = 1u)
+ : begin (f, l, c)
+ , end (f, l, c)
+ {
+ }
+
+
+ /// Initialization.
+ void initialize (std::string* f = YY_NULLPTR,
+ unsigned int l = 1u,
+ unsigned int c = 1u)
+ {
+ begin.initialize (f, l, c);
+ end = begin;
+ }
+
+ /** \name Line and Column related manipulators
+ ** \{ */
+ public:
+ /// Reset initial location to final location.
+ void step ()
+ {
+ begin = end;
+ }
+
+ /// Extend the current location to the COUNT next columns.
+ void columns (int count = 1)
+ {
+ end += count;
+ }
+
+ /// Extend the current location to the COUNT next lines.
+ void lines (int count = 1)
+ {
+ end.lines (count);
+ }
+ /** \} */
+
+
+ public:
+ /// Beginning of the located region.
+ position begin;
+ /// End of the located region.
+ position end;
+ };
+
+ /// Join two locations, in place.
+ inline location& operator+= (location& res, const location& end)
+ {
+ res.end = end.end;
+ return res;
+ }
+
+ /// Join two locations.
+ inline location operator+ (location res, const location& end)
+ {
+ return res += end;
+ }
+
+ /// Add \a width columns to the end position, in place.
+ inline location& operator+= (location& res, int width)
+ {
+ res.columns (width);
+ return res;
+ }
+
+ /// Add \a width columns to the end position.
+ inline location operator+ (location res, int width)
+ {
+ return res += width;
+ }
+
+ /// Subtract \a width columns to the end position, in place.
+ inline location& operator-= (location& res, int width)
+ {
+ return res += -width;
+ }
+
+ /// Subtract \a width columns to the end position.
+ inline location operator- (location res, int width)
+ {
+ return res -= width;
+ }
+
+ /// Compare two location objects.
+ inline bool
+ operator== (const location& loc1, const location& loc2)
+ {
+ return loc1.begin == loc2.begin && loc1.end == loc2.end;
+ }
+
+ /// Compare two location objects.
+ inline bool
+ operator!= (const location& loc1, const location& loc2)
+ {
+ return !(loc1 == loc2);
+ }
+
+ /** \brief Intercept output stream redirection.
+ ** \param ostr the destination output stream
+ ** \param loc a reference to the location to redirect
+ **
+ ** Avoid duplicate information.
+ */
+ template <typename YYChar>
+ inline std::basic_ostream<YYChar>&
+ operator<< (std::basic_ostream<YYChar>& ostr, const location& loc)
+ {
+ unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0;
+ ostr << loc.begin;
+ if (loc.end.filename
+ && (!loc.begin.filename
+ || *loc.begin.filename != *loc.end.filename))
+ ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col;
+ else if (loc.begin.line < loc.end.line)
+ ostr << '-' << loc.end.line << '.' << end_col;
+ else if (loc.begin.column < end_col)
+ ostr << '-' << end_col;
+ return ostr;
+ }
+
+#line 14 "d2_parser.yy" // location.cc:296
+} } // isc::d2
+#line 192 "location.hh" // location.cc:296
+#endif // !YY_D2_PARSER_LOCATION_HH_INCLUDED
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <d2/d2_parser.h>
+#include <d2/parser_context.h>
+#include <exceptions/exceptions.h>
+#include <cc/data.h>
+#include <boost/lexical_cast.hpp>
+#include <fstream>
+#include <limits>
+
+namespace isc {
+namespace d2 {
+
+D2ParserContext::D2ParserContext()
+ : ctx_(NO_KEYWORD), trace_scanning_(false), trace_parsing_(false)
+{
+}
+
+isc::data::ElementPtr
+D2ParserContext::parseString(const std::string& str, ParserType parser_type)
+{
+ scanStringBegin(str, parser_type);
+ return (parseCommon());
+}
+
+isc::data::ElementPtr
+D2ParserContext::parseFile(const std::string& filename, ParserType parser_type) {
+ FILE* f = fopen(filename.c_str(), "r");
+ if (!f) {
+ isc_throw(D2ParseError, "Unable to open file " << filename);
+ }
+ scanFileBegin(f, filename, parser_type);
+ return (parseCommon());
+}
+
+isc::data::ElementPtr
+D2ParserContext::parseCommon() {
+ isc::d2::D2Parser parser(*this);
+ // Uncomment this to get detailed parser logs.
+ // trace_parsing_ = true;
+ parser.set_debug_level(trace_parsing_);
+ try {
+ int res = parser.parse();
+ if (res != 0) {
+ isc_throw(D2ParseError, "Parser abort");
+ }
+ scanEnd();
+ }
+ catch (...) {
+ scanEnd();
+ throw;
+ }
+ if (stack_.size() == 1) {
+ return (stack_[0]);
+ } else {
+ isc_throw(D2ParseError, "Expected exactly one terminal Element expected, found "
+ << stack_.size());
+ }
+}
+
+
+void
+D2ParserContext::error(const isc::d2::location& loc, const std::string& what)
+{
+ isc_throw(D2ParseError, loc << ": " << what);
+}
+
+void
+D2ParserContext::error (const std::string& what)
+{
+ isc_throw(D2ParseError, what);
+}
+
+void
+D2ParserContext::fatal (const std::string& what)
+{
+ isc_throw(D2ParseError, what);
+}
+
+isc::data::Element::Position
+D2ParserContext::loc2pos(isc::d2::location& loc)
+{
+ const std::string& file = *loc.begin.filename;
+ const uint32_t line = loc.begin.line;
+ const uint32_t pos = loc.begin.column;
+ return (isc::data::Element::Position(file, line, pos));
+}
+
+void
+D2ParserContext::enter(const ParserContext& ctx)
+{
+ cstack_.push_back(ctx_);
+ ctx_ = ctx;
+}
+
+void
+D2ParserContext::leave()
+{
+ if (cstack_.empty()) {
+ fatal("unbalanced syntactic context");
+ }
+
+ ctx_ = cstack_.back();
+ cstack_.pop_back();
+}
+
+const std::string
+D2ParserContext::contextName()
+{
+ switch (ctx_) {
+ case NO_KEYWORD:
+ return ("__no keyword__");
+ case CONFIG:
+ return ("toplevel");
+ case DHCPDDNS:
+ return ("DhcpDdns");
+ case TSIG_KEY:
+ return ("tsig-key");
+ case TSIG_KEYS:
+ return ("tsig-keys");
+ case ALGORITHM:
+ return("algorithm");
+ case DIGEST_BITS:
+ return("digest-bits");
+ case SECRET:
+ return("secret");
+ case FORWARD_DDNS:
+ return("forward-ddns");
+ case REVERSE_DDNS:
+ return("reverse-ddns");
+ case DDNS_DOMAIN:
+ return("ddns-domain");
+ case DDNS_DOMAINS:
+ return("ddns-domains");
+ case DNS_SERVER:
+ return("dns-server");
+ case DNS_SERVERS:
+ return("dns-servers");
+ case LOGGING:
+ return ("Logging");
+ case LOGGERS:
+ return ("loggers");
+ case OUTPUT_OPTIONS:
+ return ("output-options");
+ case NCR_PROTOCOL:
+ return ("ncr-protocol");
+ case NCR_FORMAT:
+ return ("ncr-format");
+ default:
+ return ("__unknown__");
+ }
+}
+
+};
+};
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef PARSER_CONTEXT_H
+#define PARSER_CONTEXT_H
+#include <string>
+#include <map>
+#include <vector>
+#include <d2/d2_parser.h>
+#include <d2/parser_context_decl.h>
+#include <exceptions/exceptions.h>
+
+// Tell Flex the lexer's prototype ...
+#define YY_DECL isc::d2::D2Parser::symbol_type d2_parser_lex (D2ParserContext& driver)
+
+// ... and declare it for the parser's sake.
+YY_DECL;
+
+namespace isc {
+namespace d2 {
+
+/// @brief Evaluation error exception raised when trying to parse.
+///
+/// @todo: This probably should be common for Dhcp4 and Dhcp6.
+class D2ParseError : public isc::Exception {
+public:
+ D2ParseError(const char* file, size_t line, const char* what) :
+ isc::Exception(file, line, what) { };
+};
+
+
+/// @brief Evaluation context, an interface to the expression evaluation.
+class D2ParserContext
+{
+public:
+
+ /// @brief Defines currently supported scopes
+ ///
+ /// D2Parser may eventually support multiple levels of parsing scope.
+ /// Currently it supports only the D2 module scope which expects the data
+ /// to be parsed to be a map containing the DhcpDdns element and its
+ /// constituents.
+ ///
+ typedef enum {
+ /// This parser will parse the content as generic JSON.
+ PARSER_JSON,
+
+ ///< Used for parsing top level (contains DhcpDdns, Logging, others)
+ PARSER_DHCPDDNS,
+
+ ///< Used for parsing content of DhcpDdns.
+ PARSER_SUB_DHCPDDNS,
+
+ ///< Used for parsing content of a TSIG key.
+ PARSER_TSIG_KEY,
+
+ ///< Used for pasing a list of TSIG Keys.
+ PARSER_TSIG_KEYS,
+
+ ///< Used for parsing content of a DDNS Domain.
+ PARSER_DDNS_DOMAIN,
+
+ ///< Used for parsing a list a DDNS Domains.
+ PARSER_DDNS_DOMAINS,
+
+ ///< Used for parsing content of a DNS Server.
+ PARSER_DNS_SERVER,
+
+ ///< Used for pasing a list of DNS servers.
+ PARSER_DNS_SERVERS
+ } ParserType;
+
+ /// @brief Default constructor.
+ D2ParserContext();
+
+ /// @brief JSON elements being parsed.
+ std::vector<isc::data::ElementPtr> stack_;
+
+ /// @brief Method called before scanning starts on a string.
+ ///
+ /// @param str string to be parsed
+ /// @param type specifies expected content
+ void scanStringBegin(const std::string& str, ParserType type);
+
+ /// @brief Method called before scanning starts on a file.
+ ///
+ /// @param f stdio FILE pointer
+ /// @param filename file to be parsed
+ /// @param type specifies expected content
+ void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
+
+ /// @brief Method called after the last tokens are scanned.
+ void scanEnd();
+
+ /// @brief Divert input to an include file.
+ ///
+ /// @param filename file to be included
+ void includeFile(const std::string& filename);
+
+ /// @brief Run the parser on the string specified.
+ ///
+ /// This method parses specified string. Depending on the value of
+ /// parser_type, parser may either check only that the input is valid
+ /// JSON, or may do more specific syntax checking. See @ref ParserType
+ /// for supported syntax checkers.
+ ///
+ /// @param str string to be parsed
+ /// @param parser_type specifies expected content
+ /// @return Element structure representing parsed text.
+ isc::data::ElementPtr parseString(const std::string& str,
+ ParserType parser_type);
+
+ /// @brief Run the parser on the file specified.
+ ///
+ /// This method parses specified file. Depending on the value of
+ /// parser_type, parser may either check only that the input is valid
+ /// JSON, or may do more specific syntax checking. See @ref ParserType
+ /// for supported syntax checkers.
+ ///
+ /// @param filename file to be parsed
+ /// @param parser_type specifies expected content
+ /// @return Element structure representing parsed text.
+ isc::data::ElementPtr parseFile(const std::string& filename,
+ ParserType parser_type);
+
+ /// @brief Error handler
+ ///
+ /// @param loc location within the parsed file when experienced a problem.
+ /// @param what string explaining the nature of the error.
+ /// @throw D2ParseError
+ void error(const isc::d2::location& loc, const std::string& what);
+
+ /// @brief Error handler
+ ///
+ /// This is a simplified error reporting tool for reporting
+ /// parsing errors.
+ ///
+ /// @param what string explaining the nature of the error.
+ /// @throw D2ParseError
+ void error(const std::string& what);
+
+ /// @brief Fatal error handler
+ ///
+ /// This is for should not happen but fatal errors.
+ /// Used by YY_FATAL_ERROR macro so required to be static.
+ ///
+ /// @param what string explaining the nature of the error.
+ /// @throw D2ParseError
+ static void fatal(const std::string& what);
+
+ /// @brief Converts bison's position to one understood by isc::data::Element
+ ///
+ /// Convert a bison location into an element position
+ /// (take the begin, the end is lost)
+ ///
+ /// @param loc location in bison format
+ /// @return Position in format accepted by Element
+ isc::data::Element::Position loc2pos(isc::d2::location& loc);
+
+ /// @brief Defines syntactic contexts for lexical tie-ins
+ typedef enum {
+ ///< This one is used in pure JSON mode.
+ NO_KEYWORD,
+
+ ///< Used while parsing top level (contains DhcpDdns, Logging, ...)
+ CONFIG,
+
+ ///< Used while parsing content of DhcpDdns.
+ DHCPDDNS,
+
+ ///< Used while parsing content of a tsig-key
+ TSIG_KEY,
+
+ ///< Used while parsing a list of tsig-keys
+ TSIG_KEYS,
+
+ ///< Used while parsing content of DhcpDdns/tsig-keys/algorithm
+ ALGORITHM,
+
+ ///< Used while parsing content of DhcpDdns/tsig-keys/digest-bits
+ DIGEST_BITS,
+
+ ///< Used while parsing content of DhcpDdns/tsig-keys/secret
+ SECRET,
+
+ ///< Used while parsing content of DhcpDdns/forward-ddns
+ FORWARD_DDNS,
+
+ ///< Used while parsing content of DhcpDdns/reverse-ddns
+ REVERSE_DDNS,
+
+ ///< Used while parsing content of a ddns-domain
+ DDNS_DOMAIN,
+
+ ///< Used while parsing a list of ddns-domains
+ DDNS_DOMAINS,
+
+ ///< Used while parsing content of a dns-server
+ DNS_SERVER,
+
+ ///< Used while parsing content of list of dns-servers
+ DNS_SERVERS,
+
+ ///< Used while parsing content of Logging
+ LOGGING,
+
+ /// Used while parsing Logging/loggers structures.
+ LOGGERS,
+
+ /// Used while parsing Logging/loggers/output_options structures.
+ OUTPUT_OPTIONS,
+
+ /// Used while parsing DhcpDdns/ncr-protocol
+ NCR_PROTOCOL,
+
+ /// Used while parsing DhcpDdns/ncr-format
+ NCR_FORMAT
+
+ } ParserContext;
+
+ /// @brief File name
+ std::string file_;
+
+ /// @brief File name stack
+ std::vector<std::string> files_;
+
+ /// @brief Location of the current token
+ ///
+ /// The lexer will keep updating it. This variable will be useful
+ /// for logging errors.
+ isc::d2::location loc_;
+
+ /// @brief Location stack
+ std::vector<isc::d2::location> locs_;
+
+ /// @brief Lexer state stack
+ std::vector<struct yy_buffer_state*> states_;
+
+ /// @brief sFile (aka FILE)
+ FILE* sfile_;
+
+ /// @brief sFile (aka FILE) stack
+ ///
+ /// This is a stack of files. Typically there's only one file (the
+ /// one being currently parsed), but there may be more if one
+ /// file includes another.
+ std::vector<FILE*> sfiles_;
+
+ /// @brief Current syntactic context
+ ParserContext ctx_;
+
+ /// @brief Enter a new syntactic context
+ ///
+ /// Entering a new syntactic context is useful in several ways.
+ /// First, it allows the parser to avoid conflicts. Second, it
+ /// allows the lexer to return different tokens depending on
+ /// context (e.g. if "name" string is detected, the lexer
+ /// will return STRING token if in JSON mode or NAME if
+ /// in TSIG_KEY mode. Finally, the syntactic context allows the
+ /// error message to be more descriptive if the input string
+ /// does not parse properly.
+ ///
+ /// @param ctx the syntactic context to enter into
+ void enter(const ParserContext& ctx);
+
+ /// @brief Leave a syntactic context
+ ///
+ /// @throw isc::Unexpected if unbalanced
+ void leave();
+
+ /// @brief Get the syntax context name
+ ///
+ /// @return printable name of the context.
+ const std::string contextName();
+
+ private:
+ /// @brief Flag determining scanner debugging.
+ bool trace_scanning_;
+
+ /// @brief Flag determining parser debugging.
+ bool trace_parsing_;
+
+ /// @brief Syntactic context stack
+ std::vector<ParserContext> cstack_;
+
+ /// @brief Common part of parseXXX
+ ///
+ /// @return Element structure representing parsed text.
+ isc::data::ElementPtr parseCommon();
+};
+
+}; // end of isc::eval namespace
+}; // end of isc namespace
+
+#endif
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef D2_PARSER_CONTEXT_DECL_H
+#define D2_PARSER_CONTEXT_DECL_H
+
+/// @file d2/parser_context_decl.h Forward declaration of the ParserContext class
+
+namespace isc {
+namespace d2 {
+
+class D2ParserContext;
+
+}; // end of isc::dhcp namespace
+}; // end of isc namespace
+
+#endif
--- /dev/null
+// Generated 201702171216
+// A Bison parser, made by GNU Bison 3.0.4.
+
+// Positions for Bison parsers in C++
+
+// Copyright (C) 2002-2015 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton. Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+/**
+ ** \file position.hh
+ ** Define the isc::d2::position class.
+ */
+
+#ifndef YY_D2_PARSER_POSITION_HH_INCLUDED
+# define YY_D2_PARSER_POSITION_HH_INCLUDED
+
+# include <algorithm> // std::max
+# include <iostream>
+# include <string>
+
+# ifndef YY_NULLPTR
+# if defined __cplusplus && 201103L <= __cplusplus
+# define YY_NULLPTR nullptr
+# else
+# define YY_NULLPTR 0
+# endif
+# endif
+
+#line 14 "d2_parser.yy" // location.cc:296
+namespace isc { namespace d2 {
+#line 56 "position.hh" // location.cc:296
+ /// Abstract a position.
+ class position
+ {
+ public:
+ /// Construct a position.
+ explicit position (std::string* f = YY_NULLPTR,
+ unsigned int l = 1u,
+ unsigned int c = 1u)
+ : filename (f)
+ , line (l)
+ , column (c)
+ {
+ }
+
+
+ /// Initialization.
+ void initialize (std::string* fn = YY_NULLPTR,
+ unsigned int l = 1u,
+ unsigned int c = 1u)
+ {
+ filename = fn;
+ line = l;
+ column = c;
+ }
+
+ /** \name Line and Column related manipulators
+ ** \{ */
+ /// (line related) Advance to the COUNT next lines.
+ void lines (int count = 1)
+ {
+ if (count)
+ {
+ column = 1u;
+ line = add_ (line, count, 1);
+ }
+ }
+
+ /// (column related) Advance to the COUNT next columns.
+ void columns (int count = 1)
+ {
+ column = add_ (column, count, 1);
+ }
+ /** \} */
+
+ /// File name to which this position refers.
+ std::string* filename;
+ /// Current line number.
+ unsigned int line;
+ /// Current column number.
+ unsigned int column;
+
+ private:
+ /// Compute max(min, lhs+rhs) (provided min <= lhs).
+ static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min)
+ {
+ return (0 < rhs || -static_cast<unsigned int>(rhs) < lhs
+ ? rhs + lhs
+ : min);
+ }
+ };
+
+ /// Add \a width columns, in place.
+ inline position&
+ operator+= (position& res, int width)
+ {
+ res.columns (width);
+ return res;
+ }
+
+ /// Add \a width columns.
+ inline position
+ operator+ (position res, int width)
+ {
+ return res += width;
+ }
+
+ /// Subtract \a width columns, in place.
+ inline position&
+ operator-= (position& res, int width)
+ {
+ return res += -width;
+ }
+
+ /// Subtract \a width columns.
+ inline position
+ operator- (position res, int width)
+ {
+ return res -= width;
+ }
+
+ /// Compare two position objects.
+ inline bool
+ operator== (const position& pos1, const position& pos2)
+ {
+ return (pos1.line == pos2.line
+ && pos1.column == pos2.column
+ && (pos1.filename == pos2.filename
+ || (pos1.filename && pos2.filename
+ && *pos1.filename == *pos2.filename)));
+ }
+
+ /// Compare two position objects.
+ inline bool
+ operator!= (const position& pos1, const position& pos2)
+ {
+ return !(pos1 == pos2);
+ }
+
+ /** \brief Intercept output stream redirection.
+ ** \param ostr the destination output stream
+ ** \param pos a reference to the position to redirect
+ */
+ template <typename YYChar>
+ inline std::basic_ostream<YYChar>&
+ operator<< (std::basic_ostream<YYChar>& ostr, const position& pos)
+ {
+ if (pos.filename)
+ ostr << *pos.filename << ':';
+ return ostr << pos.line << '.' << pos.column;
+ }
+
+#line 14 "d2_parser.yy" // location.cc:296
+} } // isc::d2
+#line 180 "position.hh" // location.cc:296
+#endif // !YY_D2_PARSER_POSITION_HH_INCLUDED
--- /dev/null
+// Generated 201702171216
+// A Bison parser, made by GNU Bison 3.0.4.
+
+// Stack handling for Bison parsers in C++
+
+// Copyright (C) 2002-2015 Free Software Foundation, Inc.
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// As a special exception, you may create a larger work that contains
+// part or all of the Bison parser skeleton and distribute that work
+// under terms of your choice, so long as that work isn't itself a
+// parser generator using the skeleton or a modified version thereof
+// as a parser skeleton. Alternatively, if you modify or redistribute
+// the parser skeleton itself, you may (at your option) remove this
+// special exception, which will cause the skeleton and the resulting
+// Bison output files to be licensed under the GNU General Public
+// License without this special exception.
+
+// This special exception was added by the Free Software Foundation in
+// version 2.2 of Bison.
+
+/**
+ ** \file stack.hh
+ ** Define the isc::d2::stack class.
+ */
+
+#ifndef YY_D2_PARSER_STACK_HH_INCLUDED
+# define YY_D2_PARSER_STACK_HH_INCLUDED
+
+# include <vector>
+
+#line 14 "d2_parser.yy" // stack.hh:132
+namespace isc { namespace d2 {
+#line 46 "stack.hh" // stack.hh:132
+ template <class T, class S = std::vector<T> >
+ class stack
+ {
+ public:
+ // Hide our reversed order.
+ typedef typename S::reverse_iterator iterator;
+ typedef typename S::const_reverse_iterator const_iterator;
+
+ stack ()
+ : seq_ ()
+ {
+ seq_.reserve (200);
+ }
+
+ stack (unsigned int n)
+ : seq_ (n)
+ {}
+
+ inline
+ T&
+ operator[] (unsigned int i)
+ {
+ return seq_[seq_.size () - 1 - i];
+ }
+
+ inline
+ const T&
+ operator[] (unsigned int i) const
+ {
+ return seq_[seq_.size () - 1 - i];
+ }
+
+ /// Steal the contents of \a t.
+ ///
+ /// Close to move-semantics.
+ inline
+ void
+ push (T& t)
+ {
+ seq_.push_back (T());
+ operator[](0).move (t);
+ }
+
+ inline
+ void
+ pop (unsigned int n = 1)
+ {
+ for (; n; --n)
+ seq_.pop_back ();
+ }
+
+ void
+ clear ()
+ {
+ seq_.clear ();
+ }
+
+ inline
+ typename S::size_type
+ size () const
+ {
+ return seq_.size ();
+ }
+
+ inline
+ const_iterator
+ begin () const
+ {
+ return seq_.rbegin ();
+ }
+
+ inline
+ const_iterator
+ end () const
+ {
+ return seq_.rend ();
+ }
+
+ private:
+ stack (const stack&);
+ stack& operator= (const stack&);
+ /// The wrapped container.
+ S seq_;
+ };
+
+ /// Present a slice of the top of a stack.
+ template <class T, class S = stack<T> >
+ class slice
+ {
+ public:
+ slice (const S& stack, unsigned int range)
+ : stack_ (stack)
+ , range_ (range)
+ {}
+
+ inline
+ const T&
+ operator [] (unsigned int i) const
+ {
+ return stack_[range_ - i];
+ }
+
+ private:
+ const S& stack_;
+ unsigned int range_;
+ };
+
+#line 14 "d2_parser.yy" // stack.hh:132
+} } // isc::d2
+#line 156 "stack.hh" // stack.hh:132
+
+#endif // !YY_D2_PARSER_STACK_HH_INCLUDED
AM_CPPFLAGS += $(BOOST_INCLUDES)
AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_top_builddir)/src/bin/d2/tests\"
AM_CPPFLAGS += -DINSTALL_PROG=\"$(abs_top_srcdir)/install-sh\"
+AM_CPPFLAGS += -DCFG_EXAMPLES=\"$(abs_top_srcdir)/doc/examples/ddns\"
CLEANFILES = $(builddir)/interfaces.txt $(builddir)/logger_lockfile
d2_unittests_SOURCES += nc_test_utils.cc nc_test_utils.h
d2_unittests_SOURCES += nc_trans_unittests.cc
d2_unittests_SOURCES += d2_controller_unittests.cc
+d2_unittests_SOURCES += d2_simple_parser_unittest.cc
+d2_unittests_SOURCES += parser_unittest.cc parser_unittest.h
d2_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
d2_unittests_LDFLAGS = $(AM_LDFLAGS) $(CRYPTO_LDFLAGS)
d2_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/libkea-dhcpsrv.la
d2_unittests_LDADD += $(top_builddir)/src/lib/dhcpsrv/testutils/libdhcpsrvtest.la
d2_unittests_LDADD += $(top_builddir)/src/lib/dhcp_ddns/libkea-dhcp_ddns.la
+d2_unittests_LDADD += $(top_builddir)/src/lib/testutils/libkea-testutils.la
d2_unittests_LDADD += $(top_builddir)/src/lib/asiodns/libkea-asiodns.la
d2_unittests_LDADD += $(top_builddir)/src/lib/stats/libkea-stats.la
d2_unittests_LDADD += $(top_builddir)/src/lib/config/libkea-cfgclient.la
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
#include <config/module_spec.h>
#include <d2/d2_config.h>
#include <d2/d2_cfg_mgr.h>
+#include <d2/d2_simple_parser.h>
+#include <d2/parser_context.h>
+#include <d2/tests/parser_unittest.h>
#include <dhcpsrv/testutils/config_result_check.h>
#include <process/testutils/d_test_stubs.h>
#include <test_data_files_config.h>
return (config.str());
}
+
/// @brief Enumeration to select between expected configuration outcomes
enum RunConfigMode {
- SHOULD_PASS,
- SHOULD_FAIL
+ NO_ERROR,
+ SYNTAX_ERROR,
+ LOGIC_ERROR
};
/// @brief Parses a configuration string and tests against a given outcome
///
/// Convenience method which accepts JSON text and an expected pass or fail
- /// outcome. It converts the text into an ElementPtr and passes that to
- /// configuration manager's parseConfig method. It then tests the
- /// parse result against the expected outcome If they do not match it
- /// the method asserts a failure. If they do match, it refreshes the
- /// the D2Params pointer with the newly parsed instance.
+ /// outcome. It uses the D2ParserContext to parse the text under the
+ /// PARSE_SUB_DHCPDDNS context, then adds the D2 defaults to the resultant
+ /// element tree. Assuming that's successful the element tree is passed
+ /// to D2CfgMgr::parseConfig() method.
///
/// @param config_str the JSON configuration text to parse
- /// @param mode indicator if the parsing should fail or not. It defaults
+ /// @param error_type indicates the type error expected, NONE, SYNTAX,
+ /// or LOGIC. SYNTAX errors are emitted by JSON parser, logic errors
+ /// are emitted by element parser(s).
+ /// @param exp_error exact text of the error message expected
/// defaults to SHOULD_PASS.
///
- void runConfig(std::string config_str, RunConfigMode mode=SHOULD_PASS) {
- // We assume the config string is valid JSON.
- ASSERT_TRUE(fromJSON(config_str));
+ /// @return AssertionSuccess if test passes, AssertionFailure otherwise
+ ::testing::AssertionResult runConfigOrFail(const std::string& json,
+ const RunConfigMode mode,
+ const std::string& exp_error) {
+
+ try {
+ // Invoke the JSON parser, casting the returned element tree
+ // into mutable form.
+ D2ParserContext parser_context;
+ data::ElementPtr elem =
+ boost::const_pointer_cast<Element>
+ (parser_context.parseString(json, D2ParserContext::
+ PARSER_SUB_DHCPDDNS));
+
+ // If parsing succeeded when we expected a syntax error, then fail.
+ if (mode == SYNTAX_ERROR) {
+ return ::testing::AssertionFailure()
+ << "Unexpected JSON parsing success"
+ << "\njson: [" << json << " ]";
+ }
- // Parse the configuration and verify we got the expected outcome.
- answer_ = cfg_mgr_->parseConfig(config_set_);
- ASSERT_TRUE(checkAnswer(mode == SHOULD_FAIL));
+ // JSON parsed ok, so add the defaults to the element tree it produced.
+ D2SimpleParser::setAllDefaults(elem);
+ config_set_ = elem;
+ } catch (const std::exception& ex) {
+ // JSON Parsing failed
+ if (exp_error.empty()) {
+ // We did not expect an error, so fail.
+ return ::testing::AssertionFailure()
+ << "Unexpected syntax error:" << ex.what()
+ << "\njson: [" << json << " ]";
+ }
- // Verify that the D2 context can be retrieved and is not null.
- D2CfgContextPtr context;
- ASSERT_NO_THROW(context = cfg_mgr_->getD2CfgContext());
+ if (ex.what() != exp_error) {
+ // Expected an error not the one we got, so fail
+ return ::testing::AssertionFailure()
+ << "Wrong syntax error detected, expected: "
+ << exp_error << ", got: " << ex.what()
+ << "\njson: [" << json << " ]";
+ }
- // Verify that the global scalars have the proper values.
- d2_params_ = context->getD2Params();
- ASSERT_TRUE(d2_params_);
- }
+ // We go the syntax error we expected, so return success
+ return ::testing::AssertionSuccess();
+ }
- /// @brief Check parse result against expected outcome and position info
- ///
- /// This method analyzes the given parsing result against an expected outcome
- /// of SHOULD_PASS or SHOULD_FAIL. If it is expected to fail, the comment
- /// contained within the result is searched for Element::Position information
- /// which should contain the given file name. It does not attempt to verify
- /// the numerical values for line number and col.
- ///
- /// @param answer Element set containing an integer result code and string
- /// comment.
- /// @param mode indicator if the parsing should fail or not.
- /// @param file_name name of the file containing the configuration text
- /// parsed. It defaults to "<string>" which is the value present if the
- /// configuration text did not originate from a file. (i.e. one did not use
- /// isc::data::Element::fromJSONFile() to read the JSON text).
- void
- checkAnswerWithError(isc::data::ConstElementPtr answer,
- RunConfigMode mode, std::string file_name="<string>") {
+ // The JSON parsed ok and we've added the defaults, pass the config
+ // into the Element parser and check for the expected outcome.
+ data::ConstElementPtr answer = cfg_mgr_->parseConfig(config_set_);
+
+ // Extract the result and error text from the answer.
int rcode = 0;
isc::data::ConstElementPtr comment;
comment = isc::config::parseAnswer(rcode, answer);
- if (mode == SHOULD_PASS) {
- if (rcode == 0) {
- return;
+ if (rcode != 0) {
+ // Element Parsing failed.
+ if (exp_error.empty()) {
+ // We didn't expect it to, fail the test.
+ return ::testing::AssertionFailure()
+ << "Unexpected logic error: " << *comment
+ << "\njson: [" << json << " ]";
}
- FAIL() << "Parsing was expected to pass but failed : " << rcode
- << " comment: " << *comment;
+ if (comment->stringValue() != exp_error) {
+ // We 't expect a different error, fail the test.
+ return ::testing::AssertionFailure()
+ << "Wrong logic error detected, expected: "
+ << exp_error << ", got: " << *comment
+ << "\njson: [" << json << " ]";
+ }
+ } else {
+ // Element parsing succeeded.
+ if (!exp_error.empty()) {
+ // It was supposed to fail, so fail the test.
+ return ::testing::AssertionFailure()
+ << "Unexpected logic success, expected error:"
+ << exp_error
+ << "\njson: [" << json << " ]";
+ }
}
- if (rcode == 0) {
- FAIL() << "Parsing was expected to fail but passed : "
- << " comment: " << *comment;
+ // Verify that the D2 context can be retrieved and is not null.
+ D2CfgContextPtr context;
+ context = cfg_mgr_->getD2CfgContext();
+ if (!context) {
+ return ::testing::AssertionFailure() << "D2CfgContext is null";
}
- // Parsing was expected to fail, test for position info.
- if (isc::dhcp::test::errorContainsPosition(answer, file_name)) {
- return;
+ // Verify that the global scalar container has been created.
+ d2_params_ = context->getD2Params();
+ if (!d2_params_) {
+ return ::testing::AssertionFailure() << "D2Params is null";
}
- FAIL() << "Parsing failed as expected but lacks position : " << *comment;
+ return ::testing::AssertionSuccess();
}
+
/// @brief Pointer the D2Params most recently parsed.
D2ParamsPtr d2_params_;
};
+/// @brief Convenience macros for invoking runOrConfig()
+#define RUN_CONFIG_OK(a) (runConfigOrFail(a, NO_ERROR, ""))
+#define SYNTAX_ERROR(a,b) ASSERT_TRUE(runConfigOrFail(a,SYNTAX_ERROR,b))
+#define LOGIC_ERROR(a,b) ASSERT_TRUE(runConfigOrFail(a,LOGIC_ERROR,b))
+
/// @brief Tests that the spec file is valid.
/// Verifies that the DHCP-DDNS configuration specification file
-// is valid.
+/// is valid.
TEST(D2SpecTest, basicSpec) {
ASSERT_NO_THROW(isc::config::
moduleSpecFromFile(specfile("dhcp-ddns.spec")));
}
-/// @brief Convenience function which compares the contents of the given
-/// DnsServerInfo against the given set of values.
-///
-/// It is structured in such a way that each value is checked, and output
-/// is generate for all that do not match.
-///
-/// @param server is a pointer to the server to check against.
-/// @param hostname is the value to compare against server's hostname_.
-/// @param ip_address is the string value to compare against server's
-/// ip_address_.
-/// @param port is the value to compare against server's port.
-///
-/// @return returns true if there is a match across the board, otherwise it
-/// returns false.
-bool checkServer(DnsServerInfoPtr server, const char* hostname,
- const char *ip_address, uint32_t port)
-{
- // Return value, assume its a match.
- bool result = true;
-
- if (!server) {
- EXPECT_TRUE(server);
- return false;
- }
-
- // Check hostname.
- if (server->getHostname() != hostname) {
- EXPECT_EQ(hostname, server->getHostname());
- result = false;
- }
-
- // Check IP address.
- if (server->getIpAddress().toText() != ip_address) {
- EXPECT_EQ(ip_address, server->getIpAddress().toText());
- result = false;
- }
-
- // Check port.
- if (server->getPort() != port) {
- EXPECT_EQ (port, server->getPort());
- result = false;
- }
-
- return (result);
-}
-
-/// @brief Convenience function which compares the contents of the given
-/// TSIGKeyInfo against the given set of values, and that the TSIGKey
-/// member points to a key.
-///
-/// @param key is a pointer to the TSIGKeyInfo instance to verify
-/// @param name is the value to compare against key's name_.
-/// @param algorithm is the string value to compare against key's algorithm.
-/// @param secret is the value to compare against key's secret.
-///
-/// @return returns true if there is a match across the board, otherwise it
-/// returns false.
-bool checkKey(TSIGKeyInfoPtr key, const std::string& name,
- const std::string& algorithm, const std::string& secret,
- uint32_t digestbits = 0) {
- // Return value, assume its a match.
- return (((key) &&
- (key->getName() == name) &&
- (key->getAlgorithm() == algorithm) &&
- (key->getDigestbits() == digestbits) &&
- (key->getSecret() == secret) &&
- (key->getTSIGKey())));
-}
-
-/// @brief Test fixture class for testing DnsServerInfo parsing.
-class TSIGKeyInfoTest : public ConfigParseTest {
-public:
-
- /// @brief Constructor
- TSIGKeyInfoTest() {
- reset();
- }
-
- /// @brief Destructor
- ~TSIGKeyInfoTest() {
- }
-
- /// @brief Wipe out the current storage and parser and replace
- /// them with new ones.
- void reset() {
- keys_.reset(new TSIGKeyInfoMap());
- parser_.reset(new TSIGKeyInfoParser("test", keys_));
- }
-
- /// @brief Storage for "committing" keys.
- TSIGKeyInfoMapPtr keys_;
-
- /// @brief Pointer to the current parser instance.
- isc::dhcp::ParserPtr parser_;
-};
-
-/// @brief Test fixture class for testing DnsServerInfo parsing.
-class DnsServerInfoTest : public ConfigParseTest {
-public:
-
- /// @brief Constructor
- DnsServerInfoTest() {
- reset();
- }
-
- /// @brief Destructor
- ~DnsServerInfoTest() {
- }
-
- /// @brief Wipe out the current storage and parser and replace
- /// them with new ones.
- void reset() {
- servers_.reset(new DnsServerInfoStorage());
- parser_.reset(new DnsServerInfoParser("test", servers_));
- }
-
- /// @brief Storage for "committing" servers.
- DnsServerInfoStoragePtr servers_;
-
- /// @brief Pointer to the current parser instance.
- isc::dhcp::ParserPtr parser_;
-};
-
-
-/// @brief Test fixture class for testing DDnsDomain parsing.
-class DdnsDomainTest : public ConfigParseTest {
-public:
-
- /// @brief Constructor
- DdnsDomainTest() {
- reset();
- }
-
- /// @brief Destructor
- ~DdnsDomainTest() {
- }
-
- /// @brief Wipe out the current storage and parser and replace
- /// them with new ones.
- void reset() {
- keys_.reset(new TSIGKeyInfoMap());
- domains_.reset(new DdnsDomainMap());
- parser_.reset(new DdnsDomainParser("test", domains_, keys_));
- }
-
- /// @brief Add TSIGKeyInfos to the key map
- ///
- /// @param name the name of the key
- /// @param algorithm the algorithm of the key
- /// @param secret the secret value of the key
- void addKey(const std::string& name, const std::string& algorithm,
- const std::string& secret) {
- TSIGKeyInfoPtr key_info(new TSIGKeyInfo(name, algorithm, secret));
- (*keys_)[name]=key_info;
- }
-
- /// @brief Storage for "committing" domains.
- DdnsDomainMapPtr domains_;
-
- /// @brief Storage for TSIGKeys
- TSIGKeyInfoMapPtr keys_;
-
- /// @brief Pointer to the current parser instance.
- isc::dhcp::ParserPtr parser_;
-};
-
/// @brief Tests a basic valid configuration for D2Param.
TEST_F(D2CfgMgrTest, validParamsEntry) {
// Verify that ip_address can be valid v4 address.
std::string config = makeParamsConfigString ("192.0.0.1", 777, 333,
"UDP", "JSON");
- runConfig(config);
+ RUN_CONFIG_OK(config);
EXPECT_EQ(isc::asiolink::IOAddress("192.0.0.1"),
d2_params_->getIpAddress());
// Verify that ip_address can be valid v6 address.
config = makeParamsConfigString ("3001::5", 777, 333, "UDP", "JSON");
- runConfig(config);
+ RUN_CONFIG_OK(config);
// Verify that the global scalars have the proper values.
EXPECT_EQ(isc::asiolink::IOAddress("3001::5"),
/// Currently they are all optional.
TEST_F(D2CfgMgrTest, defaultValues) {
+ ElementPtr defaults = isc::d2::test::parseJSON("{ }");
+ ASSERT_NO_THROW(D2SimpleParser::setAllDefaults(defaults));
+
// Check that omitting ip_address gets you its default
std::string config =
"{"
"\"reverse-ddns\" : {} "
"}";
- runConfig(config);
- EXPECT_EQ(isc::asiolink::IOAddress(D2Params::DFT_IP_ADDRESS),
- d2_params_->getIpAddress());
+ RUN_CONFIG_OK(config);
+ ConstElementPtr deflt;
+ ASSERT_NO_THROW(deflt = defaults->get("ip-address"));
+ ASSERT_TRUE(deflt);
+ EXPECT_EQ(deflt->stringValue(), d2_params_->getIpAddress().toText());
// Check that omitting port gets you its default
config =
"\"reverse-ddns\" : {} "
"}";
- runConfig(config);
- EXPECT_EQ(D2Params::DFT_PORT, d2_params_->getPort());
+ RUN_CONFIG_OK(config);
+ ASSERT_NO_THROW(deflt = defaults->get("port"));
+ ASSERT_TRUE(deflt);
+ EXPECT_EQ(deflt->intValue(), d2_params_->getPort());
// Check that omitting timeout gets you its default
config =
"\"reverse-ddns\" : {} "
"}";
- runConfig(config);
- EXPECT_EQ(D2Params::DFT_DNS_SERVER_TIMEOUT,
- d2_params_->getDnsServerTimeout());
+ RUN_CONFIG_OK(config);
+ ASSERT_NO_THROW(deflt = defaults->get("dns-server-timeout"));
+ ASSERT_TRUE(deflt);
+ EXPECT_EQ(deflt->intValue(), d2_params_->getDnsServerTimeout());
- // Check that protocol timeout gets you its default
+ // Check that omitting protocol gets you its default
config =
"{"
" \"ip-address\": \"192.0.0.1\" , "
"\"reverse-ddns\" : {} "
"}";
- runConfig(config);
- EXPECT_EQ(dhcp_ddns::stringToNcrProtocol(D2Params::DFT_NCR_PROTOCOL),
+ RUN_CONFIG_OK(config);
+ ASSERT_NO_THROW(deflt = defaults->get("ncr-protocol"));
+ ASSERT_TRUE(deflt);
+ EXPECT_EQ(dhcp_ddns::stringToNcrProtocol(deflt->stringValue()),
d2_params_->getNcrProtocol());
- // Check that format timeout gets you its default
+ // Check that omitting format gets you its default
config =
"{"
" \"ip-address\": \"192.0.0.1\" , "
"\"reverse-ddns\" : {} "
"}";
- runConfig(config);
- EXPECT_EQ(dhcp_ddns::stringToNcrFormat(D2Params::DFT_NCR_FORMAT),
+ RUN_CONFIG_OK(config);
+ ASSERT_NO_THROW(deflt = defaults->get("ncr-format"));
+ ASSERT_TRUE(deflt);
+ EXPECT_EQ(dhcp_ddns::stringToNcrFormat(deflt->stringValue()),
d2_params_->getNcrFormat());
}
"\"bogus-param\" : true "
"}";
- runConfig(config, SHOULD_FAIL);
+ SYNTAX_ERROR(config, "<string>:1.181-193: got unexpected "
+ "keyword \"bogus-param\" in DhcpDdns map.");
// Check that unsupported top level objects fails. For
// D2 these fail as they are not in the parse order.
"\"bogus-object-two\" : {} "
"}";
- runConfig(config, SHOULD_FAIL);
+ SYNTAX_ERROR(config, "<string>:1.139-156: got unexpected"
+ " keyword \"bogus-object-one\" in DhcpDdns map.");
}
// Cannot use IPv4 ANY address
std::string config = makeParamsConfigString ("0.0.0.0", 777, 333,
"UDP", "JSON");
- runConfig(config, SHOULD_FAIL);
+ LOGIC_ERROR(config, "IP address cannot be \"0.0.0.0\" (<string>:1:17)");
// Cannot use IPv6 ANY address
config = makeParamsConfigString ("::", 777, 333, "UDP", "JSON");
- runConfig(config, SHOULD_FAIL);
+ LOGIC_ERROR(config, "IP address cannot be \"::\" (<string>:1:17)");
// Cannot use port 0
config = makeParamsConfigString ("127.0.0.1", 0, 333, "UDP", "JSON");
- runConfig(config, SHOULD_FAIL);
+ SYNTAX_ERROR(config, "<string>:1.40: port must be greater than zero but less than 65536");
// Cannot use dns server timeout of 0
config = makeParamsConfigString ("127.0.0.1", 777, 0, "UDP", "JSON");
- runConfig(config, SHOULD_FAIL);
+ SYNTAX_ERROR(config, "<string>:1.69: dns-server-timeout"
+ " must be greater than zero");
// Invalid protocol
config = makeParamsConfigString ("127.0.0.1", 777, 333, "BOGUS", "JSON");
- runConfig(config, SHOULD_FAIL);
+ SYNTAX_ERROR(config, "<string>:1.92-98: syntax error,"
+ " unexpected constant string, expecting UDP or TCP");
// Unsupported protocol
config = makeParamsConfigString ("127.0.0.1", 777, 333, "TCP", "JSON");
- runConfig(config, SHOULD_FAIL);
+ LOGIC_ERROR(config, "ncr-protocol : TCP is not yet supported"
+ " (<string>:1:92)");
// Invalid format
config = makeParamsConfigString ("127.0.0.1", 777, 333, "UDP", "BOGUS");
- runConfig(config, SHOULD_FAIL);
+ SYNTAX_ERROR(config, "<string>:1.115-121: syntax error,"
+ " unexpected constant string, expecting JSON");
}
/// @brief Tests the enforcement of data validation when parsing TSIGKeyInfos.
" \"ncr-format\": \"JSON\", "
"\"tsig-keys\": ["
"{"
- " \"name\": \"d2_key.tmark.org\" , "
+ " \"name\": \"d2_key.example.com\" , "
" \"algorithm\": \"hmac-md5\" , "
" \"secret\": \"LSWXnfkKZjdPJI5QxlpnfQ==\" "
"},"
"],"
"\"forward-ddns\" : {"
"\"ddns-domains\": [ "
- "{ \"name\": \"tmark.org\" , "
- " \"key-name\": \"d2_key.tmark.org\" , "
+ "{ \"name\": \"example.com\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.0.1\" } , "
" { \"ip-address\": \"127.0.0.2\" } , "
"\"reverse-ddns\" : {"
"\"ddns-domains\": [ "
"{ \"name\": \" 0.168.192.in.addr.arpa.\" , "
- " \"key-name\": \"d2_key.tmark.org\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.1.1\" } , "
" { \"ip-address\": \"127.0.2.1\" } , "
" ] } "
"] } }";
- ASSERT_TRUE(fromJSON(config));
-
- // Verify that we can parse the configuration.
- answer_ = cfg_mgr_->parseConfig(config_set_);
- ASSERT_TRUE(checkAnswer(0));
+ // Should parse without error.
+ RUN_CONFIG_OK(config);
// Verify that the D2 context can be retrieved and is not null.
D2CfgContextPtr context;
"\"tsig-keys\": [] ,"
"\"forward-ddns\" : {"
"\"ddns-domains\": [ "
- "{ \"name\": \"tmark.org\" , "
+ "{ \"name\": \"example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.0.1\" } "
" ] } "
", "
- "{ \"name\": \"one.tmark.org\" , "
+ "{ \"name\": \"one.example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.0.2\" } "
" ] } "
"\"reverse-ddns\" : {} "
"}";
-
- ASSERT_TRUE(fromJSON(config));
// Verify that we can parse the configuration.
- answer_ = cfg_mgr_->parseConfig(config_set_);
- ASSERT_TRUE(checkAnswer(0));
+ RUN_CONFIG_OK(config);
// Verify that the D2 context can be retrieved and is not null.
D2CfgContextPtr context;
DdnsDomainPtr match;
// Verify that an exact match works.
- EXPECT_TRUE(cfg_mgr_->matchForward("tmark.org", match));
- EXPECT_EQ("tmark.org", match->getName());
+ EXPECT_TRUE(cfg_mgr_->matchForward("example.com", match));
+ EXPECT_EQ("example.com", match->getName());
- // Verify that search is case-insensitive.
- EXPECT_TRUE(cfg_mgr_->matchForward("TMARK.ORG", match));
- EXPECT_EQ("tmark.org", match->getName());
+ // Verify that search is case insensitive.
+ EXPECT_TRUE(cfg_mgr_->matchForward("EXAMPLE.COM", match));
+ EXPECT_EQ("example.com", match->getName());
// Verify that an exact match works.
- EXPECT_TRUE(cfg_mgr_->matchForward("one.tmark.org", match));
- EXPECT_EQ("one.tmark.org", match->getName());
+ EXPECT_TRUE(cfg_mgr_->matchForward("one.example.com", match));
+ EXPECT_EQ("one.example.com", match->getName());
// Verify that a FQDN for sub-domain matches.
- EXPECT_TRUE(cfg_mgr_->matchForward("blue.tmark.org", match));
- EXPECT_EQ("tmark.org", match->getName());
+ EXPECT_TRUE(cfg_mgr_->matchForward("blue.example.com", match));
+ EXPECT_EQ("example.com", match->getName());
// Verify that a FQDN for sub-domain matches.
- EXPECT_TRUE(cfg_mgr_->matchForward("red.one.tmark.org", match));
- EXPECT_EQ("one.tmark.org", match->getName());
+ EXPECT_TRUE(cfg_mgr_->matchForward("red.one.example.com", match));
+ EXPECT_EQ("one.example.com", match->getName());
// Verify that an FQDN with no match, returns the wild card domain.
EXPECT_TRUE(cfg_mgr_->matchForward("shouldbe.wildcard", match));
"\"tsig-keys\": [] ,"
"\"forward-ddns\" : {"
"\"ddns-domains\": [ "
- "{ \"name\": \"tmark.org\" , "
+ "{ \"name\": \"example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.0.1\" } "
" ] } "
", "
- "{ \"name\": \"one.tmark.org\" , "
+ "{ \"name\": \"one.example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.0.2\" } "
" ] } "
"\"reverse-ddns\" : {} "
" }";
- ASSERT_TRUE(fromJSON(config));
-
// Verify that we can parse the configuration.
- answer_ = cfg_mgr_->parseConfig(config_set_);
- ASSERT_TRUE(checkAnswer(0));
+ RUN_CONFIG_OK(config);
// Verify that the D2 context can be retrieved and is not null.
D2CfgContextPtr context;
DdnsDomainPtr match;
// Verify that full or partial matches, still match.
- EXPECT_TRUE(cfg_mgr_->matchForward("tmark.org", match));
- EXPECT_EQ("tmark.org", match->getName());
+ EXPECT_TRUE(cfg_mgr_->matchForward("example.com", match));
+ EXPECT_EQ("example.com", match->getName());
- EXPECT_TRUE(cfg_mgr_->matchForward("blue.tmark.org", match));
- EXPECT_EQ("tmark.org", match->getName());
+ EXPECT_TRUE(cfg_mgr_->matchForward("blue.example.com", match));
+ EXPECT_EQ("example.com", match->getName());
- EXPECT_TRUE(cfg_mgr_->matchForward("red.one.tmark.org", match));
- EXPECT_EQ("one.tmark.org", match->getName());
+ EXPECT_TRUE(cfg_mgr_->matchForward("red.one.example.com", match));
+ EXPECT_EQ("one.example.com", match->getName());
// Verify that a FQDN with no match, fails to match.
EXPECT_FALSE(cfg_mgr_->matchForward("shouldbe.wildcard", match));
"\"reverse-ddns\" : {} "
"}";
- ASSERT_TRUE(fromJSON(config));
-
// Verify that we can parse the configuration.
- answer_ = cfg_mgr_->parseConfig(config_set_);
- ASSERT_TRUE(checkAnswer(0));
+ RUN_CONFIG_OK(config);
// Verify that the D2 context can be retrieved and is not null.
D2CfgContextPtr context;
// Verify that wild card domain is returned for any FQDN.
DdnsDomainPtr match;
- EXPECT_TRUE(cfg_mgr_->matchForward("tmark.org", match));
+ EXPECT_TRUE(cfg_mgr_->matchForward("example.com", match));
EXPECT_EQ("*", match->getName());
EXPECT_TRUE(cfg_mgr_->matchForward("shouldbe.wildcard", match));
EXPECT_EQ("*", match->getName());
" ] } "
"] } }";
- ASSERT_TRUE(fromJSON(config));
-
// Verify that we can parse the configuration.
- answer_ = cfg_mgr_->parseConfig(config_set_);
- ASSERT_TRUE(checkAnswer(0));
+ RUN_CONFIG_OK(config);
// Verify that the D2 context can be retrieved and is not null.
D2CfgContextPtr context;
}
/// @brief Tests D2 config parsing against a wide range of config permutations.
+///
+/// It tests for both syntax errors that the JSON parsing (D2ParserContext)
+/// should detect as well as post-JSON parsing logic errors generated by
+/// the Element parsers (i.e...SimpleParser/DhcpParser derivations)
+///
+///
/// It iterates over all of the test configurations described in given file.
/// The file content is JSON specialized to this test. The format of the file
/// is:
///
/// # Each test has:
/// # 1. description - optional text description
-/// # 2. should-fail - bool indicator if parsing is expected to file
-/// # (defaults to false)
-/// # 3. data - configuration text to parse
+/// # 2. syntax-error - error JSON parser should emit (omit if none)
+/// # 3. logic-error - error element parser(s) should emit (omit if none)
+/// # 4. data - configuration text to parse
/// #
/// "description" : "<text describing test>",
-/// "should_fail" : <true|false> ,
+/// "syntax-error" : "<exact text from JSON parser including position>" ,
+/// "logic-error" : "<exact text from element parser including position>" ,
/// "data" :
/// {
/// # configuration elements here
}
// Read in each test For each test, read:
+ //
// 1. description - optional text description
- // 2. should-fail - bool indicator if parsing is expected to file (defaults
- // to false
+ // 2. syntax-error or logic-error or neither
// 3. data - configuration text to parse
- //
- // Next attempt to parse the configuration by passing it into
- // D2CfgMgr::parseConfig(). Then check the parsing outcome against the
- // expected outcome as given by should-fail.
+ // 4. convert data into JSON text
+ // 5. submit JSON for parsing
isc::data::ConstElementPtr test;
ASSERT_TRUE(tests->get("test-list"));
BOOST_FOREACH(test, tests->get("test-list")->listValue()) {
-
// Grab the description.
std::string description = "<no desc>";
isc::data::ConstElementPtr elem = test->get("description");
elem->getValue(description);
}
- // Grab the outcome flag, should-fail, defaults to false if it's
- // not specified.
- bool should_fail = false;
- elem = test->get("should-fail");
- if (elem) {
- elem->getValue(should_fail);
+ // Grab the expected error message, if there is one.
+ std::string expected_error = "";
+ RunConfigMode mode = NO_ERROR;
+ elem = test->get("syntax-error");
+ if (elem) {
+ elem->getValue(expected_error);
+ mode = SYNTAX_ERROR;
+ } else {
+ elem = test->get("logic-error");
+ if (elem) {
+ elem->getValue(expected_error);
+ mode = LOGIC_ERROR;
+ }
}
// Grab the test's configuration data.
ASSERT_TRUE(data) << "No data for test: "
<< " : " << test->getPosition();
- // Attempt to parse the configuration. We verify that we get the expected
- // outcome, and if it was supposed to fail if the explanation contains
- // position information.
- checkAnswerWithError(cfg_mgr_->parseConfig(data),
- (should_fail ? SHOULD_FAIL : SHOULD_PASS),
- test_file);
+ // Convert the test data back to JSON text, then submit it for parsing.
+ stringstream os;
+ data->toJSON(os);
+ EXPECT_TRUE(runConfigOrFail(os.str(), mode, expected_error))
+ << " failed for test: " << test->getPosition() << std::endl;
}
}
+
} // end of anonymous namespace
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
#include <d2/d2_controller.h>
#include <d2/d2_process.h>
#include <process/spec_config.h>
+#include <d2/tests/nc_test_utils.h>
#include <process/testutils/d_test_stubs.h>
#include <boost/pointer_cast.hpp>
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
#include <d2/d2_process.h>
#include <dhcp_ddns/ncr_io.h>
#include <process/testutils/d_test_stubs.h>
+#include <d2/tests/nc_test_utils.h>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
"\"ip-address\" : \"1.1.1.1\" , "
"\"port\" : 5031, "
"\"tsig-keys\": ["
- "{ \"name\": \"d2_key.tmark.org\" , "
+ "{ \"name\": \"d2_key.example.com\" , "
" \"algorithm\": \"HMAC-MD5\" ,"
" \"secret\": \"LSWXnfkKZjdPJI5QxlpnfQ==\" "
"} ],"
"\"forward-ddns\" : {"
"\"ddns-domains\": [ "
- "{ \"name\": \"tmark.org\" , "
- " \"key-name\": \"d2_key.tmark.org\" , "
+ "{ \"name\": \"example.com\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.0.101\" } "
"] } ] }, "
"\"reverse-ddns\" : {"
"\"ddns-domains\": [ "
"{ \"name\": \" 0.168.192.in.addr.arpa.\" , "
- " \"key-name\": \"d2_key.tmark.org\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
" \"dns-servers\" : [ "
" { \"ip-address\": \"127.0.0.101\" , "
" \"port\": 100 } ] } "
" \"change-type\" : 0 , "
" \"forward-change\" : true , "
" \"reverse-change\" : false , "
- " \"fqdn\" : \"fish.tmark.org\" , "
+ " \"fqdn\" : \"fish.example.com\" , "
" \"ip-address\" : \"192.168.2.1\" , "
" \"dhcid\" : \"010203040A7F8E3D\" , "
" \"lease-expires-on\" : \"20130121132405\" , "
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.com/MPL/2.0/.
+
+#include <config.h>
+#include <gtest/gtest.h>
+#include <d2/d2_simple_parser.h>
+#include <d2/tests/parser_unittest.h>
+#include <cc/data.h>
+
+#include <boost/lexical_cast.hpp>
+
+using namespace isc;
+using namespace isc::data;
+using namespace isc::d2;
+
+namespace {
+
+/// @brief Checks if specified element matches the given integer default
+///
+/// @param element defaulted element to check
+/// @param deflt SimpleDefault which supplied the default value
+void checkIntegerValue(const ConstElementPtr& element,
+ const SimpleDefault& deflt) {
+ ASSERT_TRUE(element);
+
+ // Verify it is an integer.
+ ASSERT_EQ(Element::integer, element->getType());
+
+ // Turn default value string into an int.
+ int64_t default_value = 0;
+ ASSERT_NO_THROW(default_value = boost::lexical_cast<int64_t>(deflt.value_));
+
+ // Verify it has the expected value.
+ EXPECT_EQ(default_value, element->intValue());
+}
+
+/// @brief Checks if specified element matches the given boolean default
+///
+/// @param element defaulted element to check
+/// @param deflt SimpleDefault which supplied the default valaue
+void checkBooleanValue(const ConstElementPtr& element,
+ const SimpleDefault& deflt) {
+ ASSERT_TRUE(element);
+
+ // Verify it is a bool.
+ ASSERT_EQ(Element::boolean, element->getType());
+
+ // Turn default value string into a bool.
+ bool default_value = false;
+ ASSERT_NO_THROW(boost::lexical_cast<bool>(deflt.value_));
+
+ // Verify it has the expected value.
+ EXPECT_EQ(default_value, element->boolValue());
+}
+
+/// @brief Checks if specified element matches the given string default
+///
+/// @param element defaulted element to check
+/// @param deflt SimpleDefault which supplied the default valaue
+void checkStringValue(const ConstElementPtr& element,
+ const SimpleDefault& deflt) {
+ ASSERT_TRUE(element);
+
+ // Verify it's a string
+ ASSERT_EQ(Element::string, element->getType());
+
+ // Verify it has the expected value
+ EXPECT_EQ(deflt.value_, element->stringValue());
+ }
+
+/// TSIGKeyInfo against the given set of values, and that the TSIGKey
+/// member points to a key.
+///
+/// @param key is a pointer to the TSIGKeyInfo instance to verify
+/// @param name is the value to compare against key's name_.
+/// @param algorithm is the string value to compare against key's algorithm.
+/// @param secret is the value to compare against key's secret.
+///
+/// @return returns true if there is a match across the board, otherwise it
+/// returns false.
+bool checkKey(TSIGKeyInfoPtr key, const std::string& name,
+ const std::string& algorithm, const std::string& secret,
+ uint32_t digestbits = 0) {
+ // Return value, assume its a match.
+ return (((key) &&
+ (key->getName() == name) &&
+ (key->getAlgorithm() == algorithm) &&
+ (key->getDigestbits() == digestbits) &&
+ (key->getSecret() == secret) &&
+ (key->getTSIGKey())));
+}
+
+/// @brief Convenience function which compares the contents of the given
+/// DnsServerInfo against the given set of values.
+///
+/// It is structured in such a way that each value is checked, and output
+/// is generated for all that do not match.
+///
+/// @param server is a pointer to the server to check against.
+/// @param hostname is the value to compare against server's hostname_.
+/// @param ip_address is the string value to compare against server's
+/// ip_address_.
+/// @param port is the value to compare against server's port.
+///
+/// @return returns true if there is a match across the board, otherwise it
+/// returns false.
+bool checkServer(DnsServerInfoPtr server, const char* hostname,
+ const char *ip_address, uint32_t port)
+{
+ // Return value, assume its a match.
+ bool result = true;
+
+ if (!server) {
+ EXPECT_TRUE(server);
+ return false;
+ }
+
+ // Check hostname.
+ if (server->getHostname() != hostname) {
+ EXPECT_EQ(hostname, server->getHostname());
+ result = false;
+ }
+
+ // Check IP address.
+ if (server->getIpAddress().toText() != ip_address) {
+ EXPECT_EQ(ip_address, server->getIpAddress().toText());
+ result = false;
+ }
+
+ // Check port.
+ if (server->getPort() != port) {
+ EXPECT_EQ (port, server->getPort());
+ result = false;
+ }
+
+ return (result);
+}
+
+/// @brief Base class test fixture for testing JSON and element parsing
+/// for D2 configuration elements. It combines the three phases of
+/// configuration parsing normally orchestrated by D2CfgMgr:
+/// 1. Submit the JSON text to the JSON parser
+/// 2. Add defaults to the element tree produced by the JSON parser
+/// 3. Pass the element tree into the appropriate SimpleParser derivation
+/// to parse the element tree into D2 objects.
+class D2SimpleParserTest : public ::testing::Test {
+public:
+ /// @brief Constructor
+ ///
+ /// @param parser_type specifies the parsing starting point at which
+ /// the JSON parser should begin. It defaults to PARSER_JSON. See @c
+ /// D2ParserContext::ParserType for all possible values.
+ D2SimpleParserTest(const D2ParserContext::ParserType&
+ parser_type = D2ParserContext::PARSER_JSON)
+ : parser_type_(parser_type) {
+ reset();
+ }
+
+ /// @brief Destructor
+ virtual ~D2SimpleParserTest() {
+ reset();
+ }
+
+ /// @brief Parses JSON text and compares the results against an expected
+ /// outcome.
+ ///
+ /// The JSON text is submitted to the D2ParserContext for parsing. Any
+ /// errors emitted here are caught and compared against the expected
+ /// error or flagged as unexpected.
+ /// Next, the virtual method, setDefaults()is invoked. his method should
+ /// be used by derivations to add default values to the element tree
+ /// produced by the JSON parser.
+ /// Lastly, it passes the element tree into the virtual method,
+ /// parseElement(). This method should be used by derivations to create
+ /// the appropriate element parser to parse the element tree into the
+ /// appropriate D2 object(s).
+ ///
+ /// @param json JSON text to parse
+ /// @param exp_error exact text of the error message expected or ""
+ /// if parsing should succeed.
+ ::testing::AssertionResult parseOrFail(const std::string& json,
+ const std::string& exp_error) {
+ try {
+ // Free up objects created by previous invocation
+ reset();
+
+ // Submit JSON text to JSON parser. We convert the result to
+ // a mutable element tree to allow defaults to be added.
+ D2ParserContext context;
+ data::ElementPtr elem = boost::const_pointer_cast<Element>
+ (context.parseString(json, parser_type_));
+ // Add any defaults
+ setDefaults(elem);
+
+ // Now pares the element tree into object(s).
+ parseElement(elem);
+ } catch (const std::exception& ex) {
+ std::string caught_error = ex.what();
+ if (exp_error.empty()) {
+ return ::testing::AssertionFailure()
+ << "Unexpected error: " << caught_error
+ << "\n json: [" << json << "]";
+ }
+
+ if (exp_error != caught_error) {
+ return ::testing::AssertionFailure()
+ << "Wrong error detected, expected: "
+ << exp_error << ", got: " << caught_error
+ << "\n json: [" << json << "]";
+ }
+ return ::testing::AssertionSuccess();
+ }
+
+ if (!exp_error.empty()) {
+ return ::testing::AssertionFailure()
+ << "Unexpected parsing success "
+ << exp_error << "\n json: [" << json << "]";
+ }
+
+ return ::testing::AssertionSuccess();
+ }
+
+
+protected:
+ /// @brief Free up objects created by element parsing
+ /// This method is invoked at the beginning of @c parseOrFail() to
+ /// ensure any D2 object(s) that were created by a prior invocation are
+ /// destroyed. This permits parsing to be conducted more than once
+ /// in the same test.
+ virtual void reset(){};
+
+ /// @brief Adds default values to the given element tree
+ ///
+ /// Derivations are expected to use the appropriate methods in
+ /// D2SimpleParser to add defaults values.
+ ///
+ /// @param config element tree in which defaults should be added
+ /// @return the number of default items added to the tree
+ virtual size_t setDefaults(data::ElementPtr config) {
+ static_cast<void>(config);
+ return (0);
+ }
+
+ /// @brief Parses a given element tree into D2 object(s)
+ ///
+ /// Derivations are expected to create the appropriate element
+ /// parser and pass it the element tree for parsing. Any object(s)
+ /// created should likely be saved for content verification
+ /// outside of this method.
+ ///
+ /// @param config element tree to parse
+ virtual void parseElement(data::ConstElementPtr config) {
+ static_cast<void>(config);
+ }
+
+ D2ParserContext::ParserType parser_type_;
+};
+
+/// @brief Convenience macros for calling parseOrFail
+#define PARSE_OK(a) EXPECT_TRUE((parseOrFail(a, "")))
+#define PARSE_FAIL(a,b) EXPECT_TRUE((parseOrFail(a, b)))
+
+// This test checks if global defaults are properly set for D2.
+TEST_F(D2SimpleParserTest, globalD2Defaults) {
+
+ ElementPtr empty = isc::d2::test::parseJSON("{ }");
+ size_t num = 0;
+
+ EXPECT_NO_THROW(num = D2SimpleParser::setAllDefaults(empty));
+
+ // We expect 5 parameters to be inserted.
+ EXPECT_EQ(num, 8);
+
+ // Let's go over all parameters we have defaults for.
+ BOOST_FOREACH(SimpleDefault deflt, D2SimpleParser::D2_GLOBAL_DEFAULTS) {
+ ConstElementPtr x;
+ ASSERT_NO_THROW(x = empty->get(deflt.name_));
+
+ EXPECT_TRUE(x);
+ if (x) {
+ if (deflt.type_ == Element::integer) {
+ checkIntegerValue(x, deflt);
+ } else if (deflt.type_ == Element::boolean) {
+ checkBooleanValue(x, deflt);
+ } else if (deflt.type_ == Element::string) {
+ checkStringValue(x, deflt);
+ } else {
+ // add them if we need to. Like what do you if it's a map?
+ ADD_FAILURE() << "default type not supported:" << deflt.name_
+ << " ,type: " << deflt.type_;
+ }
+ }
+ }
+}
+
+/// @brief Test fixture class for testing TSIGKeyInfo parsing.
+class TSIGKeyInfoParserTest : public D2SimpleParserTest {
+public:
+ /// @brief Constructor
+ TSIGKeyInfoParserTest()
+ : D2SimpleParserTest(D2ParserContext::PARSER_TSIG_KEY) {
+ }
+
+ /// @brief Free up the keys created by parsing
+ virtual void reset() {
+ key_.reset();
+ };
+
+ /// @brief Destructor
+ virtual ~TSIGKeyInfoParserTest() {
+ reset();
+ };
+
+ /// @brief Adds TSIG Key default values to the given TSIG Key element
+ ///
+ /// @param config TSIG Key element to which defaults should be added
+ ///
+ /// @return the number of default items added to the tree
+ size_t setDefaults(data::ElementPtr config) {
+ return (SimpleParser::setDefaults(config, D2SimpleParser::
+ TSIG_KEY_DEFAULTS));
+ }
+
+ /// @brief Attempts to parse the given element into a TSIGKeyInfo
+ ///
+ /// Assumes the given element is a Map containing the attributes for
+ /// a TSIG Key. If parsing is successful the new TSIGKeyInfo instance
+ /// is retained in the member, key_;
+ ///
+ /// @param config element to parse
+ void parseElement(data::ConstElementPtr config) {
+ TSIGKeyInfoParser parser;
+ key_ = parser.parse(config);
+ }
+
+ /// @brief Retains the TSIGKeyInfo created by a successful parsing
+ TSIGKeyInfoPtr key_;
+};
+
+
+/// @brief Test fixture class for testing TSIGKeyInfo list parsing.
+class TSIGKeyInfoListParserTest : public D2SimpleParserTest {
+public:
+ /// @brief Constructor
+ TSIGKeyInfoListParserTest()
+ : D2SimpleParserTest(D2ParserContext::PARSER_TSIG_KEYS) {
+ }
+
+ /// @brief Destructor
+ virtual ~TSIGKeyInfoListParserTest() {
+ reset();
+ }
+
+ /// @brief Free up the keys created by parsing
+ virtual void reset() {
+ keys_.reset();
+ };
+
+ /// @brief Adds TSIG Key default values to a list of TSIG Key elements
+ ///
+ /// @param config list of TSIG Key elements to which defaults should be
+ /// added
+ ///
+ /// @return the number of default items added to the tree
+ size_t setDefaults(data::ElementPtr config) {
+ return (SimpleParser::setListDefaults(config, D2SimpleParser::
+ TSIG_KEY_DEFAULTS));
+ }
+
+ /// @brief Attempts to parse the given element into a list of TSIGKeyInfos
+ ///
+ /// Assumes the given element is a list containing one or more TSIG Keys
+ /// elements. If parsing is successful the list of TSIGKeyInfo instances
+ /// is retained in the member, keys_;
+ ///
+ /// @param config element to parse
+ void parseElement(data::ConstElementPtr config) {
+ TSIGKeyInfoListParser parser;
+ keys_ = parser.parse(config);
+ }
+
+ /// @brief Retains the TSIGKeyInfos created by a successful parsing
+ TSIGKeyInfoMapPtr keys_;
+};
+
+/// @brief Test fixture class for testing DnsServerInfo parsing.
+class DnsServerInfoParserTest : public D2SimpleParserTest {
+public:
+ /// @brief Constructor
+ DnsServerInfoParserTest()
+ : D2SimpleParserTest(D2ParserContext::PARSER_DNS_SERVER) {
+ }
+
+ /// @brief Destructor
+ virtual ~DnsServerInfoParserTest() {
+ reset();
+ }
+
+ /// @brief Free up the server created by parsing
+ virtual void reset() {
+ server_.reset();
+ }
+
+ /// @brief Adds DNS Server default values to the given DNS Server element
+ ///
+ /// @param config DNS Server element to which defaults should be added
+ ///
+ /// @return the number of default items added to the tree
+ virtual size_t setDefaults(data::ElementPtr config) {
+ return (SimpleParser::setDefaults(config, D2SimpleParser::
+ DNS_SERVER_DEFAULTS));
+ }
+
+ /// @brief Attempts to parse the given element into a DnsServerInfo
+ ///
+ /// Assumes the given element is a map containing the attributes for
+ /// a DNS Server. If parsing is successful the new DnsServerInfo instance
+ /// is retained in the member, server_;
+ ///
+ /// @param config element to parse
+ virtual void parseElement(data::ConstElementPtr config) {
+ DnsServerInfoParser parser;
+ server_ = parser.parse(config);
+ }
+
+ /// @brief Retains the DnsServerInfo created by a successful parsing
+ DnsServerInfoPtr server_;
+};
+
+/// @brief Test fixture class for testing DnsServerInfoList parsing.
+class DnsServerInfoListParserTest : public D2SimpleParserTest {
+public:
+ /// @brief Constructor
+ DnsServerInfoListParserTest()
+ : D2SimpleParserTest(D2ParserContext::PARSER_DNS_SERVERS) {
+ }
+
+ /// @brief Destructor
+ virtual ~DnsServerInfoListParserTest() {
+ reset();
+ }
+
+ /// @brief Free up the servers created by parsing
+ virtual void reset() {
+ servers_.reset();
+ }
+
+ /// @brief Adds DNS Server default values to a list of DNS Server elements
+ ///
+ /// @param config list of DNS Server elements to which defaults should be
+ /// added
+ ///
+ /// @return the number of default items added to the tree
+ virtual size_t setDefaults(data::ElementPtr config) {
+ return (SimpleParser::setListDefaults(config, D2SimpleParser::
+ DNS_SERVER_DEFAULTS));
+ }
+
+ /// @brief Attempts to parse the given element into a list of DnsServerInfos
+ ///
+ /// Assumes the given element is a list containing one or more DNS Servers
+ /// elements. If parsing is successful the list of DnsServerInfo instances
+ /// is retained in the member, keys_;
+ ///
+ /// @param config element to parse
+ virtual void parseElement(data::ConstElementPtr config) {
+ DnsServerInfoListParser parser;
+ servers_ = parser.parse(config);
+ }
+
+ /// @brief Retains the DnsServerInfos created by a successful parsing
+ DnsServerInfoStoragePtr servers_;
+};
+
+
+/// @brief Test fixture class for testing DDnsDomain parsing.
+class DdnsDomainParserTest : public D2SimpleParserTest {
+public:
+
+ /// @brief Constructor
+ DdnsDomainParserTest(const D2ParserContext::ParserType& parser_type
+ = D2ParserContext::PARSER_DDNS_DOMAIN)
+ : D2SimpleParserTest(parser_type), keys_(new TSIGKeyInfoMap()) {
+ }
+
+ /// @brief Destructor
+ virtual ~DdnsDomainParserTest() {
+ reset();
+ }
+
+ /// @brief Free up the domain created by parsing
+ virtual void reset() {
+ domain_.reset();
+ }
+
+ /// @brief Add TSIGKeyInfos to the key map
+ ///
+ /// @param name the name of the key
+ /// @param algorithm the algorithm of the key
+ /// @param secret the secret value of the key
+ void addKey(const std::string& name, const std::string& algorithm,
+ const std::string& secret) {
+ TSIGKeyInfoPtr key_info(new TSIGKeyInfo(name, algorithm, secret));
+ (*keys_)[name]=key_info;
+ }
+
+ /// @brief Adds DDNS Domain values to the given DDNS Domain element
+ ///
+ /// @param config DDNS Domain element to which defaults should be added
+ ///
+ /// @return the number of default items added to the tree
+ virtual size_t setDefaults(data::ElementPtr config) {
+ return (D2SimpleParser::setDdnsDomainDefaults(config, D2SimpleParser::
+ DDNS_DOMAIN_DEFAULTS));
+ }
+
+ /// @brief Attempts to parse the given element into a DdnsDomain
+ ///
+ /// Assumes the given element is a map containing the attributes for
+ /// a DDNS Domain. If parsing is successful the new DdnsDomain instance
+ /// is retained in the member, server_;
+ ///
+ /// @param config element to parse
+ virtual void parseElement(data::ConstElementPtr config) {
+ DdnsDomainParser parser;
+ domain_ = parser.parse(config, keys_);
+ }
+
+ /// @brief Retains the DdnsDomain created by a successful parsing
+ DdnsDomainPtr domain_;
+
+ /// @brief Storage for TSIGKeys, used by DdnsDomainParser to validate
+ /// domain keys
+ TSIGKeyInfoMapPtr keys_;
+};
+
+class DdnsDomainListParserTest : public DdnsDomainParserTest {
+public:
+ /// @brief Constructor
+ DdnsDomainListParserTest()
+ // We need the list context type to parse lists correctly
+ : DdnsDomainParserTest(D2ParserContext::PARSER_DDNS_DOMAINS) {
+ }
+
+ /// @brief Destructor
+ virtual ~DdnsDomainListParserTest() {
+ reset();
+ }
+
+ /// @brief Free up domains created by parsing
+ virtual void reset() {
+ domains_.reset();
+ }
+
+ /// @brief Adds DDNS Domain default values to a list of DDNS Domain elements
+ ///
+ /// @param config list of DDNS Domain elements to which defaults should be
+ /// added
+ ///
+ /// @return the number of default items added to the tree
+ virtual size_t setDefaults(data::ElementPtr config) {
+ size_t cnt = 0;
+ // We don't use SimpleParser::setListDefaults() as this does
+ // not handle sub-lists or sub-maps
+ BOOST_FOREACH(ElementPtr domain, config->listValue()) {
+ cnt += D2SimpleParser::
+ setDdnsDomainDefaults(domain, D2SimpleParser::
+ DDNS_DOMAIN_DEFAULTS);
+ }
+
+ return (cnt);
+ }
+
+ /// @brief Attempts to parse the given element into a list of DdnsDomains
+ ///
+ /// Assumes the given element is a list containing one or more DDNS Domains
+ /// elements. If parsing is successful the list of DdnsDomain instances
+ /// is retained in the member, keys_;
+ ///
+ /// @param config element to parse
+ virtual void parseElement(data::ConstElementPtr config) {
+ DdnsDomainListParser parser;
+ domains_ = parser.parse(config, keys_);
+ }
+
+ /// @brief Retains the DdnsDomains created by a successful parsing
+ DdnsDomainMapPtr domains_;
+};
+
+/// @brief Tests the enforcement of data validation when parsing TSIGKeyInfos.
+/// It verifies that:
+/// 1. Name cannot be blank.
+/// 2. Algorithm cannot be blank.
+/// 3. Secret cannot be blank.
+TEST_F(TSIGKeyInfoParserTest, invalidEntry) {
+
+ // Name cannot be blank.
+ std::string config = "{"
+ " \"name\": \"\" , "
+ " \"algorithm\": \"HMAC-MD5\" , "
+ " \"secret\": \"LSWXnfkKZjdPJI5QxlpnfQ==\" "
+ "}";
+ PARSE_FAIL(config, "<string>:1.9: TSIG key name cannot be blank");
+
+ // Algorithm cannot be be blank.
+ config = "{"
+ " \"name\": \"d2_key_one\" , "
+ " \"algorithm\": \"\" , "
+ " \"secret\": \"LSWXnfkKZjdPJI5QxlpnfQ==\" "
+ "}";
+ PARSE_FAIL(config, "<string>:1.38: TSIG key algorithm cannot be blank");
+
+ // Algorithm must be a valid algorithm
+ config = "{"
+ " \"name\": \"d2_key_one\" , "
+ " \"algorithm\": \"bogus\" , "
+ " \"secret\": \"LSWXnfkKZjdPJI5QxlpnfQ==\" "
+ "}";
+ PARSE_FAIL(config, "tsig-key : Unknown TSIG Key algorithm:"
+ " bogus (<string>:1:40)");
+
+ // Secret cannot be blank
+ config = "{"
+ " \"name\": \"d2_key_one\" , "
+ " \"algorithm\": \"HMAC-MD5\" , "
+ " \"secret\": \"\" "
+ "}";
+ PARSE_FAIL(config, "<string>:1.62: TSIG key secret cannot be blank");
+
+ // Secret must be valid for algorithm
+ config = "{"
+ " \"name\": \"d2_key_one\" , "
+ " \"algorithm\": \"HMAC-MD5\" , "
+ " \"digest-bits\": 120 , "
+ " \"secret\": \"bogus\" "
+ "}";
+ PARSE_FAIL(config, "Cannot make TSIGKey: Incomplete input for base64:"
+ " bogus (<string>:1:1)");
+}
+
+
+/// @brief Verifies that TSIGKeyInfo parsing creates a proper TSIGKeyInfo
+/// when given a valid combination of entries.
+TEST_F(TSIGKeyInfoParserTest, validEntry) {
+ // Valid entries for TSIG key, all items are required.
+ std::string config = "{"
+ " \"name\": \"d2_key_one\" , "
+ " \"algorithm\": \"HMAC-MD5\" , "
+ " \"digest-bits\": 120 , "
+ " \"secret\": \"dGhpcyBrZXkgd2lsbCBtYXRjaA==\" "
+ "}";
+ // Verify that it parses.
+ PARSE_OK(config);
+ ASSERT_TRUE(key_);
+
+ // Verify the key contents.
+ EXPECT_TRUE(checkKey(key_, "d2_key_one", "HMAC-MD5",
+ "dGhpcyBrZXkgd2lsbCBtYXRjaA==", 120));
+}
+
+/// @brief Verifies that attempting to parse an invalid list of TSIGKeyInfo
+/// entries is detected.
+TEST_F(TSIGKeyInfoListParserTest, invalidTSIGKeyList) {
+ // Construct a list of keys with an invalid key entry.
+ std::string config = "["
+ " { \"name\": \"key1\" , "
+ " \"algorithm\": \"HMAC-MD5\" ,"
+ " \"digest-bits\": 120 , "
+ " \"secret\": \"GWG/Xfbju4O2iXGqkSu4PQ==\" "
+ " },"
+ // this entry has an invalid algorithm
+ " { \"name\": \"key2\" , "
+ " \"algorithm\": \"\" ,"
+ " \"digest-bits\": 120 , "
+ " \"secret\": \"GWG/Xfbju4O2iXGqkSu4PQ==\" "
+ " },"
+ " { \"name\": \"key3\" , "
+ " \"algorithm\": \"HMAC-MD5\" ,"
+ " \"secret\": \"GWG/Xfbju4O2iXGqkSu4PQ==\" "
+ " }"
+ " ]";
+
+ PARSE_FAIL(config, "<string>:1.151: TSIG key algorithm cannot be blank");
+}
+
+/// @brief Verifies that attempting to parse an invalid list of TSIGKeyInfo
+/// entries is detected.
+TEST_F(TSIGKeyInfoListParserTest, duplicateTSIGKey) {
+ // Construct a list of keys with an invalid key entry.
+ std::string config = "["
+ " { \"name\": \"key1\" , "
+ " \"algorithm\": \"HMAC-MD5\" ,"
+ " \"digest-bits\": 120 , "
+ " \"secret\": \"GWG/Xfbju4O2iXGqkSu4PQ==\" "
+ " },"
+ " { \"name\": \"key2\" , "
+ " \"algorithm\": \"HMAC-MD5\" ,"
+ " \"digest-bits\": 120 , "
+ " \"secret\": \"GWG/Xfbju4O2iXGqkSu4PQ==\" "
+ " },"
+ " { \"name\": \"key1\" , "
+ " \"algorithm\": \"HMAC-MD5\" ,"
+ " \"secret\": \"GWG/Xfbju4O2iXGqkSu4PQ==\" "
+ " }"
+ " ]";
+
+ PARSE_FAIL(config,
+ "Duplicate TSIG key name specified : key1 (<string>:1:239)");
+}
+
+/// @brief Verifies a valid list of TSIG Keys parses correctly.
+/// Also verifies that all of the supported algorithm names work.
+TEST_F(TSIGKeyInfoListParserTest, validTSIGKeyList) {
+ // Construct a valid list of keys.
+ std::string config = "["
+ " { \"name\": \"key1\" , "
+ " \"algorithm\": \"HMAC-MD5\" ,"
+ " \"digest-bits\": 80 , "
+ " \"secret\": \"dGhpcyBrZXkgd2lsbCBtYXRjaA==\" "
+ " },"
+ " { \"name\": \"key2\" , "
+ " \"algorithm\": \"HMAC-SHA1\" ,"
+ " \"digest-bits\": 80 , "
+ " \"secret\": \"dGhpcyBrZXkgd2lsbCBtYXRjaA==\" "
+ " },"
+ " { \"name\": \"key3\" , "
+ " \"algorithm\": \"HMAC-SHA256\" ,"
+ " \"digest-bits\": 128 , "
+ " \"secret\": \"dGhpcyBrZXkgd2lsbCBtYXRjaA==\" "
+ " },"
+ " { \"name\": \"key4\" , "
+ " \"algorithm\": \"HMAC-SHA224\" ,"
+ " \"digest-bits\": 112 , "
+ " \"secret\": \"dGhpcyBrZXkgd2lsbCBtYXRjaA==\" "
+ " },"
+ " { \"name\": \"key5\" , "
+ " \"algorithm\": \"HMAC-SHA384\" ,"
+ " \"digest-bits\": 192 , "
+ " \"secret\": \"dGhpcyBrZXkgd2lsbCBtYXRjaA==\" "
+ " },"
+ " { \"name\": \"key6\" , "
+ " \"algorithm\": \"HMAC-SHA512\" ,"
+ " \"digest-bits\": 256 , "
+ " \"secret\": \"dGhpcyBrZXkgd2lsbCBtYXRjaA==\" "
+ " }"
+ " ]";
+
+ PARSE_OK(config);
+ ASSERT_TRUE(keys_);
+
+ std::string ref_secret = "dGhpcyBrZXkgd2lsbCBtYXRjaA==";
+ // Verify the correct number of keys are present
+ int count = keys_->size();
+ ASSERT_EQ(6, count);
+
+ // Find the 1st key and retrieve it.
+ TSIGKeyInfoMap::iterator gotit = keys_->find("key1");
+ ASSERT_TRUE(gotit != keys_->end());
+ TSIGKeyInfoPtr& key = gotit->second;
+
+ // Verify the key contents.
+ EXPECT_TRUE(checkKey(key, "key1", TSIGKeyInfo::HMAC_MD5_STR,
+ ref_secret, 80));
+
+ // Find the 2nd key and retrieve it.
+ gotit = keys_->find("key2");
+ ASSERT_TRUE(gotit != keys_->end());
+ key = gotit->second;
+
+ // Verify the key contents.
+ EXPECT_TRUE(checkKey(key, "key2", TSIGKeyInfo::HMAC_SHA1_STR,
+ ref_secret, 80));
+
+ // Find the 3rd key and retrieve it.
+ gotit = keys_->find("key3");
+ ASSERT_TRUE(gotit != keys_->end());
+ key = gotit->second;
+
+ // Verify the key contents.
+ EXPECT_TRUE(checkKey(key, "key3", TSIGKeyInfo::HMAC_SHA256_STR,
+ ref_secret, 128));
+
+ // Find the 4th key and retrieve it.
+ gotit = keys_->find("key4");
+ ASSERT_TRUE(gotit != keys_->end());
+ key = gotit->second;
+
+ // Verify the key contents.
+ EXPECT_TRUE(checkKey(key, "key4", TSIGKeyInfo::HMAC_SHA224_STR,
+ ref_secret, 112));
+
+ // Find the 5th key and retrieve it.
+ gotit = keys_->find("key5");
+ ASSERT_TRUE(gotit != keys_->end());
+ key = gotit->second;
+
+ // Verify the key contents.
+ EXPECT_TRUE(checkKey(key, "key5", TSIGKeyInfo::HMAC_SHA384_STR,
+ ref_secret, 192));
+
+ // Find the 6th key and retrieve it.
+ gotit = keys_->find("key6");
+ ASSERT_TRUE(gotit != keys_->end());
+ key = gotit->second;
+
+ // Verify the key contents.
+ EXPECT_TRUE(checkKey(key, "key6", TSIGKeyInfo::HMAC_SHA512_STR,
+ ref_secret, 256));
+}
+
+/// @brief Tests the enforcement of data validation when parsing DnsServerInfos.
+/// It verifies that:
+/// 1. Specifying both a hostname and an ip address is not allowed.
+/// 2. Specifying both blank a hostname and blank ip address is not allowed.
+/// 3. Specifying a negative port number is not allowed.
+
+TEST_F(DnsServerInfoParserTest, invalidEntry) {
+ // Create a config in which both host and ip address are supplied.
+ // Verify that parsing fails.
+ std::string config = "{ \"hostname\": \"pegasus.example\", "
+ " \"ip-address\": \"127.0.0.1\", "
+ " \"port\": 100} ";
+ PARSE_FAIL(config, "<string>:1.13: hostname is not yet supported");
+
+
+ // Neither host nor ip address supplied
+ // Verify that builds fails.
+ config = "{ \"hostname\": \"\", "
+ " \"ip-address\": \"\", "
+ " \"port\": 100} ";
+ PARSE_FAIL(config, "Dns Server must specify one or the other"
+ " of hostname or IP address (<string>:1:1)");
+
+ // Create a config with a negative port number.
+ // Verify that build fails.
+ config = "{ \"hostname\": \"\", "
+ " \"ip-address\": \"192.168.5.6\" ,"
+ " \"port\": -100 }";
+ PARSE_FAIL(config, "<string>:1.60-63: port must be greater than zero but less than 65536");
+}
+
+
+/// @brief Verifies that DnsServerInfo parsing creates a proper DnsServerInfo
+/// when given a valid combination of entries.
+/// It verifies that:
+/// 1. A DnsServerInfo entry is correctly made, when given only a hostname.
+/// 2. A DnsServerInfo entry is correctly made, when given ip address and port.
+/// 3. A DnsServerInfo entry is correctly made, when given only an ip address.
+TEST_F(DnsServerInfoParserTest, validEntry) {
+ /// @todo When resolvable hostname is supported you'll need this test.
+ /// // Valid entries for dynamic host
+ /// std::string config = "{ \"hostname\": \"pegasus.example\" }";
+ /// ASSERT_TRUE(fromJSON(config));
+
+ /// // Verify that it builds and commits without throwing.
+ /// ASSERT_NO_THROW(parser_->build(config_set_));
+ /// ASSERT_NO_THROW(parser_->commit());
+
+ /// //Verify the correct number of servers are present
+ /// int count = servers_->size();
+ /// EXPECT_EQ(1, count);
+
+ /// Verify the server exists and has the correct values.
+ /// DnsServerInfoPtr server = (*servers_)[0];
+ /// EXPECT_TRUE(checkServer(server, "pegasus.example",
+ /// DnsServerInfo::EMPTY_IP_STR,
+ /// DnsServerInfo::STANDARD_DNS_PORT));
+
+ /// // Start over for a new test.
+ /// reset();
+
+ // Valid entries for static ip
+ std::string config = " { \"hostname\" : \"\", "
+ " \"ip-address\": \"127.0.0.1\" , "
+ " \"port\": 100 }";
+ PARSE_OK(config);
+ ASSERT_TRUE(server_);
+ EXPECT_TRUE(checkServer(server_, "", "127.0.0.1", 100));
+
+ // Valid entries for static ip, no port
+ // This will fail without invoking set defaults
+ config = " { \"ip-address\": \"192.168.2.5\" }";
+ PARSE_OK(config);
+ ASSERT_TRUE(server_);
+ EXPECT_TRUE(checkServer(server_, "", "192.168.2.5",
+ DnsServerInfo::STANDARD_DNS_PORT));
+}
+
+/// @brief Verifies that attempting to parse an invalid list of DnsServerInfo
+/// entries is detected.
+TEST_F(DnsServerInfoListParserTest, invalidServerList) {
+ // Construct a list of servers with an invalid server entry.
+ std::string config = "[ { \"ip-address\": \"127.0.0.1\" }, "
+ "{ \"ip-address\": \"\" }, "
+ "{ \"ip-address\": \"127.0.0.2\" } ]";
+ PARSE_FAIL(config, "Dns Server must specify one or the other"
+ " of hostname or IP address (<string>:1:34)");
+ ASSERT_FALSE(servers_);
+}
+
+/// @brief Verifies that a list of DnsServerInfo entries parses correctly given
+/// a valid configuration.
+TEST_F(DnsServerInfoListParserTest, validServerList) {
+ // Create a valid list of servers.
+ std::string config = "[ { \"ip-address\": \"127.0.0.1\" }, "
+ "{ \"ip-address\": \"127.0.0.2\" }, "
+ "{ \"ip-address\": \"127.0.0.3\" } ]";
+ PARSE_OK(config);
+
+ // Verify that the server storage contains the correct number of servers.
+ ASSERT_EQ(3, servers_->size());
+
+ // Verify the first server exists and has the correct values.
+ DnsServerInfoPtr server = (*servers_)[0];
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.1",
+ DnsServerInfo::STANDARD_DNS_PORT));
+
+ // Verify the second server exists and has the correct values.
+ server = (*servers_)[1];
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.2",
+ DnsServerInfo::STANDARD_DNS_PORT));
+
+ // Verify the third server exists and has the correct values.
+ server = (*servers_)[2];
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.3",
+ DnsServerInfo::STANDARD_DNS_PORT));
+}
+
+/// @brief Tests the enforcement of data validation when parsing DdnsDomains.
+/// It verifies that:
+/// 1. Domain storage cannot be null when constructing a DdnsDomainParser.
+/// 2. The name entry is not optional.
+/// 3. The server list may not be empty.
+/// 4. That a mal-formed server entry is detected.
+/// 5. That an undefined key name is detected.
+TEST_F(DdnsDomainParserTest, invalidDomain) {
+ // Create a domain configuration without a name
+ std::string config = "{ \"key-name\": \"d2_key.example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.1\" , "
+ " \"port\": 100 },"
+ " { \"ip-address\": \"127.0.0.2\" , "
+ " \"port\": 200 },"
+ " { \"ip-address\": \"127.0.0.3\" , "
+ " \"port\": 300 } ] } ";
+ PARSE_FAIL(config, "String parameter name not found(<string>:1:1)");
+
+ // Create a domain configuration with an empty server list.
+ config = "{ \"name\": \"example.com\" , "
+ " \"key-name\": \"\" , "
+ " \"dns-servers\" : [ "
+ " ] } ";
+ PARSE_FAIL(config, "<string>:1.69: syntax error, unexpected ], expecting {");
+
+ // Create a domain configuration with a mal-formed server entry.
+ config = "{ \"name\": \"example.com\" , "
+ " \"key-name\": \"\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.3\" , "
+ " \"port\": -1 } ] } ";
+ PARSE_FAIL(config, "<string>:1.111-112: port must be greater than zero but less than 65536");
+
+ // Create a domain configuration without an defined key name
+ config = "{ \"name\": \"example.com\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.3\" , "
+ " \"port\": 300 } ] } ";
+ PARSE_FAIL(config, "DdnsDomain : example.com specifies"
+ " an undefined key: d2_key.example.com (<string>:1:41)");
+}
+
+/// @brief Verifies the basics of parsing of a DdnsDomain.
+TEST_F(DdnsDomainParserTest, validDomain) {
+ // Add a TSIG key to the test key map, so key validation will pass.
+ addKey("d2_key.example.com", "HMAC-MD5", "GWG/Xfbju4O2iXGqkSu4PQ==");
+
+ // Create a valid domain configuration entry containing three valid
+ // servers.
+ std::string config =
+ "{ \"name\": \"example.com\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.1\" , "
+ " \"port\": 100 },"
+ " { \"ip-address\": \"127.0.0.2\" , "
+ " \"port\": 200 },"
+ " { \"ip-address\": \"127.0.0.3\" , "
+ " \"port\": 300 } ] } ";
+ PARSE_OK(config);
+
+ // Domain should exist
+ ASSERT_TRUE(domain_);
+
+ // Verify the name and key_name values.
+ EXPECT_EQ("example.com", domain_->getName());
+ EXPECT_EQ("d2_key.example.com", domain_->getKeyName());
+ ASSERT_TRUE(domain_->getTSIGKeyInfo());
+ ASSERT_TRUE(domain_->getTSIGKeyInfo()->getTSIGKey());
+
+ // Verify that the server list exists and contains the correct number of
+ // servers.
+ const DnsServerInfoStoragePtr& servers = domain_->getServers();
+ EXPECT_TRUE(servers);
+ EXPECT_EQ(3, servers->size());
+
+ // Fetch each server and verify its contents.
+ DnsServerInfoPtr server = (*servers)[0];
+ EXPECT_TRUE(server);
+
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.1", 100));
+
+ server = (*servers)[1];
+ EXPECT_TRUE(server);
+
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.2", 200));
+
+ server = (*servers)[2];
+ EXPECT_TRUE(server);
+
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.3", 300));
+}
+
+/// @brief Tests the fundamentals of parsing DdnsDomain lists.
+/// This test verifies that given a valid domain list configuration
+/// it will accurately parse and populate each domain in the list.
+TEST_F(DdnsDomainListParserTest, validList) {
+ // Add keys to key map so key validation passes.
+ addKey("d2_key.example.com", "HMAC-MD5", "GWG/Xfbju4O2iXGqkSu4PQ==");
+ addKey("d2_key.billcat.net", "HMAC-MD5", "GWG/Xfbju4O2iXGqkSu4PQ==");
+
+ // Create a valid domain list configuration, with two domains
+ // that have three servers each.
+ std::string config =
+ "[ "
+ "{ \"name\": \"example.com\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.1\" , "
+ " \"port\": 100 },"
+ " { \"ip-address\": \"127.0.0.2\" , "
+ " \"port\": 200 },"
+ " { \"ip-address\": \"127.0.0.3\" , "
+ " \"port\": 300 } ] } "
+ ", "
+ "{ \"name\": \"billcat.net\" , "
+ " \"key-name\": \"d2_key.billcat.net\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.4\" , "
+ " \"port\": 400 },"
+ " { \"ip-address\": \"127.0.0.5\" , "
+ " \"port\": 500 },"
+ " { \"ip-address\": \"127.0.0.6\" , "
+ " \"port\": 600 } ] } "
+ "] ";
+
+ // Verify that the domain list parses without error.
+ PARSE_OK(config);
+ ASSERT_TRUE(domains_);
+ EXPECT_EQ(2, domains_->size());
+
+ // Verify that the first domain exists and can be retrieved.
+ DdnsDomainMap::iterator gotit = domains_->find("example.com");
+ ASSERT_TRUE(gotit != domains_->end());
+ DdnsDomainPtr& domain = gotit->second;
+
+ // Verify the name and key_name values of the first domain.
+ EXPECT_EQ("example.com", domain->getName());
+ EXPECT_EQ("d2_key.example.com", domain->getKeyName());
+
+ // Verify the TSIGKeyInfo name and that the actual key was created
+ ASSERT_TRUE(domain->getTSIGKeyInfo());
+ EXPECT_EQ(domain->getKeyName(), domain->getTSIGKeyInfo()->getName());
+ EXPECT_TRUE(domain->getTSIGKeyInfo()->getTSIGKey());
+
+ // Verify the each of the first domain's servers
+ DnsServerInfoStoragePtr servers = domain->getServers();
+ EXPECT_TRUE(servers);
+ EXPECT_EQ(3, servers->size());
+
+ DnsServerInfoPtr server = (*servers)[0];
+ EXPECT_TRUE(server);
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.1", 100));
+
+ server = (*servers)[1];
+ EXPECT_TRUE(server);
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.2", 200));
+
+ server = (*servers)[2];
+ EXPECT_TRUE(server);
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.3", 300));
+
+ // Verify second domain
+ gotit = domains_->find("billcat.net");
+ ASSERT_TRUE(gotit != domains_->end());
+ domain = gotit->second;
+
+ // Verify the name and key_name values of the second domain.
+ EXPECT_EQ("billcat.net", domain->getName());
+ EXPECT_EQ("d2_key.billcat.net", domain->getKeyName());
+ ASSERT_TRUE(domain->getTSIGKeyInfo());
+ EXPECT_EQ(domain->getKeyName(), domain->getTSIGKeyInfo()->getName());
+ EXPECT_TRUE(domain->getTSIGKeyInfo()->getTSIGKey());
+
+ // Verify the each of second domain's servers
+ servers = domain->getServers();
+ EXPECT_TRUE(servers);
+ servers->size();
+ EXPECT_EQ(3, servers->size());
+
+ server = (*servers)[0];
+ EXPECT_TRUE(server);
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.4", 400));
+
+ server = (*servers)[1];
+ EXPECT_TRUE(server);
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.5", 500));
+
+ server = (*servers)[2];
+ EXPECT_TRUE(server);
+ EXPECT_TRUE(checkServer(server, "", "127.0.0.6", 600));
+}
+
+/// @brief Tests that a domain list configuration cannot contain duplicates.
+TEST_F(DdnsDomainListParserTest, duplicateDomain) {
+ // Create a domain list configuration that contains two domains with
+ // the same name.
+ std::string config =
+ "[ "
+ "{ \"name\": \"example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.3\" , "
+ " \"port\": 300 } ] } "
+ ", "
+ "{ \"name\": \"example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.3\" , "
+ " \"port\": 300 } ] } "
+ "] ";
+ // Verify that the parsing fails.
+ PARSE_FAIL(config,
+ "Duplicate domain specified:example.com (<string>:1:115)");
+}
+
+};
+
namespace isc {
namespace d2 {
+const char* valid_d2_config = "{ "
+ "\"ip-address\" : \"127.0.0.1\" , "
+ "\"port\" : 5031, "
+ "\"tsig-keys\": ["
+ "{ \"name\": \"d2_key.example.com\" , "
+ " \"algorithm\": \"HMAC-MD5\" ,"
+ " \"secret\": \"LSWXnfkKZjdPJI5QxlpnfQ==\" "
+ "} ],"
+ "\"forward-ddns\" : {"
+ "\"ddns-domains\": [ "
+ "{ \"name\": \"example.com.\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.101\" } "
+ "] } ] }, "
+ "\"reverse-ddns\" : {"
+ "\"ddns-domains\": [ "
+ "{ \"name\": \" 0.168.192.in.addr.arpa.\" , "
+ " \"key-name\": \"d2_key.example.com\" , "
+ " \"dns-servers\" : [ "
+ " { \"ip-address\": \"127.0.0.101\" , "
+ " \"port\": 100 } ] } "
+ "] } }";
+
+
const char* TEST_DNS_SERVER_IP = "127.0.0.1";
size_t TEST_DNS_SERVER_PORT = 5301;
namespace isc {
namespace d2 {
+extern const char* valid_d2_config;
extern const char* TEST_DNS_SERVER_IP;
extern size_t TEST_DNS_SERVER_PORT;
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#include <gtest/gtest.h>
+#include <cc/data.h>
+#include <d2/parser_context.h>
+#include <d2/tests/parser_unittest.h>
+#include <testutils/io_utils.h>
+
+using namespace isc::data;
+using namespace std;
+
+namespace isc {
+namespace d2 {
+namespace test {
+
+/// @brief compares two JSON trees
+///
+/// If differences are discovered, gtest failure is reported (using EXPECT_EQ)
+///
+/// @param a first to be compared
+/// @param b second to be compared
+void compareJSON(ConstElementPtr a, ConstElementPtr b) {
+ ASSERT_TRUE(a);
+ ASSERT_TRUE(b);
+ EXPECT_EQ(a->str(), b->str());
+}
+
+/// @brief Tests if the input string can be parsed with specific parser
+///
+/// The input text will be passed to bison parser of specified type.
+/// Then the same input text is passed to legacy JSON parser and outputs
+/// from both parsers are compared. The legacy comparison can be disabled,
+/// if the feature tested is not supported by the old parser (e.g.
+/// new comment styles)
+///
+/// @param txt text to be compared
+/// @param parser_type bison parser type to be instantiated
+/// @param compare whether to compare the output with legacy JSON parser
+void testParser(const std::string& txt, D2ParserContext::ParserType parser_type,
+ bool compare = true) {
+ ConstElementPtr test_json;
+
+ ASSERT_NO_THROW({
+ try {
+ D2ParserContext ctx;
+ test_json = ctx.parseString(txt, parser_type);
+ } catch (const std::exception &e) {
+ cout << "EXCEPTION: " << e.what() << endl;
+ throw;
+ }
+
+ });
+
+ if (!compare) {
+ return;
+ }
+
+ // Now compare if both representations are the same.
+ ElementPtr reference_json;
+ ASSERT_NO_THROW(reference_json = Element::fromJSON(txt, true));
+ compareJSON(reference_json, test_json);
+}
+
+// Generic JSON parsing tests
+TEST(ParserTest, mapInMap) {
+ string txt = "{ \"xyzzy\": { \"foo\": 123, \"baz\": 456 } }";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+TEST(ParserTest, listInList) {
+ string txt = "[ [ \"Britain\", \"Wales\", \"Scotland\" ], "
+ "[ \"Pomorze\", \"Wielkopolska\", \"Tatry\"] ]";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+TEST(ParserTest, nestedMaps) {
+ string txt = "{ \"europe\": { \"UK\": { \"London\": { \"street\": \"221B Baker\" }}}}";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+TEST(ParserTest, nestedLists) {
+ string txt = "[ \"half\", [ \"quarter\", [ \"eighth\", [ \"sixteenth\" ]]]]";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+TEST(ParserTest, listsInMaps) {
+ string txt = "{ \"constellations\": { \"orion\": [ \"rigel\", \"betelgeuse\" ], "
+ "\"cygnus\": [ \"deneb\", \"albireo\"] } }";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+TEST(ParserTest, mapsInLists) {
+ string txt = "[ { \"body\": \"earth\", \"gravity\": 1.0 },"
+ " { \"body\": \"mars\", \"gravity\": 0.376 } ]";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+TEST(ParserTest, types) {
+ string txt = "{ \"string\": \"foo\","
+ "\"integer\": 42,"
+ "\"boolean\": true,"
+ "\"map\": { \"foo\": \"bar\" },"
+ "\"list\": [ 1, 2, 3 ],"
+ "\"null\": null }";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+TEST(ParserTest, keywordJSON) {
+ string txt = "{ \"name\": \"user\","
+ "\"type\": \"password\","
+ "\"user\": \"name\","
+ "\"password\": \"type\" }";
+ testParser(txt, D2ParserContext::PARSER_JSON);
+}
+
+// PARSER_DHCPDDNS parser tests
+TEST(ParserTest, keywordDhcpDdns) {
+ string txt =
+ "{ \"DhcpDdns\" : \n"
+ "{ \n"
+ " \"ip-address\": \"192.168.77.1\", \n"
+ " \"port\": 777 , \n "
+ " \"ncr-protocol\": \"UDP\", \n"
+ "\"tsig-keys\": [], \n"
+ "\"forward-ddns\" : {}, \n"
+ "\"reverse-ddns\" : {} \n"
+ "} \n"
+ "} \n";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
+}
+
+TEST(ParserTest, keywordDhcp6) {
+ string txt = "{ \"Dhcp6\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"type\", \"htype\" ] },\n"
+ "\"preferred-lifetime\": 3000,\n"
+ "\"rebind-timer\": 2000, \n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface\": \"test\" } ],\n"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
+}
+
+TEST(ParserTest, keywordDhcp4) {
+ string txt = "{ \"Dhcp4\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"type\", \"htype\" ] },\n"
+ "\"rebind-timer\": 2000, \n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet4\": [ { "
+ " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],"
+ " \"subnet\": \"192.0.2.0/24\", "
+ " \"interface\": \"test\" } ],\n"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
+}
+
+TEST(ParserTest, Logging) {
+ string txt = "{ \"Logging\": { \n"
+ " \"loggers\": [ \n"
+ " { \n"
+ " \"name\": \"kea-dhcp6\", \n"
+ " \"output_options\": [ \n"
+ " { \n"
+ " \"output\": \"stdout\" \n"
+ " } \n"
+ " ], \n"
+ " \"debuglevel\": 0, \n"
+ " \"severity\": \"INFO\" \n"
+ " } \n"
+ " ] }\n"
+ "} \n";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
+}
+
+
+// Tests if bash (#) comments are supported. That's the only comment type that
+// was supported by the old parser.
+TEST(ParserTest, bashComments) {
+ string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000,\n"
+ "# this is a comment\n"
+ "\"rebind-timer\": 2000, \n"
+ "# lots of comments here\n"
+ "# and here\n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS);
+}
+
+// Tests if C++ (//) comments can start anywhere, not just in the first line.
+TEST(ParserTest, cppComments) {
+ string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000, // this is a comment \n"
+ "\"rebind-timer\": 2000, // everything after // is ignored\n"
+ "\"renew-timer\": 1000, // this will be ignored, too\n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
+}
+
+// Tests if bash (#) comments can start anywhere, not just in the first line.
+TEST(ParserTest, bashCommentsInline) {
+ string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000, # this is a comment \n"
+ "\"rebind-timer\": 2000, # everything after # is ignored\n"
+ "\"renew-timer\": 1000, # this will be ignored, too\n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
+}
+
+// Tests if multi-line C style comments are handled correctly.
+TEST(ParserTest, multilineComments) {
+ string txt= "{ \"Dhcp6\": { \"interfaces-config\": {"
+ " \"interfaces\": [ \"*\" ]"
+ "},\n"
+ "\"preferred-lifetime\": 3000, /* this is a C style comment\n"
+ "that\n can \n span \n multiple \n lines */ \n"
+ "\"rebind-timer\": 2000,\n"
+ "\"renew-timer\": 1000, \n"
+ "\"subnet6\": [ { "
+ " \"pools\": [ { \"pool\": \"2001:db8:1::/64\" } ],"
+ " \"subnet\": \"2001:db8:1::/48\", "
+ " \"interface\": \"eth0\""
+ " } ],"
+ "\"valid-lifetime\": 4000 } }";
+ testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false);
+}
+
+/// @brief Loads specified example config file
+///
+/// This test loads specified example file twice: first, using the legacy
+/// JSON file and then second time using bison parser. Two created Element
+/// trees are then compared. The input is decommented before it is passed
+/// to legacy parser (as legacy support for comments is very limited).
+///
+/// @param fname name of the file to be loaded
+void testFile(const std::string& fname) {
+ ElementPtr reference_json;
+ ConstElementPtr test_json;
+
+ string decommented = dhcp::test::decommentJSONfile(fname);
+ EXPECT_NO_THROW(reference_json = Element::fromJSONFile(decommented, true));
+
+ // remove the temporary file
+ EXPECT_NO_THROW(::remove(decommented.c_str()));
+
+ EXPECT_NO_THROW(
+ try {
+ D2ParserContext ctx;
+ test_json = ctx.parseFile(fname, D2ParserContext::PARSER_DHCPDDNS);
+ } catch (const std::exception &x) {
+ cout << "EXCEPTION: " << x.what() << endl;
+ throw;
+ });
+
+ ASSERT_TRUE(reference_json);
+ ASSERT_TRUE(test_json);
+
+ compareJSON(reference_json, test_json);
+}
+
+// This test loads all available existing files. Each config is loaded
+// twice: first with the existing Element::fromJSONFile() and then
+// the second time with D2Parser. Both JSON trees are then compared.
+TEST(ParserTest, file) {
+ vector<string> configs;
+ configs.push_back("sample1.json");
+ configs.push_back("template.json");
+
+ for (int i = 0; i<configs.size(); i++) {
+ testFile(string(CFG_EXAMPLES) + "/" + configs[i]);
+ }
+}
+
+/// @brief Tests error conditions in D2Parser
+///
+/// @param txt text to be parsed
+/// @param parser_type type of the parser to be used in the test
+/// @param msg expected content of the exception
+void testError(const std::string& txt,
+ D2ParserContext::ParserType parser_type,
+ const std::string& msg)
+{
+ try {
+ D2ParserContext ctx;
+ ConstElementPtr parsed = ctx.parseString(txt, parser_type);
+ FAIL() << "Expected D2ParseError but nothing was raised (expected: "
+ << msg << ")";
+ }
+ catch (const D2ParseError& ex) {
+ EXPECT_EQ(msg, ex.what());
+ }
+ catch (...) {
+ FAIL() << "Expected D2ParseError but something else was raised";
+ }
+}
+
+// Verify that error conditions are handled correctly.
+TEST(ParserTest, errors) {
+ // no input
+ testError("", D2ParserContext::PARSER_JSON,
+ "<string>:1.1: syntax error, unexpected end of file");
+ testError(" ", D2ParserContext::PARSER_JSON,
+ "<string>:1.2: syntax error, unexpected end of file");
+ testError("\n", D2ParserContext::PARSER_JSON,
+ "<string>:2.1: syntax error, unexpected end of file");
+ testError("\t", D2ParserContext::PARSER_JSON,
+ "<string>:1.2: syntax error, unexpected end of file");
+ testError("\r", D2ParserContext::PARSER_JSON,
+ "<string>:1.2: syntax error, unexpected end of file");
+
+ // comments
+ testError("# nothing\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:2.1: syntax error, unexpected end of file");
+ testError(" #\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:2.1: syntax error, unexpected end of file");
+ testError("// nothing\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:2.1: syntax error, unexpected end of file");
+ testError("/* nothing */\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:2.1: syntax error, unexpected end of file");
+ testError("/* no\nthing */\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:3.1: syntax error, unexpected end of file");
+ testError("/* no\nthing */\n\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:4.1: syntax error, unexpected end of file");
+ testError("/* nothing\n",
+ D2ParserContext::PARSER_JSON,
+ "Comment not closed. (/* in line 1");
+ testError("\n\n\n/* nothing\n",
+ D2ParserContext::PARSER_JSON,
+ "Comment not closed. (/* in line 4");
+ testError("{ /* */*/ }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.3-8: Invalid character: *");
+ testError("{ /* // *// }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.3-11: Invalid character: /");
+ testError("{ /* // */// }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:2.1: syntax error, unexpected end of file, "
+ "expecting }");
+
+ // includes
+ testError("<?\n",
+ D2ParserContext::PARSER_JSON,
+ "Directive not closed.");
+ testError("<?include\n",
+ D2ParserContext::PARSER_JSON,
+ "Directive not closed.");
+ string file = string(CFG_EXAMPLES) + "/" + "sample1.json";
+ testError("<?include \"" + file + "\"\n",
+ D2ParserContext::PARSER_JSON,
+ "Directive not closed.");
+ testError("<?include \"/foo/bar\" ?>/n",
+ D2ParserContext::PARSER_JSON,
+ "Can't open include file /foo/bar");
+
+ // JSON keywords
+ testError("{ \"foo\": True }",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.10-13: JSON true reserved keyword is lower case only");
+ testError("{ \"foo\": False }",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.10-14: JSON false reserved keyword is lower case only");
+ testError("{ \"foo\": NULL }",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.10-13: JSON null reserved keyword is lower case only");
+ testError("{ \"foo\": Tru }",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.10: Invalid character: T");
+ testError("{ \"foo\": nul }",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.10: Invalid character: n");
+
+ // numbers
+ testError("123",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1-3: syntax error, unexpected integer, "
+ "expecting {");
+ testError("-456",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1-4: syntax error, unexpected integer, "
+ "expecting {");
+ testError("-0001",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1-5: syntax error, unexpected integer, "
+ "expecting {");
+ testError("1234567890123456789012345678901234567890",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1-40: Failed to convert "
+ "1234567890123456789012345678901234567890"
+ " to an integer.");
+ testError("-3.14e+0",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1-8: syntax error, unexpected floating point, "
+ "expecting {");
+ testError("1e50000",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1-7: Failed to convert 1e50000 "
+ "to a floating point.");
+
+ // strings
+ testError("\"aabb\"",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1-6: syntax error, unexpected constant string, "
+ "expecting {");
+ testError("{ \"aabb\"err",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.9: Invalid character: e");
+ testError("{ err\"aabb\"",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.3: Invalid character: e");
+ testError("\"a\n\tb\"",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1-6: Invalid control in \"a\n\tb\"");
+ testError("\"a\\n\\tb\"",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1-8: syntax error, unexpected constant string, "
+ "expecting {");
+ testError("\"a\\x01b\"",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1-8: Bad escape in \"a\\x01b\"");
+ testError("\"a\\u0162\"",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1-9: Unsupported unicode escape in \"a\\u0162\"");
+ testError("\"a\\u062z\"",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1-9: Bad escape in \"a\\u062z\"");
+ testError("\"abc\\\"",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1-6: Overflow escape in \"abc\\\"");
+
+ // from data_unittest.c
+ testError("\\a",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1: Invalid character: \\");
+ testError("\\",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1: Invalid character: \\");
+ testError("\\\"\\\"",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.1: Invalid character: \\");
+
+ // want a map
+ testError("[]\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1: syntax error, unexpected [, "
+ "expecting {");
+ testError("[]\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.1: syntax error, unexpected [, "
+ "expecting {");
+ testError("{ 123 }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.3-5: syntax error, unexpected integer, "
+ "expecting }");
+ testError("{ 123 }\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.3-5: syntax error, unexpected integer");
+ testError("{ \"foo\" }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.9: syntax error, unexpected }, "
+ "expecting :");
+ testError("{ \"foo\" }\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.9: syntax error, unexpected }, expecting :");
+ testError("{ \"foo\":null }\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.3-7: got unexpected keyword "
+ "\"foo\" in toplevel map.");
+ testError("{ \"Dhcp6\" }\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:1.11: syntax error, unexpected }, "
+ "expecting :");
+ testError("{ \"Dhcp4\":[]\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:2.1: syntax error, unexpected end of file, "
+ "expecting \",\" or }");
+ testError("{}{}\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.3: syntax error, unexpected {, "
+ "expecting end of file");
+
+ // bad commas
+ testError("{ , }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.3: syntax error, unexpected \",\", "
+ "expecting }");
+ testError("{ , \"foo\":true }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.3: syntax error, unexpected \",\", "
+ "expecting }");
+ testError("{ \"foo\":true, }\n",
+ D2ParserContext::PARSER_JSON,
+ "<string>:1.15: syntax error, unexpected }, "
+ "expecting constant string");
+
+ // bad type
+ testError("{ \"DhcpDdns\":{\n"
+ " \"dns-server-timeout\":false }}\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:2.24-28: syntax error, unexpected boolean, "
+ "expecting integer");
+
+ // unknown keyword
+ testError("{ \"DhcpDdns\":{\n"
+ " \"totally-bogus\":600 }}\n",
+ D2ParserContext::PARSER_DHCPDDNS,
+ "<string>:2.2-16: got unexpected keyword "
+ "\"totally-bogus\" in DhcpDdns map.");
+}
+
+// Check unicode escapes
+TEST(ParserTest, unicodeEscapes) {
+ ConstElementPtr result;
+ string json;
+
+ // check we can reread output
+ for (char c = -128; c < 127; ++c) {
+ string ins(" ");
+ ins[1] = c;
+ ConstElementPtr e(new StringElement(ins));
+ json = e->str();
+ ASSERT_NO_THROW(
+ try {
+ D2ParserContext ctx;
+ result = ctx.parseString(json, D2ParserContext::PARSER_JSON);
+ } catch (const std::exception &x) {
+ cout << "EXCEPTION: " << x.what() << endl;
+ throw;
+ });
+ ASSERT_EQ(Element::string, result->getType());
+ EXPECT_EQ(ins, result->stringValue());
+ }
+}
+
+// This test checks that all representations of a slash is recognized properly.
+TEST(ParserTest, unicodeSlash) {
+ // check the 4 possible encodings of solidus '/'
+ ConstElementPtr result;
+ string json = "\"/\\/\\u002f\\u002F\"";
+ ASSERT_NO_THROW(
+ try {
+ D2ParserContext ctx;
+ result = ctx.parseString(json, D2ParserContext::PARSER_JSON);
+ } catch (const std::exception &x) {
+ cout << "EXCEPTION: " << x.what() << endl;
+ throw;
+ });
+ ASSERT_EQ(Element::string, result->getType());
+ EXPECT_EQ("////", result->stringValue());
+}
+
+};
+};
+};
--- /dev/null
+// Copyright (C) 2017 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
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef PARSER_UNITTEST_H
+#define PARSER_UNITTEST_H
+
+#include <gtest/gtest.h>
+#include <cc/data.h>
+#include <d2/parser_context.h>
+
+using namespace isc::data;
+using namespace std;
+
+namespace isc {
+namespace d2 {
+namespace test {
+
+/// @brief Runs parser in JSON mode, useful for parser testing
+///
+/// @param in string to be parsed
+/// @return ElementPtr structure representing parsed JSON
+inline isc::data::ElementPtr
+parseJSON(const std::string& in)
+{
+ isc::d2::D2ParserContext ctx;
+ return (ctx.parseString(in, isc::d2::D2ParserContext::PARSER_JSON));
+}
+
+};
+};
+};
+
+#endif // PARSER_UNITTEST_H
-# Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
+# Copyright (C) 2014-2015,2017 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
# Each test entry consists of:
#
# description - text describing the test (optional)
-# should-fail - indicates whether parsing is expected to fail, defaults to
-# false
+# syntax-error - syntax error the JSON parsing should emit for this test
+# defaults to "" = no error
+# logic-error - indicates whether a post-JSON parsing logic error should occur
+# defaults to false
# data {} - Configuration text to submit for parsing.
#
# The vast majority of the tests in this file are invalid and are expected
-# to fail. There are some that should succeed and are used more or less
-# as sanity checks.
+# to fail either as a syntax error caught by the JSON parser or a logic error
+# caught during element processing. There are some that should succeed and are
+# used more or less as sanity checks.
{ "test-list" : [
#-----
# as well as validating this as the smallest config which makes writing
# permutations easier.
"description" : "D2 smallest, valid config",
-"should-fail" : false,
"data" :
{
"forward-ddns" : {},
}
#-----
+# Map should be supplied through setDefaults
,{
"description" : "D2 missing forward-ddns map",
-"should-fail" : true,
"data" :
{
"reverse-ddns" : {},
}
#-----
+# Map should be supplied through setDefaults
,{
"description" : "D2 missing reverse-ddns map",
-"should-fail" : true,
"data" :
{
"forward-ddns" : {},
#-----
+# Map should be supplied through setDefaults
,{
"description" : "D2 missing tsig-keys list",
-"should-fail" : true,
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2 unknown scalar",
-"should-fail" : true,
+"syntax-error" : "<string>:1.3-16: got unexpected keyword \"bogus-scalar\" in DhcpDdns map.",
"data" :
{
"bogus-scalar" : true,
#-----
,{
"description" : "D2 unknown map",
-"should-fail" : true,
+"syntax-error" : "<string>:1.3-13: got unexpected keyword \"bogus-map\" in DhcpDdns map.",
"data" :
{
"bogus-map" : {},
#-----
,{
"description" : "D2 unknown list",
-"should-fail" : true,
+"syntax-error" : "<string>:1.3-14: got unexpected keyword \"bogus-list\" in DhcpDdns map.",
"data" :
{
"bogus-list" : [],
#-----
,{
"description" : "D2Params.ip-address invalid value",
-"should-fail" : true,
+"logic-error" : "invalid address (bogus) specified for parameter 'ip-address' (<string>:1:39)",
"data" :
{
"ip-address" : "bogus",
#-----
,{
"description" : "D2Params.port can't be 0",
-"should-fail" : true,
+"syntax-error" : "<string>:1.33: port must be greater than zero but less than 65536",
"data" :
{
"port" : 0,
#-----
,{
"description" : "D2Params.port, non numeric",
-"should-fail" : true,
+"syntax-error" : "<string>:1.33-39: syntax error, unexpected constant string, expecting integer",
"data" :
{
"port" : "bogus",
#-----
,{
"description" : "D2Params.dns-server-timeout can't be 0",
-"should-fail" : true,
+"syntax-error" : "<string>:1.25: dns-server-timeout must be greater than zero",
"data" :
{
"dns-server-timeout" : 0,
#-----
,{
"description" : "D2Params.dns-server-timeout, non numeric",
-"should-fail" : true,
+"syntax-error" : "<string>:1.25-31: syntax error, unexpected constant string, expecting integer",
"data" :
{
"dns-server-timeout" : "bogus",
#-----
,{
"description" : "D2Params.ncr-protocol, unsupported TCP",
-"should-fail" : true,
+"logic-error" : "ncr-protocol : TCP is not yet supported (<string>:1:41)",
"data" :
{
"ncr-protocol" : "TCP",
#-----
,{
"description" : "D2Params.ncr-protocol, invalid value",
-"should-fail" : true,
+"syntax-error" : "<string>:1.41-47: syntax error, unexpected constant string, expecting UDP or TCP",
"data" :
{
"ncr-protocol" : "bogus",
#-----
,{
"description" : "D2Params.ncr-format, invalid value",
-"should-fail" : true,
+"syntax-error" : "<string>:1.39-45: syntax error, unexpected constant string, expecting JSON",
"data" :
{
"ncr-format" : "bogus",
#-----
,{
"description" : "D2.tsig-keys, missing key name",
-"should-fail" : true,
+"logic-error" : "element: tsig-keys : String parameter name not found(<string>:1:62)<string>:1:47",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, blank key name",
-"should-fail" : true,
+"syntax-error" : "<string>:1.95: TSIG key name cannot be blank",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, duplicate key name",
-"should-fail" : true,
+"logic-error" : "Duplicate TSIG key name specified : first.key (<string>:1:185)",
"data" :
{
"forward-ddns" : {},
#----- D2.tsig-keys, algorithm tests
,{
-"description" : "D2.tsig-keys, all valid algorthms",
+"description" : "D2.tsig-keys, all valid algorithms",
"data" :
{
"forward-ddns" : {},
#----- D2.tsig-keys, algorithm tests
,{
"description" : "D2.tsig-keys, missing algorithm",
-"should-fail" : true,
+"logic-error" : "element: tsig-keys : String parameter algorithm not found(<string>:1:62)<string>:1:47",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, blank algorithm",
-"should-fail" : true,
+"syntax-error" : "<string>:1.75: TSIG key algorithm cannot be blank",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, invalid algorithm",
-"should-fail" : true,
+"logic-error" : "tsig-key : Unknown TSIG Key algorithm: bogus (<string>:1:77)",
"data" :
{
"forward-ddns" : {},
#----- D2.tsig-keys, digest-bits tests
,{
-"description" : "D2.tsig-keys, all valid algorthms",
+"description" : "D2.tsig-keys, all valid algorthims",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, invalid digest-bits",
-"should-fail" : true,
+"syntax-error" : "<string>:1.104-105: TSIG key digest-bits must either be zero or a positive, multiple of eight",
"data" :
{
"forward-ddns" : {},
"algorithm" : "HMAC-MD5",
"digest-bits" : 84,
"secret" : "LSWXnfkKZjdPJI5QxlpnfQ=="
- },
+ }
]
}
}
#-----
,{
"description" : "D2.tsig-keys, too small truncated HMAC-MD5",
-"should-fail" : true,
+"logic-error" : "tsig-key: digest-bits too small : (<string>:1:104)",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, too small truncated HMAC-SHA1",
-"should-fail" : true,
+"logic-error" : "tsig-key: digest-bits too small : (<string>:1:105)",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, too small truncated HMAC-SHA224",
-"should-fail" : true,
+"logic-error" : "tsig-key: digest-bits too small : (<string>:1:107)",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, too small truncated HMAC-SHA256",
-"should-fail" : true,
+"logic-error" : "tsig-key: digest-bits too small : (<string>:1:107)",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, too small truncated HMAC-SHA384",
-"should-fail" : true,
+"logic-error" : "tsig-key: digest-bits too small : (<string>:1:107)",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, too small truncated HMAC-SHA512",
-"should-fail" : true,
+"logic-error" : "tsig-key: digest-bits too small : (<string>:1:107)",
"data" :
{
"forward-ddns" : {},
#----- D2.tsig-keys, secret tests
,{
"description" : "D2.tsig-keys, missing secret",
-"should-fail" : true,
+"logic-error" : "element: tsig-keys : String parameter secret not found(<string>:1:62)<string>:1:47",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, blank secret",
-"should-fail" : true,
+"syntax-error" : "<string>:1.118: TSIG key secret cannot be blank",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.tsig-keys, invalid secret",
-"should-fail" : true,
+"logic-error" : "Cannot make TSIGKey: Incomplete input for base64: bogus (<string>:1:62)",
"data" :
{
"forward-ddns" : {},
#------
,{
"description" : "D2.forward-ddns, unknown parameter",
-"should-fail" : true,
+"syntax-error" : "<string>:1.21-27: got unexpected keyword \"bogus\" in forward-ddns map.",
"data" :
{
"forward-ddns" :
#------
,{
"description" : "D2.forward-ddns, duplicate domain",
-"should-fail" : true,
+"logic-error" : "Duplicate domain specified:four.example.com. (<string>:1:184)",
"data" :
{
"forward-ddns" :
#----- D2.forward-ddns.dhcp-ddns tests
,{
"description" : "D2.forward-ddns.dhcp-ddns, unknown parameter",
-"should-fail" : true,
+"syntax-error" : "<string>:1.41-47: got unexpected keyword \"bogus\" in ddns-domains map.",
"data" :
{
"forward-ddns" :
#----- D2.forward-ddns.dhcp-ddns.name tests
,{
-"description" : "D2.forward-ddns.dhcp-ddns, no name",
-"should-fail" : true,
+"description" : "D2.forward-ddns.dhcp-ddns, empty domain",
+"syntax-error" : "<string>:1.42: syntax error, unexpected }, expecting key-name or dns-servers or name or constant string",
"data" :
{
"forward-ddns" :
#-----
,{
"description" : "D2.forward-ddns.dhcp-ddns, blank name",
-"should-fail" : true,
+"syntax-error" : "<string>:1.47: Ddns domain name cannot be blank",
"data" :
{
"forward-ddns" :
#------ "D2.forward-ddns.dhcp-ddns, key-name tests
,{
"description" : "D2.forward-ddns, no matching key name",
-"should-fail" : true,
+"logic-error" : "DdnsDomain : four.example.com. specifies an undefined key: no.such.key (<string>:1:104)",
"data" :
{
"forward-ddns" :
#----- D2.forward-ddns.dhcp-ddns.dns-servers tests
,{
"description" : "D2.forward-ddns.dhcp-ddns.dns-servers, no servers",
-"should-fail" : true,
+"syntax-error" : "<string>:1.59: syntax error, unexpected ], expecting {",
"data" :
{
"forward-ddns" :
#----- D2.forward-ddns.dhcp-ddns.dns-servers tests
,{
"description" : "D2.forward-ddns.dhcp-ddns.dns-servers, unknown parameter",
-"should-fail" : true,
+"syntax-error" : "<string>:1.60-66: got unexpected keyword \"bogus\" in dns-servers map.",
"data" :
{
"forward-ddns" :
#-----
,{
"description" : "D2.forward-ddns.dhcp-ddns.dns-servers.hostname unsupported",
-"should-fail" : true,
+"syntax-error" : "<string>:1.70: hostname is not yet supported",
"data" :
{
"forward-ddns" :
#-----
,{
"description" : "D2.forward-ddns.dhcp-ddns.dns-servers.ip-address invalid address ",
-"should-fail" : true,
+"logic-error" : "Dns Server : invalid IP address : bogus (<string>:1:74)",
"data" :
{
"forward-ddns" :
#-----
,{
"description" : "D2.forward-ddns.dhcp-ddns.dns-servers.port cannot be 0 ",
-"should-fail" : true,
+"syntax-error" : "<string>:1.97: port must be greater than zero but less than 65536",
"data" :
{
"forward-ddns" :
#------
,{
"description" : "D2.reverse-ddns, unknown parameter",
-"should-fail" : true,
+"syntax-error" : "<string>:1.43-49: got unexpected keyword \"bogus\" in reverse-ddns map.",
"data" :
{
"forward-ddns" : {},
#------
,{
"description" : "D2.reverse-ddns, duplicate domain",
-"should-fail" : true,
+"logic-error" : "Duplicate domain specified:2.0.192.in-addra.arpa. (<string>:1:211)",
"data" :
{
"forward-ddns" : {},
#----- D2.reverse-ddns.dhcp-ddns tests
,{
"description" : "D2.reverse-ddns.dhcp-ddns, unknown parameter",
-"should-fail" : true,
+"syntax-error" : "<string>:1.63-69: got unexpected keyword \"bogus\" in ddns-domains map.",
"data" :
{
"forward-ddns" : {},
#----- D2.reverse-ddns.dhcp-ddns.name tests
,{
"description" : "D2.reverse-ddns.dhcp-ddns, no name",
-"should-fail" : true,
+"syntax-error" : "<string>:1.64: syntax error, unexpected }, expecting key-name or dns-servers or name or constant string",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.reverse-ddns.dhcp-ddns, blank name",
-"should-fail" : true,
+"syntax-error" : "<string>:1.69: Ddns domain name cannot be blank",
"data" :
{
"forward-ddns" : {},
#------ "D2.reverse-ddns.dhcp-ddns, key-name tests
,{
"description" : "D2.reverse-ddns, no matching key name",
-"should-fail" : true,
+"logic-error" : "DdnsDomain : 2.0.192.in-addr.arpa. specifies an undefined key: no.such.key (<string>:1:126)",
"data" :
{
"forward-ddns" : {},
#----- D2.reverse-ddns.dhcp-ddns.dns-servers tests
,{
"description" : "D2.reverse-ddns.dhcp-ddns.dns-servers, no servers",
-"should-fail" : true,
+"syntax-error" : "<string>:1.81: syntax error, unexpected ], expecting {",
"data" :
{
"forward-ddns" : {},
#----- D2.reverse-ddns.dhcp-ddns.dns-servers tests
,{
"description" : "D2.reverse-ddns.dhcp-ddns.dns-servers, unknown parameter",
-"should-fail" : true,
+"syntax-error" : "<string>:1.82-88: got unexpected keyword \"bogus\" in dns-servers map.",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.reverse-ddns.dhcp-ddns.dns-servers.hostname unsupported",
-"should-fail" : true,
+"syntax-error" : "<string>:1.92: hostname is not yet supported",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.reverse-ddns.dhcp-ddns.dns-servers.ip-address invalid value",
-"should-fail" : true,
+"logic-error" : "Dns Server : invalid IP address : bogus (<string>:1:96)",
"data" :
{
"forward-ddns" : {},
#-----
,{
"description" : "D2.reverse-ddns.dhcp-ddns.dns-servers.port cannot be 0 ",
-"should-fail" : true,
+"syntax-error" : "<string>:1.119: port must be greater than zero but less than 65536",
"data" :
{
"forward-ddns" : {},
if ((position_.file_ != "") || \
(position_.line_ != 0) || \
(position_.pos_ != 0)) { \
- msg_ += " in " + position_.str(); \
+ msg_ += " in (" + position_.str() + ")"; \
} \
isc_throw(TypeError, msg_); \
}
break;
}
case Element::integer: {
- int int_value = boost::lexical_cast<int>(def_value.value_);
- x.reset(new IntElement(int_value, pos));
+ try {
+ int int_value = boost::lexical_cast<int>(def_value.value_);
+ x.reset(new IntElement(int_value, pos));
+ }
+ catch (const std::exception& ex) {
+ isc_throw(BadValue, "Internal error. Integer value expected for: "
+ << def_value.name_ << ", value is: "
+ << def_value.value_ );
+ }
+
break;
}
case Element::boolean: {
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
std::string element_id;
try {
+
+ // Make the configuration mutable so we can then insert default values.
+ ElementPtr mutable_cfg = boost::const_pointer_cast<Element>(config_set);
+ setCfgDefaults(mutable_cfg);
+
// Split the configuration into two maps. The first containing only
// top-level scalar parameters (i.e. globals), the second containing
// non-scalar or object elements (maps, lists, etc...). This allows
ElementMap objects_map;
isc::dhcp::ConfigPair config_pair;
- BOOST_FOREACH(config_pair, config_set->mapValue()) {
+ BOOST_FOREACH(config_pair, mutable_cfg->mapValue()) {
std::string element_id = config_pair.first;
isc::data::ConstElementPtr element = config_pair.second;
switch (element->getType()) {
isc_throw(DCfgMgrBaseError,
"Element required by parsing order is missing: "
<< element_id << " ("
- << config_set->getPosition() << ")");
+ << mutable_cfg->getPosition() << ")");
}
}
return (answer);
}
+void
+DCfgMgrBase::setCfgDefaults(isc::data::ElementPtr) {
+}
+
+void
+DCfgMgrBase::parseElement(const std::string&, isc::data::ConstElementPtr) {
+};
+
+
void
DCfgMgrBase::buildParams(isc::data::ConstElementPtr params_config) {
// Loop through scalars parsing them and committing them to storage.
BOOST_FOREACH(dhcp::ConfigPair param, params_config->mapValue()) {
- // Call derivation's method to create the proper parser.
- dhcp::ParserPtr parser(createConfigParser(param.first,
- param.second->getPosition()));
- parser->build(param.second);
- parser->commit();
+ // Call derivation's element parser to parse the element.
+ parseElement(param.first, param.second);
}
}
void DCfgMgrBase::buildAndCommit(std::string& element_id,
isc::data::ConstElementPtr value) {
- // Call derivation's implementation to create the appropriate parser
- // based on the element id.
- ParserPtr parser = createConfigParser(element_id, value->getPosition());
- if (!parser) {
- isc_throw(DCfgMgrBaseError, "Could not create parser");
- }
-
- // Invoke the parser's build method passing in the value. This will
- // "convert" the Element form of value into the actual data item(s)
- // and store them in parser's local storage.
- parser->build(value);
-
- // Invoke the parser's commit method. This "writes" the data
- // item(s) stored locally by the parser into the context. (Note that
- // parsers are free to do more than update the context, but that is an
- // nothing something we are concerned with here.)
- parser->commit();
+ // Call derivation's element parser to parse the element.
+ parseElement(element_id, value);
}
}; // end of isc::dhcp namespace
/// This allows a derivation to specify the order in which its elements are
/// parsed if there are dependencies between elements.
///
-/// To parse a given element, its id is passed into createConfigParser,
-/// which returns an instance of the appropriate parser. This method is
-/// abstract so the derivation's implementation determines the type of parser
-/// created. This isolates the knowledge of specific element ids and which
-/// application specific parsers to derivation.
-///
-/// Once the parser has been created, it is used to parse the data value
-/// associated with the element id and update the context with the parsed
-/// results.
+/// To parse a given element, its id along with the element itself,
+/// is passed into the virtual method, @c parseElement. Derivations are
+/// expected to converts the element into application specific object(s),
+/// thereby isolating the CPL from application details.
///
/// In the event that an error occurs, parsing is halted and the
/// configuration context is restored from backup.
virtual std::string getConfigSummary(const uint32_t selection) = 0;
protected:
+ /// @brief Adds default values to the given config
+ ///
+ /// Provides derviations a means to add defaults to a configuration
+ /// Element map prior to parsing it.
+ ///
+ /// @param mutable_config - configuration to which defaults should be added
+ virtual void setCfgDefaults(isc::data::ElementPtr mutable_config);
+
+ /// @brief Parses an individual element
+ ///
+ /// Each element to be parsed is passed into this method to be converted
+ /// into the requisite application object(s).
+ ///
+ /// @param element_id name of the element as it is expected in the cfg
+ /// @param element value of the element as ElementPtr
+ ///
+ virtual void parseElement(const std::string& element_id,
+ isc::data::ConstElementPtr element);
+
/// @brief Parses a set of scalar configuration elements into global
/// parameters
///
/// For each scalar element in the set:
- /// - create a parser for the element
- /// - invoke the parser's build method
- /// - invoke the parser's commit method
+ /// - Invoke parseElement
+ /// - If it returns true go to the next element othewise:
+ /// - create a parser for the element
+ /// - invoke the parser's build method
+ /// - invoke the parser's commit method
///
/// This will commit the values to context storage making them accessible
/// during object parsing.
/// @param params_config set of scalar configuration elements to parse
virtual void buildParams(isc::data::ConstElementPtr params_config);
- /// @brief Create a parser instance based on an element id.
- ///
- /// Given an element_id returns an instance of the appropriate parser.
- /// This method is abstract, isolating any direct knowledge of element_ids
- /// and parsers to within the application-specific derivation.
- ///
- /// @param element_id is the string name of the element as it will appear
- /// in the configuration set.
- /// @param pos position within the configuration text (or file) of element
- /// to be parsed. This is passed for error messaging.
- ///
- /// @return returns a ParserPtr to the parser instance.
- /// @throw throws DCfgMgrBaseError if an error occurs.
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& element_id,
- const isc::data::Element::Position& pos
- = isc::data::Element::Position()) = 0;
-
/// @brief Abstract factory which creates a context instance.
///
/// This method is used at the beginning of configuration process to
/// @brief Parse a configuration element.
///
- /// Given an element_id and data value, instantiate the appropriate
- /// parser, parse the data value, and commit the results.
+ /// Given an element_id and data value, invoke parseElement. If
+ /// it returns true the return, otherwise created the appropriate
+ /// parser, parse the data value, and commit the results.
+ ///
///
/// @param element_id is the string name of the element as it will appear
/// in the configuration set.
controller_ = controller;
}
+isc::data::ConstElementPtr
+DControllerBase::parseFile(const std::string&) {
+ isc::data::ConstElementPtr elements;
+ return (elements);
+}
+
void
DControllerBase::launch(int argc, char* argv[], const bool test_mode) {
// rather than calling exit() here which disrupts gtest.
isc_throw(VersionMessage, getVersion(true));
break;
-
+
case 'W':
// gather Kea config report and throw so main() can catch and
// return rather than calling exit() here which disrupts gtest.
"use -c command line option.");
}
- // Read contents of the file and parse it as JSON
- isc::data::ConstElementPtr whole_config =
- isc::data::Element::fromJSONFile(config_file, true);
+ // If parseFile returns an empty pointer, then pass the file onto the
+ // original JSON parser.
+ isc::data::ConstElementPtr whole_config = parseFile(config_file);
+ if (!whole_config) {
+ // Read contents of the file and parse it as JSON
+ whole_config = isc::data::Element::fromJSONFile(config_file, true);
+ }
// Let's configure logging before applying the configuration,
// so we can log things during configuration process.
tmp << "linked with:" << std::endl;
tmp << isc::log::Logger::getVersion() << std::endl;
tmp << isc::cryptolink::CryptoLink::getVersion() << std::endl;
- tmp << "database:" << std::endl;
+ tmp << "database:" << std::endl;
#ifdef HAVE_MYSQL
tmp << isc::dhcp::MySqlLeaseMgr::getDBVersion() << std::endl;
#endif
-// Copyright (C) 2013-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
/// include at least:
///
/// @code
- /// { "<module-name>": {<module-config>} }
+ /// { "<module-name>": {<module-config>}
+ ///
+ /// # Logging element is optional
+ /// ,"Logging": {<logger connfig}
+ /// }
///
/// where:
/// module-name : is a label which uniquely identifies the
/// the application's configuration values
/// @endcode
///
- /// The method extracts the set of configuration elements for the
- /// module-name which matches the controller's app_name_ and passes that
+ /// To translate the JSON content into Elements, @c parseFile() is called
+ /// first. This virtual method provides derivations a means to parse the
+ /// file content using an alternate parser. If it returns an empty pointer
+ /// than the JSON parsing providing by Element::fromJSONFile() is called.
+ ///
+ /// Once parsed, the method looks for the Element "Logging" and, if present
+ /// uses it to configure loging.
+ ///
+ /// It then extracts the set of configuration elements for the
+ /// module-name that matches the controller's app_name_ and passes that
/// set into @c updateConfig().
///
/// The file may contain an arbitrary number of other modules.
/// @throw VersionMessage if the -v or -V arguments is given.
void parseArgs(int argc, char* argv[]);
+
+ ///@brief Parse a given file into Elements
+ ///
+ /// This method provides a means for deriving classes to use alternate
+ /// parsing mechanisms to parse configuration files into the corresponding
+ /// isc::data::Elements. The elements produced must be equivalent to those
+ /// which would be produced by the original JSON parsing. Implementations
+ /// should throw when encountering errors.
+ ///
+ /// The default implementation returns an empty pointer, signifying to
+ /// callers that they should submit the file to the original parser.
+ ///
+ /// @param file_name pathname of the file to parse
+ ///
+ /// @return pointer to the elements created
+ ///
+ virtual isc::data::ConstElementPtr parseFile(const std::string& file_name);
+
+ ///@brief Parse text into Elements
+ ///
+ /// This method provides a means for deriving classes to use alternate
+ /// parsing mechanisms to parse configuration text into the corresponding
+ /// isc::data::Elements. The elements produced must be equivalent to those
+ /// which would be produced by the original JSON parsing. Implementations
+ /// should throw when encountering errors.
+ ///
+ /// The default implementation returns an empty pointer, signifying to
+ /// callers that they should submit the text to the original parser.
+ ///
+ /// @param input text to parse
+ ///
+ /// @return pointer to the elements created
+ ///
+ virtual isc::data::ConstElementPtr parseText(const std::string& input) {
+ static_cast<void>(input); // just tu shut up the unused parameter warning
+ isc::data::ConstElementPtr elements;
+ return (elements);
+ }
+
/// @brief Instantiates the application process and then initializes it.
/// This is the second step taken during launch, following successful
/// command line parsing. It is used to invoke the derivation-specific
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
using namespace isc;
using namespace isc::config;
using namespace isc::process;
+using namespace isc::data;
using namespace boost::posix_time;
namespace {
return (DCfgContextBasePtr());
}
- /// @brief Dummy implementation as this method is abstract.
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& /* element_id */,
- const isc::data::Element::Position& /* pos */) {
- return (isc::dhcp::ParserPtr());
- }
-
/// @brief Returns summary of configuration in the textual format.
virtual std::string getConfigSummary(const uint32_t) {
return ("");
answer_ = cfg_mgr_->parseConfig(config_set_);
EXPECT_TRUE(checkAnswer(0));
- // Verify that an error building the element is caught and returns a
- // failed parse result.
- SimFailure::set(SimFailure::ftElementBuild);
- answer_ = cfg_mgr_->parseConfig(config_set_);
- EXPECT_TRUE(checkAnswer(1));
-
- // Verify that an error committing the element is caught and returns a
- // failed parse result.
- SimFailure::set(SimFailure::ftElementCommit);
- answer_ = cfg_mgr_->parseConfig(config_set_);
- EXPECT_TRUE(checkAnswer(1));
-
// Verify that an unknown element error is caught and returns a failed
// parse result.
SimFailure::set(SimFailure::ftElementUnknown);
EXPECT_EQ(pos.file_, isc::data::Element::ZERO_POSITION().file_);
}
-
} // end of anonymous namespace
EXPECT_EQ(SIGHUP, signals[0]);
}
+// Tests that the original configuration is retained after a SIGHUP triggered
+// reconfiguration fails due to invalid config content.
+TEST_F(DStubControllerTest, alternateParsing) {
+ controller_->useAlternateParser(true);
+
+ // Setup to raise SIGHUP in 200 ms.
+ TimedSignal sighup(*getIOService(), SIGHUP, 200);
+
+ // Write the config and then run launch() for 500 ms
+ // After startup, which will load the initial configuration this enters
+ // the process's runIO() loop. We will first rewrite the config file.
+ // Next we process the SIGHUP signal which should cause us to reconfigure.
+ time_duration elapsed_time;
+ runWithConfig("{ \"string_test\": \"first value\" }", 500, elapsed_time);
+
+ // Context is still available post launch. Check to see that our
+ // configuration value is still the original value.
+ std::string actual_value = "";
+ ASSERT_NO_THROW(getContext()->getParam("string_test", actual_value));
+ EXPECT_EQ("alt value", actual_value);
+
+ // Verify that we saw the signal.
+ std::vector<int>& signals = controller_->getProcessedSignals();
+ ASSERT_EQ(1, signals.size());
+ EXPECT_EQ(SIGHUP, signals[0]);
+}
+
+
+
// Tests that the original configuration is replaced after a SIGHUP triggered
// reconfiguration succeeds.
TEST_F(DStubControllerTest, validConfigReload) {
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
namespace isc {
namespace process {
-const char* valid_d2_config = "{ "
- "\"ip-address\" : \"127.0.0.1\" , "
- "\"port\" : 5031, "
- "\"tsig-keys\": ["
- "{ \"name\": \"d2_key.tmark.org\" , "
- " \"algorithm\": \"HMAC-MD5\" ,"
- " \"secret\": \"LSWXnfkKZjdPJI5QxlpnfQ==\" "
- "} ],"
- "\"forward-ddns\" : {"
- "\"ddns-domains\": [ "
- "{ \"name\": \"tmark.org.\" , "
- " \"key-name\": \"d2_key.tmark.org\" , "
- " \"dns-servers\" : [ "
- " { \"ip-address\": \"127.0.0.101\" } "
- "] } ] }, "
- "\"reverse-ddns\" : {"
- "\"ddns-domains\": [ "
- "{ \"name\": \" 0.168.192.in.addr.arpa.\" , "
- " \"key-name\": \"d2_key.tmark.org\" , "
- " \"dns-servers\" : [ "
- " { \"ip-address\": \"127.0.0.101\" , "
- " \"port\": 100 } ] } "
- "] } }";
-
// Initialize the static failure flag.
SimFailure::FailureType SimFailure::failure_type_ = SimFailure::ftNoFailure;
DStubController::DStubController()
: DControllerBase(stub_app_name_, stub_bin_name_),
- processed_signals_(), record_signal_only_(false) {
+ processed_signals_(), record_signal_only_(false), use_alternate_parser_(false) {
if (getenv("KEA_FROM_BUILD")) {
setSpecFileName(std::string(getenv("KEA_FROM_BUILD")) +
DControllerBase::processSignal(signum);
}
+isc::data::ConstElementPtr
+DStubController::parseFile(const std::string& /*file_name*/) {
+ isc::data::ConstElementPtr elements;
+ if (use_alternate_parser_) {
+ std::ostringstream os;
+
+ os << "{ \"" << getController()->getAppName()
+ << "\": " << std::endl;
+ os << "{ \"string_test\": \"alt value\" } ";
+ os << " } " << std::endl;
+ elements = isc::data::Element::fromJSON(os.str());
+ }
+
+ return (elements);
+}
+
DStubController::~DStubController() {
}
/// @brief Defines the name of the configuration file to use
const char* DControllerTest::CFG_TEST_FILE = "d2-test-config.json";
-//************************** ObjectParser *************************
-
-ObjectParser::ObjectParser(const std::string& param_name,
- ObjectStoragePtr& object_values)
- : param_name_(param_name), object_values_(object_values) {
-}
-
-ObjectParser::~ObjectParser(){
-}
-
-void
-ObjectParser::build(isc::data::ConstElementPtr new_config) {
- if (SimFailure::shouldFailOn(SimFailure::ftElementBuild)) {
- // Simulates an error during element data parsing.
- isc_throw (DCfgMgrBaseError, "Simulated build exception");
- }
-
- value_ = new_config;
-}
-
-void
-ObjectParser::commit() {
- if (SimFailure::shouldFailOn(SimFailure::ftElementCommit)) {
- // Simulates an error while committing the parsed element data.
- throw std::runtime_error("Simulated commit exception");
- }
-
- object_values_->setParam(param_name_, value_,
- isc::data::Element::Position());
-}
-
//************************** DStubContext *************************
DStubContext::DStubContext(): object_values_(new ObjectStorage()) {
return (DCfgContextBasePtr (new DStubContext()));
}
-isc::dhcp::ParserPtr
-DStubCfgMgr::createConfigParser(const std::string& element_id,
- const isc::data::Element::Position& pos) {
- isc::dhcp::ParserPtr parser;
+void
+DStubCfgMgr::parseElement(const std::string& element_id,
+ isc::data::ConstElementPtr element) {
DStubContextPtr context
= boost::dynamic_pointer_cast<DStubContext>(getContext());
+
if (element_id == "bool_test") {
- parser.reset(new isc::dhcp::
- BooleanParser(element_id,
- context->getBooleanStorage()));
+ bool value = element->boolValue();
+ context->getBooleanStorage()->setParam(element_id, value,
+ element->getPosition());
} else if (element_id == "uint32_test") {
- parser.reset(new isc::dhcp::Uint32Parser(element_id,
- context->getUint32Storage()));
+ uint32_t value = element->intValue();
+ context->getUint32Storage()->setParam(element_id, value,
+ element->getPosition());
+
} else if (element_id == "string_test") {
- parser.reset(new isc::dhcp::StringParser(element_id,
- context->getStringStorage()));
+ std::string value = element->stringValue();
+ context->getStringStorage()->setParam(element_id, value,
+ element->getPosition());
} else {
// Fail only if SimFailure dictates we should. This makes it easier
// to test parse ordering, by permitting a wide range of element ids
if (SimFailure::shouldFailOn(SimFailure::ftElementUnknown)) {
isc_throw(DCfgMgrBaseError,
"Configuration parameter not supported: " << element_id
- << pos);
+ << element->getPosition());
}
// Going to assume anything else is an object element.
- parser.reset(new ObjectParser(element_id, context->getObjectStorage()));
+ context->getObjectStorage()->setParam(element_id, element,
+ element->getPosition());
}
parsed_order_.push_back(element_id);
- return (parser);
}
}; // namespace isc::process
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
namespace isc {
namespace process {
-/// @brief Provides a valid DHCP-DDNS configuration for testing basic
-/// parsing fundamentals.
-extern const char* valid_d2_config;
-
-
/// @brief Class is used to set a globally accessible value that indicates
/// a specific type of failure to simulate. Test derivations of base classes
/// can exercise error handling code paths by testing for specific SimFailure
record_signal_only_ = value;
}
+ /// @brief Determines if parseFile() implementation is used
+ ///
+ /// If true, parseFile() will return a Map of elements with fixed content,
+ /// mimicking a controller which is using alternate JSON parsing.
+ /// If false, parseFile() will return an empty pointer mimicking a
+ /// controller which is using original JSON parsing supplied by the
+ /// Element class.
+ ///
+ /// @param value boolean which if true enables record-only behavior
+ void useAlternateParser(bool value) {
+ use_alternate_parser_ = value;
+ }
+
protected:
/// @brief Handles additional command line options that are supported
/// by DStubController. This implementation supports an option "-x".
/// @param signum OS signal value received
virtual void processSignal(int signum);
+ /// @brief Provides alternate parse file implementation
+ ///
+ /// Overrides the base class implementation to mimick controllers which
+ /// implement alternate file parsing. If enabled via useAlternateParser()
+ /// the method will return a fixed map of elements reflecting the following
+ /// JSON:
+ ///
+ /// @code
+ /// { "<name>getController()->getAppName()" :
+ /// { "string_test": "alt value" };
+ /// }
+ ///
+ /// @endcode
+ ///
+ /// where <name> is getController()->getAppName()
+ ///
+ /// otherwise it return an empty pointer.
+ virtual isc::data::ConstElementPtr parseFile(const std::string&);
+
private:
/// @brief Constructor is private to protect singleton integrity.
DStubController();
/// @brief Boolean for controlling if signals are merely recorded.
bool record_signal_only_;
+ /// @brief Boolean for controlling if parseFile is "implemented"
+ bool use_alternate_parser_;
+
public:
virtual ~DStubController();
};
typedef isc::dhcp::ValueStorage<isc::data::ConstElementPtr> ObjectStorage;
typedef boost::shared_ptr<ObjectStorage> ObjectStoragePtr;
-/// @brief Simple parser derivation for parsing object elements.
-class ObjectParser : public isc::dhcp::DhcpConfigParser {
-public:
-
- /// @brief Constructor
- ///
- /// See @ref DhcpConfigParser class for details.
- ///
- /// @param param_name name of the parsed parameter
- ObjectParser(const std::string& param_name, ObjectStoragePtr& object_values);
-
- /// @brief Destructor
- virtual ~ObjectParser();
-
- /// @brief Builds parameter value.
- ///
- /// See @ref DhcpConfigParser class for details.
- ///
- /// @param new_config pointer to the new configuration
- /// @throw throws DCfgMgrBaseError if the SimFailure is set to
- /// ftElementBuild. This allows for the simulation of an
- /// exception during the build portion of parsing an element.
- virtual void build(isc::data::ConstElementPtr new_config);
-
- /// @brief Commits the parsed value to storage.
- ///
- /// See @ref DhcpConfigParser class for details.
- ///
- /// @throw throws DCfgMgrBaseError if SimFailure is set to ftElementCommit.
- /// This allows for the simulation of an exception during the commit
- /// portion of parsing an element.
- virtual void commit();
-
-private:
- /// name of the parsed parameter
- std::string param_name_;
-
- /// pointer to the parsed value of the parameter
- isc::data::ConstElementPtr value_;
-
- /// Pointer to the storage where committed value is stored.
- ObjectStoragePtr object_values_;
-};
-
-
/// @brief Test Derivation of the DCfgContextBase class.
///
/// This class is used to test basic functionality of configuration context.
/// @brief Destructor
virtual ~DStubCfgMgr();
- /// @brief Given an element_id returns an instance of the appropriate
- /// parser. It supports the element ids as described in the class brief.
+ /// @brief Parses the given element into the appropriate object
///
- /// @param element_id is the string name of the element as it will appear
- /// in the configuration set.
- /// @param pos position within the configuration text (or file) of element
- /// to be parsed. This is passed for error messaging.
+ /// The method supports three named elements:
///
- /// @return returns a ParserPtr to the parser instance.
- /// @throw throws DCfgMgrBaseError if SimFailure is ftElementUnknown.
- virtual isc::dhcp::ParserPtr
- createConfigParser(const std::string& element_id,
- const isc::data::Element::Position& pos
- = isc::data::Element::Position());
+ /// -# "bool_test"
+ /// -# "uint32_test"
+ /// -# "string_test"
+ ///
+ /// which are parsed and whose value is then stored in the
+ /// the appropriate context value store.
+ ///
+ /// Any other element_id is treated generically and stored
+ /// in the context's object store, unless the simulated
+ /// error has been set to SimFailure::ftElementUnknown.
+ ///
+ /// @param element_id name of the element to parse
+ /// @param element Element to parse
+ ///
+ /// @throw DCfgMgrBaseError if simulated error is set
+ /// to ftElementUnknown and element_id is not one of
+ /// the named elements.
+ virtual void parseElement(const std::string& element_id,
+ isc::data::ConstElementPtr element);
/// @brief Returns a summary of the configuration in the textual format.
///
asiolink::IntervalTimerPtr timer_;
};
-/// @brief Defines a small but valid DHCP-DDNS compliant configuration for
-/// testing configuration parsing fundamentals.
-extern const char* valid_d2_config;
-
}; // namespace isc::process
}; // namespace isc