Kea  1.5.0
dhcp4/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 <dhcp4/dhcp4_parser.h>
14 #include <exceptions/exceptions.h>
15 
16 // Tell Flex the lexer's prototype ...
17 #define YY_DECL isc::dhcp::Dhcp4Parser::symbol_type parser4_lex (Parser4Context& driver)
18 
19 // ... and declare it for the parser's sake.
21 
22 namespace isc {
23 namespace dhcp {
24 
29 public:
30  Dhcp4ParseError(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 
97 
100 
102  virtual ~Parser4Context();
103 
105  std::vector<isc::data::ElementPtr> stack_;
106 
111  void scanStringBegin(const std::string& str, ParserType type);
112 
118  void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
119 
121  void scanEnd();
122 
126  void includeFile(const std::string& filename);
127 
138  isc::data::ElementPtr parseString(const std::string& str,
139  ParserType parser_type);
140 
151  isc::data::ElementPtr parseFile(const std::string& filename,
152  ParserType parser_type);
153 
159  void error(const isc::dhcp::location& loc, const std::string& what);
160 
168  void error(const std::string& what);
169 
177  static void fatal(const std::string& what);
178 
186  isc::data::Element::Position loc2pos(isc::dhcp::location& loc);
187 
197  void require(const std::string& name,
199  isc::data::Element::Position close_loc);
200 
202  typedef enum {
204  NO_KEYWORD,
205 
207  CONFIG,
208 
211 
212  // not yet Dhcp6, DhcpDdns,
213 
216 
219 
222 
225 
228 
231 
234 
237 
240 
243 
246 
249 
252 
255 
260 
263 
266 
269 
272 
275 
278 
281 
284 
287 
290 
293 
296 
299 
302 
305 
308 
310 
312  std::string file_;
313 
315  std::vector<std::string> files_;
316 
321  isc::dhcp::location loc_;
322 
324  std::vector<isc::dhcp::location> locs_;
325 
327  std::vector<struct yy_buffer_state*> states_;
328 
330  FILE* sfile_;
331 
337  std::vector<FILE*> sfiles_;
338 
341 
354  void enter(const ParserContext& ctx);
355 
359  void leave();
360 
364  const std::string contextName();
365 
366  private:
368  bool trace_scanning_;
369 
371  bool trace_parsing_;
372 
374  std::vector<ParserContext> cstack_;
375 
379  isc::data::ElementPtr parseCommon();
380 };
381 
382 }; // end of isc::eval namespace
383 }; // end of isc namespace
384 
385 #endif
isc::dhcp::Parser4Context::DHCP_SOCKET_TYPE
@ DHCP_SOCKET_TYPE
Used while parsing Dhcp4/interfaces/dhcp-socket-type structures.
Definition: dhcp4/parser_context.h:224
dhcp4_parser.h
isc::dhcp::Dhcp4ParseError
Evaluation error exception raised when trying to parse.
Definition: dhcp4/parser_context.h:28
isc::dhcp::Parser4Context::HOSTS_DATABASE
@ HOSTS_DATABASE
Used while parsing Dhcp4/hosts-database[s] structures.
Definition: dhcp4/parser_context.h:233
isc::dhcp::Parser4Context::DATABASE_TYPE
@ DATABASE_TYPE
Used while parsing Dhcp4/*-database/type.
Definition: dhcp4/parser_context.h:236
isc::dhcp::Parser4Context::PARSER_DHCP_DDNS
@ PARSER_DHCP_DDNS
This will parse the input as dhcp-ddns.
Definition: dhcp4/parser_context.h:89
isc::dhcp::Parser4Context::POOLS
@ POOLS
Used while parsing Dhcp4/subnet4/pools structures.
Definition: dhcp4/parser_context.h:277
isc::dhcp::Parser4Context::DHCP_QUEUE_CONTROL
@ DHCP_QUEUE_CONTROL
Used while parsing Dhcp4/dhcp-queue-control structures.
Definition: dhcp4/parser_context.h:274
isc::dhcp::Parser4Context
Evaluation context, an interface to the expression evaluation.
Definition: dhcp4/parser_context.h:37
YY_DECL
#define YY_DECL
Definition: dhcp4/parser_context.h:17
isc::dhcp::Parser4Context::OUTBOUND_INTERFACE
@ OUTBOUND_INTERFACE
Used while parsing Dhcp4/interfaces/outbound-interface structures.
Definition: dhcp4/parser_context.h:227
isc::dhcp::Parser4Context::RESERVATION_MODE
@ RESERVATION_MODE
Used while parsing Dhcp4/reservation-mode.
Definition: dhcp4/parser_context.h:251
isc::dhcp::Parser4Context::INTERFACES_CONFIG
@ INTERFACES_CONFIG
Used while parsing Dhcp4/interfaces structures.
Definition: dhcp4/parser_context.h:218
isc::dhcp::Parser4Context::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Used while parsing Logging/loggers/output_options structures.
Definition: dhcp4/parser_context.h:289
isc::dhcp::Parser4Context::SUBNET4
@ SUBNET4
Used while parsing Dhcp4/Subnet4 structures.
Definition: dhcp4/parser_context.h:245
isc::dhcp::Parser4Context::SANITY_CHECKS
@ SANITY_CHECKS
Sanity checks.
Definition: dhcp4/parser_context.h:221
isc::dhcp::Parser4Context::EXPIRED_LEASES_PROCESSING
@ EXPIRED_LEASES_PROCESSING
Used while parsing Dhcp4/expired-leases-processing.
Definition: dhcp4/parser_context.h:265
isc::dhcp::Parser4Context::OPTION_DEF
@ OPTION_DEF
Used while parsing Dhcp4/option-def structures.
Definition: dhcp4/parser_context.h:254
isc::dhcp::Parser4Context::CONFIG
@ CONFIG
Used while parsing content of Dhcp4.
Definition: dhcp4/parser_context.h:207
isc::dhcp::Parser4Context::CONFIG_CONTROL
@ CONFIG_CONTROL
Used while parsing Dhcp4/config-control.
Definition: dhcp4/parser_context.h:304
isc::dhcp::Parser4Context::parseString
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Definition: dhcp4/parser_context.cc:30
isc::dhcp::Parser4Context::ParserType
ParserType
Defines currently supported scopes.
Definition: dhcp4/parser_context.h:50
isc::dhcp::Parser4Context::DHCP_DDNS
@ DHCP_DDNS
Used while parsing Dhcp4/dhcp-ddns.
Definition: dhcp4/parser_context.h:292
isc::dhcp::Parser4Context::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition: dhcp4/parser_context.cc:37
isc::dhcp::Parser4Context::Parser4Context
Parser4Context()
Default constructor.
Definition: dhcp4/parser_context.cc:20
isc::dhcp::Parser4Context::enter
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Definition: dhcp4/parser_context.cc:115
isc::dhcp::Parser4Context::loc_
isc::dhcp::location loc_
Location of the current token.
Definition: dhcp4/parser_context.h:321
isc::dhcp::Parser4Context::PARSER_OPTION_DATA
@ PARSER_OPTION_DATA
This will parse the input as option data.
Definition: dhcp4/parser_context.h:83
isc::dhcp::Parser4Context::PARSER_LOGGING
@ PARSER_LOGGING
This will parse the content of Logging.
Definition: dhcp4/parser_context.h:95
isc::dhcp::Parser4Context::files_
std::vector< std::string > files_
File name stack.
Definition: dhcp4/parser_context.h:315
isc::dhcp::Parser4Context::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition: dhcp4/parser_context.h:337
isc::dhcp::Parser4Context::DHCP4
@ DHCP4
Definition: dhcp4/parser_context.h:210
isc::dhcp::Parser4Context::RESERVATIONS
@ RESERVATIONS
Used while parsing Dhcp4/reservations structures.
Definition: dhcp4/parser_context.h:280
isc::dhcp::Parser4Context::sfile_
FILE * sfile_
sFile (aka FILE)
Definition: dhcp4/parser_context.h:330
isc::dhcp::Parser4Context::NCR_PROTOCOL
@ NCR_PROTOCOL
Used while parsing Dhcp4/dhcp-ddns/ncr-protocol.
Definition: dhcp4/parser_context.h:295
isc::dhcp::Parser4Context::PARSER_POOL4
@ PARSER_POOL4
This will parse the input as pool4 content.
Definition: dhcp4/parser_context.h:71
isc::dhcp::Parser4Context::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition: dhcp4/parser_context.h:327
isc::dhcp::Parser4Context::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition: dhcp4_lexer.cc:5541
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
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::Parser4Context::ctx_
ParserContext ctx_
Current syntactic context.
Definition: dhcp4/parser_context.h:340
isc::dhcp::Parser4Context::contextName
const std::string contextName()
Get the syntactic context name.
Definition: dhcp4/parser_context.cc:134
isc::dhcp::Parser4Context::PARSER_DHCP4
@ PARSER_DHCP4
This parser will parse the content as Dhcp4 config wrapped in a map (that's the regular config file)
Definition: dhcp4/parser_context.h:56
isc::dhcp::Parser4Context::CLIENT_CLASSES
@ CLIENT_CLASSES
Used while parsing Dhcp4/client-classes structures.
Definition: dhcp4/parser_context.h:262
isc::dhcp::Parser4Context::LOGGERS
@ LOGGERS
Used while parsing Logging/loggers structures.
Definition: dhcp4/parser_context.h:286
isc::dhcp::Parser4Context::PARSER_HOOKS_LIBRARY
@ PARSER_HOOKS_LIBRARY
This will parse the input as hooks-library.
Definition: dhcp4/parser_context.h:86
isc::dhcp::Parser4Context::locs_
std::vector< isc::dhcp::location > locs_
Location stack.
Definition: dhcp4/parser_context.h:324
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition: data.h:88
isc::dhcp::Parser4Context::REPLACE_CLIENT_NAME
@ REPLACE_CLIENT_NAME
Used while parsing Dhcp4/dhcp-ddns/replace-client-name.
Definition: dhcp4/parser_context.h:301
isc::dhcp::Parser4Context::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition: dhcp4_lexer.cc:5501
isc::dhcp::Parser4Context::scanFileBegin
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition: dhcp4_lexer.cc:5519
isc::dhcp::Parser4Context::PARSER_OPTION_DEF
@ PARSER_OPTION_DEF
This will parse the input as option definition.
Definition: dhcp4/parser_context.h:80
isc::dhcp::Parser4Context::NO_KEYWORD
@ NO_KEYWORD
This one is used in pure JSON mode.
Definition: dhcp4/parser_context.h:204
isc::dhcp::Parser4Context::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition: dhcp4/parser_context.cc:85
isc::dhcp::Parser4Context::loc2pos
isc::data::Element::Position loc2pos(isc::dhcp::location &loc)
Converts bison's position to one understandable by isc::data::Element.
Definition: dhcp4/parser_context.cc:91
isc::dhcp::Parser4Context::PARSER_SUBNET4
@ PARSER_SUBNET4
This will parse the input as Subnet4 content.
Definition: dhcp4/parser_context.h:68
isc::dhcp::Parser4Context::file_
std::string file_
File name.
Definition: dhcp4/parser_context.h:312
isc::dhcp::Parser4Context::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: dhcp4/parser_context.cc:100
isc::dhcp::Parser4Context::SHARED_NETWORK
@ SHARED_NETWORK
Used while parsing shared-networks structures.
Definition: dhcp4/parser_context.h:248
isc::dhcp::Parser4Context::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition: dhcp4_lexer.cc:5562
isc::dhcp::Parser4Context::NCR_FORMAT
@ NCR_FORMAT
Used while parsing Dhcp4/dhcp-ddns/ncr-format.
Definition: dhcp4/parser_context.h:298
isc::dhcp::Parser4Context::LEASE_DATABASE
@ LEASE_DATABASE
Used while parsing Dhcp4/lease-database structures.
Definition: dhcp4/parser_context.h:230
parser_context_decl.h
isc::dhcp::Parser4Context::HOST_RESERVATION_IDENTIFIERS
@ HOST_RESERVATION_IDENTIFIERS
Used while parsing Dhcp4/host-reservation-identifiers.
Definition: dhcp4/parser_context.h:239
isc::dhcp::Parser4Context::SERVER_ID
@ SERVER_ID
Used while parsing Dhcp4/server-id structures.
Definition: dhcp4/parser_context.h:268
exceptions.h
isc::dhcp::Parser4Context::~Parser4Context
virtual ~Parser4Context()
destructor
Definition: dhcp4/parser_context.cc:25
isc::dhcp::Parser4Context::error
void error(const isc::dhcp::location &loc, const std::string &what)
Error handler.
Definition: dhcp4/parser_context.cc:73
isc::dhcp::Parser4Context::CONFIG_DATABASE
@ CONFIG_DATABASE
Used while parsing config-control/config-databases.
Definition: dhcp4/parser_context.h:307
isc::dhcp::Parser4Context::LOGGING
@ LOGGING
Used while parsing content of Logging.
Definition: dhcp4/parser_context.h:215
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
isc::dhcp::Parser4Context::CONTROL_SOCKET
@ CONTROL_SOCKET
Used while parsing Dhcp4/control-socket structures.
Definition: dhcp4/parser_context.h:271
isc::dhcp::Parser4Context::leave
void leave()
Leave a syntactic context.
Definition: dhcp4/parser_context.cc:122
isc::dhcp::Dhcp4ParseError::Dhcp4ParseError
Dhcp4ParseError(const char *file, size_t line, const char *what)
Definition: dhcp4/parser_context.h:30
isc::dhcp::Parser4Context::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition: dhcp4/parser_context.h:52
isc::dhcp::Parser4Context::PARSER_CONFIG_CONTROL
@ PARSER_CONFIG_CONTROL
This will parse the input as config-control.
Definition: dhcp4/parser_context.h:92
isc::dhcp::Parser4Context::SUBPARSER_DHCP4
@ SUBPARSER_DHCP4
This parser will parse the content of Dhcp4 (without outer { } and without "Dhcp4").
Definition: dhcp4/parser_context.h:62
isc::dhcp::Parser4Context::PARSER_OPTION_DEFS
@ PARSER_OPTION_DEFS
This will parse the input option definitions (for tests).
Definition: dhcp4/parser_context.h:77
isc::dhcp::Parser4Context::ParserContext
ParserContext
Defines syntactic contexts for lexical tie-ins.
Definition: dhcp4/parser_context.h:202
isc::dhcp::Parser4Context::RELAY
@ RELAY
Used while parsing Dhcp4/subnet4relay structures.
Definition: dhcp4/parser_context.h:283
isc::dhcp::Parser4Context::PARSER_HOST_RESERVATION
@ PARSER_HOST_RESERVATION
This will parse the input as host-reservation.
Definition: dhcp4/parser_context.h:74
isc::dhcp::Parser4Context::OPTION_DATA
@ OPTION_DATA
Used while parsing Dhcp4/option-data, Dhcp4/subnet4/option-data or anywhere option-data is present (c...
Definition: dhcp4/parser_context.h:259
isc::dhcp::Parser4Context::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition: dhcp4/parser_context.h:105
isc::dhcp::Parser4Context::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing Dhcp4/hooks-libraries.
Definition: dhcp4/parser_context.h:242
isc::dhcp::Parser4Context::PARSER_INTERFACES
@ PARSER_INTERFACES
This will parse the input as interfaces content.
Definition: dhcp4/parser_context.h:65