Kea: parser_context.h Source File

| Kea 3.2.0-git

dhcp6/parser_context.h
Go to the documentation of this file.
1// Copyright (C) 2015-2025 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>
13#include <dhcp6/parser_context_decl.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.
20 YY_DECL;
21
22namespace isc {
23namespace dhcp {
24
28 class Dhcp6ParseError : public isc::Exception {
29public:
30 Dhcp6ParseError(const char* file, size_t line, const char* what) :
31 isc::Exception(file, line, what) { }
32};
33
35 class Parser6Context
36{
37public:
38
49 typedef enum {
51 PARSER_JSON,
52
55 PARSER_DHCP6,
56
61 SUBPARSER_DHCP6,
62
64 PARSER_INTERFACES,
65
67 PARSER_SUBNET6,
68
70 PARSER_POOL6,
71
73 PARSER_PD_POOL,
74
76 PARSER_HOST_RESERVATION,
77
79 PARSER_OPTION_DEFS,
80
82 PARSER_OPTION_DEF,
83
85 PARSER_OPTION_DATA,
86
88 PARSER_HOOKS_LIBRARY,
89
91 PARSER_DHCP_DDNS,
92
94 PARSER_CONFIG_CONTROL,
95 } ParserType;
96
98 Parser6Context();
99
101 virtual ~Parser6Context();
102
104 std::vector<isc::data::ElementPtr> stack_;
105
110 void scanStringBegin(const std::string& str, ParserType type);
111
117 void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
118
120 void scanEnd();
121
125 void includeFile(const std::string& filename);
126
137 isc::data::ElementPtr parseString(const std::string& str,
138 ParserType parser_type);
139
150 isc::data::ElementPtr parseFile(const std::string& filename,
151 ParserType parser_type);
152
162 void error(const isc::dhcp::location& loc,
163 const std::string& what,
164 size_t pos = 0);
165
173 void error(const std::string& what);
174
182 static void fatal(const std::string& what);
183
191 isc::data::Element::Position loc2pos(isc::dhcp::location& loc);
192
202 void require(const std::string& name,
203 isc::data::Element::Position open_loc,
204 isc::data::Element::Position close_loc);
205
214 void unique(const std::string& name,
215 isc::data::Element::Position loc);
216
223 void warning(const isc::dhcp::location& loc, const std::string& what);
224
230 void warnAboutExtraCommas(const isc::dhcp::location& loc);
231
233 typedef enum {
235 NO_KEYWORD,
236
238 CONFIG,
239
241 DHCP6,
242
244 INTERFACES_CONFIG,
245
247 SANITY_CHECKS,
248
250 LEASE_DATABASE,
251
253 HOSTS_DATABASE,
254
256 DATABASE_ON_FAIL,
257
259 SSL_MODE,
260
262 MAC_SOURCES,
263
265 HOST_RESERVATION_IDENTIFIERS,
266
268 HOOKS_LIBRARIES,
269
271 SUBNET6,
272
274 SHARED_NETWORK,
275
277 OPTION_DEF,
278
282 OPTION_DATA,
283
285 CLIENT_CLASSES,
286
288 EXPIRED_LEASES_PROCESSING,
289
291 SERVER_ID,
292
294 DUID_TYPE,
295
297 CONTROL_SOCKET,
298
300 CONTROL_SOCKET_TYPE,
301
303 AUTHENTICATION,
304
307 AUTH_TYPE,
308
311 CLIENTS,
312
314 HTTP_HEADERS,
315
317 DHCP_QUEUE_CONTROL,
318
320 DHCP_MULTI_THREADING,
321
323 POOLS,
324
326 PD_POOLS,
327
329 RESERVATIONS,
330
332 RELAY,
333
335 LOGGERS,
336
338 OUTPUT_OPTIONS,
339
341 DHCP_DDNS,
342
344 NCR_PROTOCOL,
345
347 NCR_FORMAT,
348
350 REPLACE_CLIENT_NAME,
351
353 CONFIG_CONTROL,
354
356 CONFIG_DATABASE,
357
359 COMPATIBILITY,
360
362 DDNS_CONFLICT_RESOLUTION_MODE,
363 } ParserContext;
364
366 std::string file_;
367
369 std::vector<std::string> files_;
370
375 isc::dhcp::location loc_;
376
378 std::vector<isc::dhcp::location> locs_;
379
381 std::vector<struct yy_buffer_state*> states_;
382
384 FILE* sfile_;
385
391 std::vector<FILE*> sfiles_;
392
394 ParserContext ctx_;
395
408 void enter(const ParserContext& ctx);
409
413 void leave();
414
418 const std::string contextName();
419
420 private:
422 bool trace_scanning_;
423
425 bool trace_parsing_;
426
428 std::vector<ParserContext> cstack_;
429
433 isc::data::ElementPtr parseCommon();
434};
435
436} // namespace dhcp
437} // namespace isc
438
439#endif
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition exceptions/exceptions.h:23
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
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::Dhcp6ParseError::Dhcp6ParseError
Dhcp6ParseError(const char *file, size_t line, const char *what)
Definition dhcp6/parser_context.h:30
isc::dhcp::Parser6Context::file_
std::string file_
File name.
Definition dhcp6/parser_context.h:366
isc::dhcp::Parser6Context::locs_
std::vector< isc::dhcp::location > locs_
Location stack.
Definition dhcp6/parser_context.h:378
isc::dhcp::Parser6Context::loc_
isc::dhcp::location loc_
Location of the current token.
Definition dhcp6/parser_context.h:375
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::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::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:92
isc::dhcp::Parser6Context::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition dhcp6_lexer.cc:7309
isc::dhcp::Parser6Context::~Parser6Context
virtual ~Parser6Context()
destructor
Definition dhcp6/parser_context.cc:27
isc::dhcp::Parser6Context::sfile_
FILE * sfile_
sFile (aka FILE)
Definition dhcp6/parser_context.h:384
isc::dhcp::Parser6Context::warning
void warning(const isc::dhcp::location &loc, const std::string &what)
Warning handler.
Definition dhcp6/parser_context.cc:240
isc::dhcp::Parser6Context::leave
void leave()
Leave a syntactic context.
Definition dhcp6/parser_context.cc:137
isc::dhcp::Parser6Context::unique
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
Definition dhcp6/parser_context.cc:114
isc::dhcp::Parser6Context::enter
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Definition dhcp6/parser_context.cc:131
isc::dhcp::Parser6Context::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition dhcp6/parser_context.h:104
isc::dhcp::Parser6Context::Parser6Context
Parser6Context()
Default constructor.
Definition dhcp6/parser_context.cc:22
isc::dhcp::Parser6Context::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition dhcp6_lexer.cc:7248
isc::dhcp::Parser6Context::files_
std::vector< std::string > files_
File name stack.
Definition dhcp6/parser_context.h:369
isc::dhcp::Parser6Context::ParserContext
ParserContext
Defines syntactic contexts for lexical tie-ins.
Definition dhcp6/parser_context.h:233
isc::dhcp::Parser6Context::LOGGERS
@ LOGGERS
Used while parsing Dhcp6/loggers structures.
Definition dhcp6/parser_context.h:335
isc::dhcp::Parser6Context::DHCP6
@ DHCP6
Definition dhcp6/parser_context.h:241
isc::dhcp::Parser6Context::CLIENT_CLASSES
@ CLIENT_CLASSES
Used while parsing Dhcp6/client-classes structures.
Definition dhcp6/parser_context.h:285
isc::dhcp::Parser6Context::DATABASE_ON_FAIL
@ DATABASE_ON_FAIL
Used while parsing Dhcp6/*-database/on-fail.
Definition dhcp6/parser_context.h:256
isc::dhcp::Parser6Context::OPTION_DEF
@ OPTION_DEF
Used while parsing Dhcp6/option-def structures.
Definition dhcp6/parser_context.h:277
isc::dhcp::Parser6Context::POOLS
@ POOLS
Used while parsing Dhcp6/subnet6/pools structures.
Definition dhcp6/parser_context.h:323
isc::dhcp::Parser6Context::AUTHENTICATION
@ AUTHENTICATION
Used while parsing Dhcp6/control-socket/authentication structures.
Definition dhcp6/parser_context.h:303
isc::dhcp::Parser6Context::EXPIRED_LEASES_PROCESSING
@ EXPIRED_LEASES_PROCESSING
Used while parsing Dhcp6/expired-leases-processing.
Definition dhcp6/parser_context.h:288
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:282
isc::dhcp::Parser6Context::CONTROL_SOCKET
@ CONTROL_SOCKET
Used while parsing Dhcp6/control-socket structures.
Definition dhcp6/parser_context.h:297
isc::dhcp::Parser6Context::SANITY_CHECKS
@ SANITY_CHECKS
Sanity checks.
Definition dhcp6/parser_context.h:247
isc::dhcp::Parser6Context::DHCP_QUEUE_CONTROL
@ DHCP_QUEUE_CONTROL
Used while parsing Dhcp6/dhcp-queue-control structures.
Definition dhcp6/parser_context.h:317
isc::dhcp::Parser6Context::SERVER_ID
@ SERVER_ID
Used while parsing Dhcp6/server-id structures.
Definition dhcp6/parser_context.h:291
isc::dhcp::Parser6Context::HOSTS_DATABASE
@ HOSTS_DATABASE
Used while parsing Dhcp6/hosts-database[s] structures.
Definition dhcp6/parser_context.h:253
isc::dhcp::Parser6Context::SUBNET6
@ SUBNET6
Used while parsing Dhcp6/Subnet6 structures.
Definition dhcp6/parser_context.h:271
isc::dhcp::Parser6Context::RESERVATIONS
@ RESERVATIONS
Used while parsing Dhcp6/reservations structures.
Definition dhcp6/parser_context.h:329
isc::dhcp::Parser6Context::CONFIG_DATABASE
@ CONFIG_DATABASE
Used while parsing config-control/config-databases.
Definition dhcp6/parser_context.h:356
isc::dhcp::Parser6Context::AUTH_TYPE
@ AUTH_TYPE
Used while parsing Dhcp6/control-socket/authentication/type structures.
Definition dhcp6/parser_context.h:307
isc::dhcp::Parser6Context::SSL_MODE
@ SSL_MODE
Used while parsing Dhcp6/*-database/ssl-mode.
Definition dhcp6/parser_context.h:259
isc::dhcp::Parser6Context::DHCP_DDNS
@ DHCP_DDNS
Used while parsing Dhcp6/dhcp-ddns.
Definition dhcp6/parser_context.h:341
isc::dhcp::Parser6Context::HTTP_HEADERS
@ HTTP_HEADERS
Definition dhcp6/parser_context.h:314
isc::dhcp::Parser6Context::COMPATIBILITY
@ COMPATIBILITY
Used while parsing compatibility parameters.
Definition dhcp6/parser_context.h:359
isc::dhcp::Parser6Context::INTERFACES_CONFIG
@ INTERFACES_CONFIG
Used while parsing Dhcp6/interfaces structures.
Definition dhcp6/parser_context.h:244
isc::dhcp::Parser6Context::DUID_TYPE
@ DUID_TYPE
Used while parsing Dhcp6/server-id/type structures.
Definition dhcp6/parser_context.h:294
isc::dhcp::Parser6Context::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing Dhcp6/hooks-libraries.
Definition dhcp6/parser_context.h:268
isc::dhcp::Parser6Context::CONFIG
@ CONFIG
Used while parsing content of Dhcp6.
Definition dhcp6/parser_context.h:238
isc::dhcp::Parser6Context::DDNS_CONFLICT_RESOLUTION_MODE
@ DDNS_CONFLICT_RESOLUTION_MODE
Used while parsing Dhcp6/ddns-conflict-resolution-mode.
Definition dhcp6/parser_context.h:362
isc::dhcp::Parser6Context::LEASE_DATABASE
@ LEASE_DATABASE
Used while parsing Dhcp6/lease-database structures.
Definition dhcp6/parser_context.h:250
isc::dhcp::Parser6Context::CLIENTS
@ CLIENTS
Used while parsing Dhcp6/control-socket/authentication/clients structures.
Definition dhcp6/parser_context.h:311
isc::dhcp::Parser6Context::NCR_PROTOCOL
@ NCR_PROTOCOL
Used while parsing Dhcp6/dhcp-ddns/ncr-protocol.
Definition dhcp6/parser_context.h:344
isc::dhcp::Parser6Context::RELAY
@ RELAY
Used while parsing Dhcp6/subnet6/relay structures.
Definition dhcp6/parser_context.h:332
isc::dhcp::Parser6Context::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Used while parsing Dhcp6/loggers/output-options structures.
Definition dhcp6/parser_context.h:338
isc::dhcp::Parser6Context::HOST_RESERVATION_IDENTIFIERS
@ HOST_RESERVATION_IDENTIFIERS
Used while parsing Dhcp6/host-reservation-identifiers.
Definition dhcp6/parser_context.h:265
isc::dhcp::Parser6Context::NCR_FORMAT
@ NCR_FORMAT
Used while parsing Dhcp6/dhcp-ddns/ncr-format.
Definition dhcp6/parser_context.h:347
isc::dhcp::Parser6Context::REPLACE_CLIENT_NAME
@ REPLACE_CLIENT_NAME
Used while parsing Dhcp6/dhcp-ddns/replace-client-name.
Definition dhcp6/parser_context.h:350
isc::dhcp::Parser6Context::DHCP_MULTI_THREADING
@ DHCP_MULTI_THREADING
Used while parsing Dhcp6/multi-threading structures.
Definition dhcp6/parser_context.h:320
isc::dhcp::Parser6Context::NO_KEYWORD
@ NO_KEYWORD
This one is used in pure JSON mode.
Definition dhcp6/parser_context.h:235
isc::dhcp::Parser6Context::SHARED_NETWORK
@ SHARED_NETWORK
Used while parsing shared-networks structures.
Definition dhcp6/parser_context.h:274
isc::dhcp::Parser6Context::CONTROL_SOCKET_TYPE
@ CONTROL_SOCKET_TYPE
Used while parsing Dhcp6/control-socket/socket-type structures.
Definition dhcp6/parser_context.h:300
isc::dhcp::Parser6Context::PD_POOLS
@ PD_POOLS
Used while parsing Dhcp6/subnet6/pd-pools structures.
Definition dhcp6/parser_context.h:326
isc::dhcp::Parser6Context::MAC_SOURCES
@ MAC_SOURCES
Used while parsing Dhcp6/mac-sources structures.
Definition dhcp6/parser_context.h:262
isc::dhcp::Parser6Context::CONFIG_CONTROL
@ CONFIG_CONTROL
Used while parsing Dhcp6/config-control.
Definition dhcp6/parser_context.h:353
isc::dhcp::Parser6Context::warnAboutExtraCommas
void warnAboutExtraCommas(const isc::dhcp::location &loc)
Warning for extra commas.
Definition dhcp6/parser_context.cc:249
isc::dhcp::Parser6Context::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition dhcp6_lexer.cc:7288
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:31
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:7266
isc::dhcp::Parser6Context::ParserType
ParserType
Defines currently supported scopes.
Definition dhcp6/parser_context.h:49
isc::dhcp::Parser6Context::PARSER_PD_POOL
@ PARSER_PD_POOL
This will parse the input as pd-pool content.
Definition dhcp6/parser_context.h:73
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:55
isc::dhcp::Parser6Context::PARSER_OPTION_DATA
@ PARSER_OPTION_DATA
This will parse the input as option data.
Definition dhcp6/parser_context.h:85
isc::dhcp::Parser6Context::PARSER_HOOKS_LIBRARY
@ PARSER_HOOKS_LIBRARY
This will parse the input as hooks-library.
Definition dhcp6/parser_context.h:88
isc::dhcp::Parser6Context::PARSER_POOL6
@ PARSER_POOL6
This will parse the input as pool6 content.
Definition dhcp6/parser_context.h:70
isc::dhcp::Parser6Context::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition dhcp6/parser_context.h:51
isc::dhcp::Parser6Context::PARSER_OPTION_DEF
@ PARSER_OPTION_DEF
This will parse the input as option definition.
Definition dhcp6/parser_context.h:82
isc::dhcp::Parser6Context::PARSER_INTERFACES
@ PARSER_INTERFACES
This will parse the input as interfaces content.
Definition dhcp6/parser_context.h:64
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:91
isc::dhcp::Parser6Context::PARSER_CONFIG_CONTROL
@ PARSER_CONFIG_CONTROL
This will parse the input as config-control.
Definition dhcp6/parser_context.h:94
isc::dhcp::Parser6Context::PARSER_HOST_RESERVATION
@ PARSER_HOST_RESERVATION
This will parse the input as host-reservation.
Definition dhcp6/parser_context.h:76
isc::dhcp::Parser6Context::PARSER_OPTION_DEFS
@ PARSER_OPTION_DEFS
This will parse the input option definitions (for tests).
Definition dhcp6/parser_context.h:79
isc::dhcp::Parser6Context::PARSER_SUBNET6
@ PARSER_SUBNET6
This will parse the input as Subnet6 content.
Definition dhcp6/parser_context.h:67
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:61
isc::dhcp::Parser6Context::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition dhcp6/parser_context.h:391
isc::dhcp::Parser6Context::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition dhcp6/parser_context.h:381
isc::dhcp::Parser6Context::contextName
const std::string contextName()
Get the syntactic context name.
Definition dhcp6/parser_context.cc:148
isc::dhcp::Parser6Context::ctx_
ParserContext ctx_
Current syntactic context.
Definition dhcp6/parser_context.h:394
YY_DECL
#define YY_DECL
Definition d2_lexer.cc:1484
parser_context_decl.h
Forward declaration of the ParserContext class.
dhcp6_parser.h
Define the isc::dhcp::parser class.
exceptions.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::db::fatal
@ fatal
Definition db_log.h:123
isc::db::error
@ error
Definition db_log.h:124
isc::util::file
Definition filesystem.cc:29
isc::util::str
Definition str.cc:29
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition data.h:107