14#include <boost/lexical_cast.hpp>
23 : sfile_(nullptr), ctx_(NO_KEYWORD), trace_scanning_(false),
24 trace_parsing_(false) {
33 return (parseCommon());
38 FILE* f = fopen(filename.c_str(),
"r");
43 return (parseCommon());
47Parser6Context::parseCommon() {
51 parser.set_debug_level(trace_parsing_);
53 int res = parser.parse();
72 const std::string& what,
93 const std::string& file = *loc.begin.filename;
94 const uint32_t line = loc.begin.line;
95 const uint32_t pos = loc.begin.column;
106 "missing parameter '" << name <<
"' ("
107 <<
stack_.back()->getPosition() <<
") ["
109 << open_loc <<
" and " << close_loc <<
"]");
121 <<
" map (previous at " << value->getPosition() <<
")");
124 <<
" entries in JSON"
125 <<
" map (previous at " << value->getPosition() <<
")");
132 cstack_.push_back(
ctx_);
139 if (cstack_.empty()) {
140 fatal(
"unbalanced syntactic context");
143 ctx_ = cstack_.back();
151 return (
"__no keyword__");
157 return (
"interfaces-config");
159 return (
"lease-database");
161 return (
"hosts-database");
163 return (
"database-on-fail");
165 return (
"mac-sources");
167 return (
"host-reservation-identifiers");
169 return (
"hooks-libraries");
173 return (
"option-def");
175 return (
"option-data");
177 return (
"client-classes");
179 return (
"expired-leases-processing");
181 return (
"server-id");
183 return (
"duid-type");
185 return (
"control-socket");
187 return (
"control-socket-type");
189 return (
"authentication");
191 return (
"auth-type");
195 return (
"http-headers");
197 return (
"dhcp-queue-control");
199 return (
"multi-threading");
205 return (
"reservations");
211 return (
"output-options");
213 return (
"dhcp-ddns");
215 return (
"ncr-protocol");
217 return (
"ncr-format");
219 return (
"replace-client-name");
221 return (
"shared-networks");
223 return (
"sanity-checks");
225 return (
"config-control");
227 return (
"config-database");
229 return (
"compatibility");
231 return (
"ddns-conflict-resolution-mode");
233 return (
"__unknown__");
239 const std::string& what) {
240 std::ostringstream msg;
241 msg << loc <<
": " << what;
248 warning(loc,
"Extraneous comma. A piece of configuration may have been omitted.");
Evaluation error exception raised when trying to parse.
void require(const std::string &name, isc::data::Element::Position open_loc, isc::data::Element::Position close_loc)
Check if a required parameter is present.
static void fatal(const std::string &what)
Fatal error handler.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
isc::data::Element::Position loc2pos(isc::dhcp::location &loc)
Converts bison's position to one understandable by isc::data::Element.
virtual ~Parser6Context()
destructor
void warning(const isc::dhcp::location &loc, const std::string &what)
Warning handler.
void leave()
Leave a syntactic context.
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
void enter(const ParserContext &ctx)
Enter a new syntactic context.
void error(const isc::dhcp::location &loc, const std::string &what, size_t pos=0)
Error handler.
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Parser6Context()
Default constructor.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
ParserContext
Defines syntactic contexts for lexical tie-ins.
@ LOGGERS
Used while parsing Dhcp6/loggers structures.
@ CLIENT_CLASSES
Used while parsing Dhcp6/client-classes structures.
@ DATABASE_ON_FAIL
Used while parsing Dhcp6/*-database/on-fail.
@ OPTION_DEF
Used while parsing Dhcp6/option-def structures.
@ POOLS
Used while parsing Dhcp6/subnet6/pools structures.
@ AUTHENTICATION
Used while parsing Dhcp6/control-socket/authentication structures.
@ EXPIRED_LEASES_PROCESSING
Used while parsing Dhcp6/expired-leases-processing.
@ OPTION_DATA
Used while parsing Dhcp6/option-data, Dhcp6/subnet6/option-data or anywhere option-data is present (c...
@ CONTROL_SOCKET
Used while parsing Dhcp6/control-socket structures.
@ SANITY_CHECKS
Sanity checks.
@ DHCP_QUEUE_CONTROL
Used while parsing Dhcp6/dhcp-queue-control structures.
@ SERVER_ID
Used while parsing Dhcp6/server-id structures.
@ HOSTS_DATABASE
Used while parsing Dhcp6/hosts-database[s] structures.
@ SUBNET6
Used while parsing Dhcp6/Subnet6 structures.
@ RESERVATIONS
Used while parsing Dhcp6/reservations structures.
@ CONFIG_DATABASE
Used while parsing config-control/config-databases.
@ AUTH_TYPE
Used while parsing Dhcp6/control-socket/authentication/type structures.
@ DHCP_DDNS
Used while parsing Dhcp6/dhcp-ddns.
@ COMPATIBILITY
Used while parsing compatibility parameters.
@ INTERFACES_CONFIG
Used while parsing Dhcp6/interfaces structures.
@ DUID_TYPE
Used while parsing Dhcp6/server-id/type structures.
@ HOOKS_LIBRARIES
Used while parsing Dhcp6/hooks-libraries.
@ CONFIG
Used while parsing content of Dhcp6.
@ DDNS_CONFLICT_RESOLUTION_MODE
Used while parsing Dhcp6/ddns-conflict-resolution-mode.
@ LEASE_DATABASE
Used while parsing Dhcp6/lease-database structures.
@ CLIENTS
Used while parsing Dhcp6/control-socket/authentication/clients structures.
@ NCR_PROTOCOL
Used while parsing Dhcp6/dhcp-ddns/ncr-protocol.
@ RELAY
Used while parsing Dhcp6/subnet6/relay structures.
@ OUTPUT_OPTIONS
Used while parsing Dhcp6/loggers/output-options structures.
@ HOST_RESERVATION_IDENTIFIERS
Used while parsing Dhcp6/host-reservation-identifiers.
@ NCR_FORMAT
Used while parsing Dhcp6/dhcp-ddns/ncr-format.
@ REPLACE_CLIENT_NAME
Used while parsing Dhcp6/dhcp-ddns/replace-client-name.
@ DHCP_MULTI_THREADING
Used while parsing Dhcp6/multi-threading structures.
@ NO_KEYWORD
This one is used in pure JSON mode.
@ SHARED_NETWORK
Used while parsing shared-networks structures.
@ CONTROL_SOCKET_TYPE
Used while parsing Dhcp6/control-socket/socket-type structures.
@ PD_POOLS
Used while parsing Dhcp6/subnet6/pd-pools structures.
@ MAC_SOURCES
Used while parsing Dhcp6/mac-sources structures.
@ CONFIG_CONTROL
Used while parsing Dhcp6/config-control.
void warnAboutExtraCommas(const isc::dhcp::location &loc)
Warning for extra commas.
void scanEnd()
Method called after the last tokens are scanned.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
ParserType
Defines currently supported scopes.
const std::string contextName()
Get the syntactic context name.
ParserContext ctx_
Current syntactic context.
Define the isc::dhcp::parser class.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
const isc::log::MessageID DHCP6_CONFIG_SYNTAX_WARNING
isc::log::Logger dhcp6_logger(DHCP6_APP_LOGGER_NAME)
Base logger for DHCPv6 server.
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.