Kea  1.5.0
dhcp6/parser_context.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef PARSER_CONTEXT_H
8 #define PARSER_CONTEXT_H
9 #include <string>
10 #include <map>
11 #include <vector>
12 #include <dhcp6/dhcp6_parser.h>
14 #include <exceptions/exceptions.h>
15 
16 // Tell Flex the lexer's prototype ...
17 #define YY_DECL isc::dhcp::Dhcp6Parser::symbol_type parser6_lex (Parser6Context& driver)
18 
19 // ... and declare it for the parser's sake.
21 
22 namespace isc {
23 namespace dhcp {
24 
29 public:
30  Dhcp6ParseError(const char* file, size_t line, const char* what) :
31  isc::Exception(file, line, what) { };
32 };
33 
34 
37 {
38 public:
39 
50  typedef enum {
53 
57 
63 
66 
69 
72 
75 
78 
81 
84 
87 
90 
93 
96 
99 
101 
103  Parser6Context();
104 
106  virtual ~Parser6Context();
107 
109  std::vector<isc::data::ElementPtr> stack_;
110 
115  void scanStringBegin(const std::string& str, ParserType type);
116 
122  void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
123 
125  void scanEnd();
126 
130  void includeFile(const std::string& filename);
131 
142  isc::data::ElementPtr parseString(const std::string& str,
143  ParserType parser_type);
144 
155  isc::data::ElementPtr parseFile(const std::string& filename,
156  ParserType parser_type);
157 
163  void error(const isc::dhcp::location& loc, const std::string& what);
164 
172  void error(const std::string& what);
173 
181  static void fatal(const std::string& what);
182 
190  isc::data::Element::Position loc2pos(isc::dhcp::location& loc);
191 
201  void require(const std::string& name,
203  isc::data::Element::Position close_loc);
204 
206  typedef enum {
208  NO_KEYWORD,
209 
211  CONFIG,
212 
215 
216  // not yet Dhcp4, DhcpDdns,
217 
220 
223 
226 
229 
232 
235 
238 
241 
244 
247 
250 
253 
256 
261 
264 
267 
270 
273 
276 
279 
282 
285 
288 
291 
294 
297 
300 
303 
306 
309 
312 
315 
317 
319  std::string file_;
320 
322  std::vector<std::string> files_;
323 
328  isc::dhcp::location loc_;
329 
331  std::vector<isc::dhcp::location> locs_;
332 
334  std::vector<struct yy_buffer_state*> states_;
335 
337  FILE* sfile_;
338 
344  std::vector<FILE*> sfiles_;
345 
348 
361  void enter(const ParserContext& ctx);
362 
366  void leave();
367 
371  const std::string contextName();
372 
373  private:
375  bool trace_scanning_;
376 
378  bool trace_parsing_;
379 
381  std::vector<ParserContext> cstack_;
382 
386  isc::data::ElementPtr parseCommon();
387 };
388 
389 }; // end of isc::eval namespace
390 }; // end of isc namespace
391 
392 #endif
dhcp6_parser.h
isc::dhcp::Parser6Context::RESERVATIONS
@ RESERVATIONS
Used while parsing Dhcp6/reservations structures.
Definition: dhcp6/parser_context.h:287
isc::dhcp::Parser6Context::Parser6Context
Parser6Context()
Default constructor.
Definition: dhcp6/parser_context.cc:20
isc::dhcp::Parser6Context::OPTION_DATA
@ OPTION_DATA
Used while parsing Dhcp6/option-data, Dhcp6/subnet6/option-data or anywhere option-data is present (c...
Definition: dhcp6/parser_context.h:260
isc::dhcp::Parser6Context::SHARED_NETWORK
@ SHARED_NETWORK
Used while parsing shared-networks structures.
Definition: dhcp6/parser_context.h:249
isc::dhcp::Parser6Context::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition: dhcp6/parser_context.h:52
isc::dhcp::Parser6Context::CONFIG_DATABASE
@ CONFIG_DATABASE
Used while parsing config-control/config-databases.
Definition: dhcp6/parser_context.h:314
isc::dhcp::Parser6Context::CONTROL_SOCKET
@ CONTROL_SOCKET
Used while parsing Dhcp6/control-socket structures.
Definition: dhcp6/parser_context.h:275
isc::dhcp::Parser6Context::PD_POOLS
@ PD_POOLS
Used while parsing Dhcp6/subnet6/pd-pools structures.
Definition: dhcp6/parser_context.h:284
isc::dhcp::Parser6Context::contextName
const std::string contextName()
Get the syntactic context name.
Definition: dhcp6/parser_context.cc:134
isc::dhcp::Parser6Context::PARSER_INTERFACES
@ PARSER_INTERFACES
This will parse the input as interfaces content.
Definition: dhcp6/parser_context.h:65
isc::dhcp::Parser6Context::PARSER_DHCP_DDNS
@ PARSER_DHCP_DDNS
This will parse the input as dhcp-ddns. (D2 client config)
Definition: dhcp6/parser_context.h:92
isc::dhcp::Parser6Context::PARSER_DHCP6
@ PARSER_DHCP6
This parser will parse the content as Dhcp6 config wrapped in a map (that's the regular config file)
Definition: dhcp6/parser_context.h:56
isc::dhcp::Parser6Context::DATABASE_TYPE
@ DATABASE_TYPE
Used while parsing Dhcp6/*-database/type.
Definition: dhcp6/parser_context.h:234
isc::dhcp::Parser6Context::RELAY
@ RELAY
Used while parsing Dhcp6/subnet6/relay structures.
Definition: dhcp6/parser_context.h:290
isc::dhcp::Parser6Context::scanFileBegin
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition: dhcp6_lexer.cc:5554
isc::dhcp::Parser6Context
Evaluation context, an interface to the expression evaluation.
Definition: dhcp6/parser_context.h:37
isc::dhcp::Parser6Context::ParserContext
ParserContext
Defines syntactic contexts for lexical tie-ins.
Definition: dhcp6/parser_context.h:206
isc::dhcp::Parser6Context::PARSER_CONFIG_CONTROL
@ PARSER_CONFIG_CONTROL
This will parse the input as config-control.
Definition: dhcp6/parser_context.h:95
isc::dhcp::Parser6Context::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition: dhcp6_lexer.cc:5536
isc::dhcp::Parser6Context::DHCP6
@ DHCP6
Definition: dhcp6/parser_context.h:214
isc::dhcp::Parser6Context::NCR_PROTOCOL
@ NCR_PROTOCOL
Used while parsing Dhcp6/dhcp-ddns/ncr-protocol.
Definition: dhcp6/parser_context.h:302
isc::dhcp::Parser6Context::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Used while parsing Logging/loggers/output_options structures.
Definition: dhcp6/parser_context.h:296
isc::dhcp::Parser6Context::require
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.
Definition: dhcp6/parser_context.cc:100
isc::dhcp::Parser6Context::PARSER_OPTION_DATA
@ PARSER_OPTION_DATA
This will parse the input as option data.
Definition: dhcp6/parser_context.h:86
isc::dhcp::Dhcp6ParseError::Dhcp6ParseError
Dhcp6ParseError(const char *file, size_t line, const char *what)
Definition: dhcp6/parser_context.h:30
isc::dhcp::Parser6Context::ParserType
ParserType
Defines currently supported scopes.
Definition: dhcp6/parser_context.h:50
parser_context_decl.h
isc::dhcp::Parser6Context::~Parser6Context
virtual ~Parser6Context()
destructor
Definition: dhcp6/parser_context.cc:25
isc::dhcp::Parser6Context::PARSER_HOOKS_LIBRARY
@ PARSER_HOOKS_LIBRARY
This will parse the input as hooks-library.
Definition: dhcp6/parser_context.h:89
isc::dhcp::Parser6Context::files_
std::vector< std::string > files_
File name stack.
Definition: dhcp6/parser_context.h:322
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc::dhcp::Parser6Context::HOST_RESERVATION_IDENTIFIERS
@ HOST_RESERVATION_IDENTIFIERS
Used while parsing Dhcp6/host-reservation-identifiers.
Definition: dhcp6/parser_context.h:240
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::dhcp::Parser6Context::locs_
std::vector< isc::dhcp::location > locs_
Location stack.
Definition: dhcp6/parser_context.h:331
isc::dhcp::Parser6Context::PARSER_OPTION_DEF
@ PARSER_OPTION_DEF
This will parse the input as option definition.
Definition: dhcp6/parser_context.h:83
isc::dhcp::Parser6Context::REPLACE_CLIENT_NAME
@ REPLACE_CLIENT_NAME
Used while parsing Dhcp6/dhcp-ddns/replace-client-name.
Definition: dhcp6/parser_context.h:308
isc::dhcp::Parser6Context::CONFIG_CONTROL
@ CONFIG_CONTROL
Used while parsing Dhcp4/config-control.
Definition: dhcp6/parser_context.h:311
isc::dhcp::Parser6Context::error
void error(const isc::dhcp::location &loc, const std::string &what)
Error handler.
Definition: dhcp6/parser_context.cc:73
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::dhcp::Parser6Context::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition: dhcp6/parser_context.h:109
isc::dhcp::Parser6Context::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition: dhcp6/parser_context.cc:37
isc::dhcp::Parser6Context::DUID_TYPE
@ DUID_TYPE
Used while parsing Dhcp6/server-id/type structures.
Definition: dhcp6/parser_context.h:272
isc::dhcp::Parser6Context::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition: dhcp6/parser_context.h:344
isc::dhcp::Parser6Context::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition: dhcp6/parser_context.h:334
isc::dhcp::Parser6Context::RESERVATION_MODE
@ RESERVATION_MODE
Used while parsing Dhcp6/reservation-mode.
Definition: dhcp6/parser_context.h:252
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition: data.h:88
isc::dhcp::Parser6Context::SERVER_ID
@ SERVER_ID
Used while parsing Dhcp6/server-id structures.
Definition: dhcp6/parser_context.h:269
isc::dhcp::Parser6Context::enter
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Definition: dhcp6/parser_context.cc:115
isc::dhcp::Parser6Context::PARSER_POOL6
@ PARSER_POOL6
This will parse the input as pool6 content.
Definition: dhcp6/parser_context.h:71
isc::dhcp::Parser6Context::DHCP_DDNS
@ DHCP_DDNS
Used while parsing Dhcp6/dhcp-ddns.
Definition: dhcp6/parser_context.h:299
isc::dhcp::Parser6Context::parseString
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Definition: dhcp6/parser_context.cc:30
isc::dhcp::Parser6Context::HOSTS_DATABASE
@ HOSTS_DATABASE
Used while parsing Dhcp6/hosts-database[s] structures.
Definition: dhcp6/parser_context.h:231
isc::dhcp::Parser6Context::leave
void leave()
Leave a syntactic context.
Definition: dhcp6/parser_context.cc:122
isc::dhcp::Parser6Context::loc_
isc::dhcp::location loc_
Location of the current token.
Definition: dhcp6/parser_context.h:328
isc::dhcp::Parser6Context::ctx_
ParserContext ctx_
Current syntactic context.
Definition: dhcp6/parser_context.h:347
isc::dhcp::Parser6Context::SUBPARSER_DHCP6
@ SUBPARSER_DHCP6
This parser will parse the content of Dhcp6 (without outer { } and without "Dhcp6").
Definition: dhcp6/parser_context.h:62
isc::dhcp::Parser6Context::sfile_
FILE * sfile_
sFile (aka FILE)
Definition: dhcp6/parser_context.h:337
isc::dhcp::Parser6Context::OPTION_DEF
@ OPTION_DEF
Used while parsing Dhcp6/option-def structures.
Definition: dhcp6/parser_context.h:255
YY_DECL
#define YY_DECL
Definition: dhcp6/parser_context.h:17
isc::dhcp::Parser6Context::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition: dhcp6_lexer.cc:5576
isc::dhcp::Parser6Context::NCR_FORMAT
@ NCR_FORMAT
Used while parsing Dhcp6/dhcp-ddns/ncr-format.
Definition: dhcp6/parser_context.h:305
isc::dhcp::Parser6Context::MAC_SOURCES
@ MAC_SOURCES
Used while parsing Dhcp6/mac-sources structures.
Definition: dhcp6/parser_context.h:237
isc::dhcp::Parser6Context::DHCP_QUEUE_CONTROL
@ DHCP_QUEUE_CONTROL
Used while parsing Dhcp4/dhcp-queue-control structures.
Definition: dhcp6/parser_context.h:278
isc::dhcp::Parser6Context::LOGGERS
@ LOGGERS
Used while parsing Logging/loggers structures.
Definition: dhcp6/parser_context.h:293
isc::dhcp::Parser6Context::loc2pos
isc::data::Element::Position loc2pos(isc::dhcp::location &loc)
Converts bison's position to one understandable by isc::data::Element.
Definition: dhcp6/parser_context.cc:91
isc::dhcp::Parser6Context::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing Dhcp6/hooks-libraries.
Definition: dhcp6/parser_context.h:243
isc::dhcp::Parser6Context::CLIENT_CLASSES
@ CLIENT_CLASSES
Used while parsing Dhcp6/client-classes structures.
Definition: dhcp6/parser_context.h:263
exceptions.h
isc::dhcp::Parser6Context::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition: dhcp6_lexer.cc:5597
isc::dhcp::Parser6Context::SUBNET6
@ SUBNET6
Used while parsing Dhcp6/Subnet6 structures.
Definition: dhcp6/parser_context.h:246
isc::dhcp::Parser6Context::file_
std::string file_
File name.
Definition: dhcp6/parser_context.h:319
isc::dhcp::Parser6Context::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition: dhcp6/parser_context.cc:85
isc::dhcp::Parser6Context::LOGGING
@ LOGGING
Used while parsing content of Logging.
Definition: dhcp6/parser_context.h:219
isc::dhcp::Parser6Context::PARSER_SUBNET6
@ PARSER_SUBNET6
This will parse the input as Subnet6 content.
Definition: dhcp6/parser_context.h:68
isc::dhcp::Parser6Context::CONFIG
@ CONFIG
Used while parsing content of Dhcp6.
Definition: dhcp6/parser_context.h:211
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::dhcp::Parser6Context::INTERFACES_CONFIG
@ INTERFACES_CONFIG
Used while parsing Dhcp6/interfaces structures.
Definition: dhcp6/parser_context.h:222
isc::dhcp::Dhcp6ParseError
Evaluation error exception raised when trying to parse.
Definition: dhcp6/parser_context.h:28
isc::dhcp::Parser6Context::NO_KEYWORD
@ NO_KEYWORD
This one is used in pure JSON mode.
Definition: dhcp6/parser_context.h:208
isc::dhcp::Parser6Context::LEASE_DATABASE
@ LEASE_DATABASE
Used while parsing Dhcp6/lease-database structures.
Definition: dhcp6/parser_context.h:228
isc::dhcp::Parser6Context::EXPIRED_LEASES_PROCESSING
@ EXPIRED_LEASES_PROCESSING
Used while parsing Dhcp6/expired-leases-processing.
Definition: dhcp6/parser_context.h:266
isc::dhcp::Parser6Context::PARSER_LOGGING
@ PARSER_LOGGING
This will parse the content of Logging.
Definition: dhcp6/parser_context.h:98
isc::dhcp::Parser6Context::SANITY_CHECKS
@ SANITY_CHECKS
Sanity checks.
Definition: dhcp6/parser_context.h:225
isc::dhcp::Parser6Context::POOLS
@ POOLS
Used while parsing Dhcp6/subnet6/pools structures.
Definition: dhcp6/parser_context.h:281
isc::dhcp::Parser6Context::PARSER_OPTION_DEFS
@ PARSER_OPTION_DEFS
This will parse the input option definitions (for tests).
Definition: dhcp6/parser_context.h:80
isc::dhcp::Parser6Context::PARSER_HOST_RESERVATION
@ PARSER_HOST_RESERVATION
This will parse the input as host-reservation.
Definition: dhcp6/parser_context.h:77
isc::dhcp::Parser6Context::PARSER_PD_POOL
@ PARSER_PD_POOL
This will parse the input as pd-pool content.
Definition: dhcp6/parser_context.h:74