Kea: parser_context.h Source File

| Kea 3.0.3-git

d2/parser_context.h
Go to the documentation of this file.
1// Copyright (C) 2017-2024 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 <d2/d2_parser.h>
13#include <d2/parser_context_decl.h>
14#include <exceptions/exceptions.h>
15
16// Tell Flex the lexer's prototype ...
17#define YY_DECL isc::d2::D2Parser::symbol_type d2_parser_lex (D2ParserContext& driver)
18
19// ... and declare it for the parser's sake.
20 YY_DECL;
21
22namespace isc {
23namespace d2 {
24
28 class D2ParseError : public isc::Exception {
29public:
30 D2ParseError(const char* file, size_t line, const char* what) :
31 isc::Exception(file, line, what) { }
32};
33
35 class D2ParserContext
36{
37public:
38
46 typedef enum {
48 PARSER_JSON,
49
51 PARSER_DHCPDDNS,
52
54 PARSER_SUB_DHCPDDNS,
55
57 PARSER_TSIG_KEY,
58
60 PARSER_TSIG_KEYS,
61
63 PARSER_DDNS_DOMAIN,
64
66 PARSER_DDNS_DOMAINS,
67
69 PARSER_DNS_SERVER,
70
72 PARSER_DNS_SERVERS,
73
75 PARSER_HOOKS_LIBRARY
76 } ParserType;
77
79 D2ParserContext();
80
82 virtual ~D2ParserContext();
83
85 std::vector<isc::data::ElementPtr> stack_;
86
91 void scanStringBegin(const std::string& str, ParserType type);
92
98 void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
99
101 void scanEnd();
102
106 void includeFile(const std::string& filename);
107
118 isc::data::ElementPtr parseString(const std::string& str,
119 ParserType parser_type);
120
131 isc::data::ElementPtr parseFile(const std::string& filename,
132 ParserType parser_type);
133
143 void error(const isc::d2::location& loc,
144 const std::string& what,
145 size_t pos = 0);
146
154 void error(const std::string& what);
155
163 static void fatal(const std::string& what);
164
172 isc::data::Element::Position loc2pos(isc::d2::location& loc);
173
183 void require(const std::string& name,
184 isc::data::Element::Position open_loc,
185 isc::data::Element::Position close_loc);
186
195 void unique(const std::string& name,
196 isc::data::Element::Position loc);
197
204 void warning(const isc::d2::location& loc, const std::string& what);
205
211 void warnAboutExtraCommas(const isc::d2::location& loc);
212
214 typedef enum {
216 NO_KEYWORD,
217
219 CONFIG,
220
222 DHCPDDNS,
223
225 TSIG_KEY,
226
228 TSIG_KEYS,
229
231 ALGORITHM,
232
234 DIGEST_BITS,
235
237 SECRET,
238
240 FORWARD_DDNS,
241
243 REVERSE_DDNS,
244
246 DDNS_DOMAIN,
247
249 DDNS_DOMAINS,
250
252 DNS_SERVER,
253
255 DNS_SERVERS,
256
258 CONTROL_SOCKET,
259
261 CONTROL_SOCKET_TYPE,
262
264 AUTHENTICATION,
265
267 AUTH_TYPE,
268
270 CLIENTS,
271
273 LOGGERS,
274
276 OUTPUT_OPTIONS,
277
279 NCR_PROTOCOL,
280
282 NCR_FORMAT,
283
285 HOOKS_LIBRARIES
286
287 } ParserContext;
288
290 std::string file_;
291
293 std::vector<std::string> files_;
294
299 isc::d2::location loc_;
300
302 std::vector<isc::d2::location> locs_;
303
305 std::vector<struct yy_buffer_state*> states_;
306
308 FILE* sfile_;
309
315 std::vector<FILE*> sfiles_;
316
318 ParserContext ctx_;
319
332 void enter(const ParserContext& ctx);
333
337 void leave();
338
342 const std::string contextName();
343
344 private:
346 bool trace_scanning_;
347
349 bool trace_parsing_;
350
352 std::vector<ParserContext> cstack_;
353
357 isc::data::ElementPtr parseCommon();
358};
359
360} // end of isc::eval namespace
361} // end of isc namespace
362
363#endif
YY_DECL
#define YY_DECL
Definition agent/parser_context.h:17
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::d2::D2ParseError::D2ParseError
D2ParseError(const char *file, size_t line, const char *what)
Definition d2/parser_context.h:30
isc::d2::D2ParserContext::ParserType
ParserType
Defines currently supported scopes.
Definition d2/parser_context.h:46
isc::d2::D2ParserContext::PARSER_TSIG_KEY
@ PARSER_TSIG_KEY
Used for parsing a list of TSIG Keys.
Definition d2/parser_context.h:57
isc::d2::D2ParserContext::PARSER_DDNS_DOMAINS
@ PARSER_DDNS_DOMAINS
Used for parsing content of a DNS Server.
Definition d2/parser_context.h:66
isc::d2::D2ParserContext::PARSER_DNS_SERVERS
@ PARSER_DNS_SERVERS
Used for parsing content of hooks libraries.
Definition d2/parser_context.h:72
isc::d2::D2ParserContext::PARSER_DDNS_DOMAIN
@ PARSER_DDNS_DOMAIN
Used for parsing a list a DDNS Domains.
Definition d2/parser_context.h:63
isc::d2::D2ParserContext::PARSER_DNS_SERVER
@ PARSER_DNS_SERVER
Used for parsing a list of DNS servers.
Definition d2/parser_context.h:69
isc::d2::D2ParserContext::PARSER_SUB_DHCPDDNS
@ PARSER_SUB_DHCPDDNS
Used for parsing content of a TSIG key.
Definition d2/parser_context.h:54
isc::d2::D2ParserContext::PARSER_HOOKS_LIBRARY
@ PARSER_HOOKS_LIBRARY
Definition d2/parser_context.h:75
isc::d2::D2ParserContext::PARSER_JSON
@ PARSER_JSON
This parser will parse the content as generic JSON.
Definition d2/parser_context.h:48
isc::d2::D2ParserContext::PARSER_TSIG_KEYS
@ PARSER_TSIG_KEYS
Used for parsing content of a DDNS Domain.
Definition d2/parser_context.h:60
isc::d2::D2ParserContext::PARSER_DHCPDDNS
@ PARSER_DHCPDDNS
Used for parsing content of DhcpDdns.
Definition d2/parser_context.h:51
isc::d2::D2ParserContext::parseString
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
Definition d2/parser_context.cc:32
isc::d2::D2ParserContext::loc_
isc::d2::location loc_
Location of the current token.
Definition d2/parser_context.h:299
isc::d2::D2ParserContext::file_
std::string file_
File name.
Definition d2/parser_context.h:290
isc::d2::D2ParserContext::includeFile
void includeFile(const std::string &filename)
Divert input to an include file.
Definition d2_lexer.cc:3987
isc::d2::D2ParserContext::D2ParserContext
D2ParserContext()
Default constructor.
Definition d2/parser_context.cc:22
isc::d2::D2ParserContext::ParserContext
ParserContext
Defines syntactic contexts for lexical tie-ins.
Definition d2/parser_context.h:214
isc::d2::D2ParserContext::AUTHENTICATION
@ AUTHENTICATION
Used while parsing content of an authentication type.
Definition d2/parser_context.h:264
isc::d2::D2ParserContext::DDNS_DOMAIN
@ DDNS_DOMAIN
Used while parsing a list of ddns-domains.
Definition d2/parser_context.h:246
isc::d2::D2ParserContext::DNS_SERVERS
@ DNS_SERVERS
Used while parsing content of a control-socket.
Definition d2/parser_context.h:255
isc::d2::D2ParserContext::DDNS_DOMAINS
@ DDNS_DOMAINS
Used while parsing content of a dns-server.
Definition d2/parser_context.h:249
isc::d2::D2ParserContext::AUTH_TYPE
@ AUTH_TYPE
Used while parsing content of a client.
Definition d2/parser_context.h:267
isc::d2::D2ParserContext::NCR_FORMAT
@ NCR_FORMAT
Used while parsing DhcpDdns/ncr-format.
Definition d2/parser_context.h:282
isc::d2::D2ParserContext::NCR_PROTOCOL
@ NCR_PROTOCOL
Used while parsing DhcpDdns/ncr-protocol.
Definition d2/parser_context.h:279
isc::d2::D2ParserContext::NO_KEYWORD
@ NO_KEYWORD
This one is used in pure JSON mode.
Definition d2/parser_context.h:216
isc::d2::D2ParserContext::DHCPDDNS
@ DHCPDDNS
Used while parsing content of a tsig-key.
Definition d2/parser_context.h:222
isc::d2::D2ParserContext::SECRET
@ SECRET
Used while parsing content of DhcpDdns/forward-ddns.
Definition d2/parser_context.h:237
isc::d2::D2ParserContext::ALGORITHM
@ ALGORITHM
Used while parsing content of DhcpDdns/tsig-keys/digest-bits.
Definition d2/parser_context.h:231
isc::d2::D2ParserContext::OUTPUT_OPTIONS
@ OUTPUT_OPTIONS
Used while parsing DhcpDdns/loggers/output-options structures.
Definition d2/parser_context.h:276
isc::d2::D2ParserContext::FORWARD_DDNS
@ FORWARD_DDNS
Used while parsing content of DhcpDdns/reverse-ddns.
Definition d2/parser_context.h:240
isc::d2::D2ParserContext::CONTROL_SOCKET_TYPE
@ CONTROL_SOCKET_TYPE
Used while parsing content of an authentication.
Definition d2/parser_context.h:261
isc::d2::D2ParserContext::TSIG_KEY
@ TSIG_KEY
Used while parsing a list of tsig-keys.
Definition d2/parser_context.h:225
isc::d2::D2ParserContext::REVERSE_DDNS
@ REVERSE_DDNS
Used while parsing content of a ddns-domain.
Definition d2/parser_context.h:243
isc::d2::D2ParserContext::LOGGERS
@ LOGGERS
Used while parsing DhcpDdns/loggers structures.
Definition d2/parser_context.h:273
isc::d2::D2ParserContext::HOOKS_LIBRARIES
@ HOOKS_LIBRARIES
Used while parsing DhcpDdns/hooks-libraries.
Definition d2/parser_context.h:285
isc::d2::D2ParserContext::TSIG_KEYS
@ TSIG_KEYS
Used while parsing content of DhcpDdns/tsig-keys/algorithm.
Definition d2/parser_context.h:228
isc::d2::D2ParserContext::CONTROL_SOCKET
@ CONTROL_SOCKET
Used while parsing content of a socket-type.
Definition d2/parser_context.h:258
isc::d2::D2ParserContext::DIGEST_BITS
@ DIGEST_BITS
Used while parsing content of DhcpDdns/tsig-keys/secret.
Definition d2/parser_context.h:234
isc::d2::D2ParserContext::CONFIG
@ CONFIG
Used while parsing content of DhcpDdns.
Definition d2/parser_context.h:219
isc::d2::D2ParserContext::CLIENTS
@ CLIENTS
Definition d2/parser_context.h:270
isc::d2::D2ParserContext::DNS_SERVER
@ DNS_SERVER
Used while parsing content of list of dns-servers.
Definition d2/parser_context.h:252
isc::d2::D2ParserContext::sfiles_
std::vector< FILE * > sfiles_
sFile (aka FILE) stack
Definition d2/parser_context.h:315
isc::d2::D2ParserContext::warning
void warning(const isc::d2::location &loc, const std::string &what)
Warning handler.
Definition d2/parser_context.cc:214
isc::d2::D2ParserContext::sfile_
FILE * sfile_
sFile (aka FILE)
Definition d2/parser_context.h:308
isc::d2::D2ParserContext::contextName
const std::string contextName()
Get the syntax context name.
Definition d2/parser_context.cc:157
isc::d2::D2ParserContext::error
void error(const isc::d2::location &loc, const std::string &what, size_t pos=0)
Error handler.
Definition d2/parser_context.cc:73
isc::d2::D2ParserContext::leave
void leave()
Leave a syntactic context.
Definition d2/parser_context.cc:146
isc::d2::D2ParserContext::scanStringBegin
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
Definition d2_lexer.cc:3926
isc::d2::D2ParserContext::parseFile
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
Definition d2/parser_context.cc:39
isc::d2::D2ParserContext::warnAboutExtraCommas
void warnAboutExtraCommas(const isc::d2::location &loc)
Warning for extra commas.
Definition d2/parser_context.cc:223
isc::d2::D2ParserContext::scanFileBegin
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
Definition d2_lexer.cc:3944
isc::d2::D2ParserContext::unique
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
Definition d2/parser_context.cc:121
isc::d2::D2ParserContext::~D2ParserContext
virtual ~D2ParserContext()
destructor.
Definition d2/parser_context.cc:27
isc::d2::D2ParserContext::locs_
std::vector< isc::d2::location > locs_
Location stack.
Definition d2/parser_context.h:302
isc::d2::D2ParserContext::ctx_
ParserContext ctx_
Current syntactic context.
Definition d2/parser_context.h:318
isc::d2::D2ParserContext::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 d2/parser_context.cc:106
isc::d2::D2ParserContext::states_
std::vector< struct yy_buffer_state * > states_
Lexer state stack.
Definition d2/parser_context.h:305
isc::d2::D2ParserContext::stack_
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
Definition d2/parser_context.h:85
isc::d2::D2ParserContext::enter
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Definition d2/parser_context.cc:139
isc::d2::D2ParserContext::fatal
static void fatal(const std::string &what)
Fatal error handler.
Definition d2/parser_context.cc:91
isc::d2::D2ParserContext::files_
std::vector< std::string > files_
File name stack.
Definition d2/parser_context.h:293
isc::d2::D2ParserContext::scanEnd
void scanEnd()
Method called after the last tokens are scanned.
Definition d2_lexer.cc:3966
isc::d2::D2ParserContext::loc2pos
isc::data::Element::Position loc2pos(isc::d2::location &loc)
Converts bison's position to one understood by isc::data::Element.
Definition d2/parser_context.cc:97
parser_context_decl.h
Forward declaration of the ParserContext class.
d2_parser.h
Define the isc::d2::parser class.
exceptions.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::dns::name
Definition name.cc:69
isc::util::file
Definition filesystem.cc:28
isc::util::str
Definition str.cc:29
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
isc::data::Element::Position
Represents the position of the data element within a configuration string.
Definition data.h:107