Kea 2.5.8
isc::dhcp::Parser4Context Class Reference

Evaluation context, an interface to the expression evaluation. More...

#include <parser_context.h>

Public Types

enum  ParserContext {
  NO_KEYWORD , CONFIG , DHCP4 , INTERFACES_CONFIG ,
  SANITY_CHECKS , DHCP_SOCKET_TYPE , OUTBOUND_INTERFACE , LEASE_DATABASE ,
  HOSTS_DATABASE , DATABASE_TYPE , DATABASE_ON_FAIL , HOST_RESERVATION_IDENTIFIERS ,
  HOOKS_LIBRARIES , SUBNET4 , SHARED_NETWORK , RESERVATION_MODE ,
  OPTION_DEF , OPTION_DATA , CLIENT_CLASSES , EXPIRED_LEASES_PROCESSING ,
  SERVER_ID , CONTROL_SOCKET , DHCP_QUEUE_CONTROL , DHCP_MULTI_THREADING ,
  POOLS , RESERVATIONS , RELAY , LOGGERS ,
  OUTPUT_OPTIONS , DHCP_DDNS , NCR_PROTOCOL , NCR_FORMAT ,
  REPLACE_CLIENT_NAME , CONFIG_CONTROL , CONFIG_DATABASE , COMPATIBILITY ,
  DDNS_CONFLICT_RESOLUTION_MODE
}
 Defines syntactic contexts for lexical tie-ins. More...
 
enum  ParserType {
  PARSER_JSON , PARSER_DHCP4 , SUBPARSER_DHCP4 , PARSER_INTERFACES ,
  PARSER_SUBNET4 , PARSER_POOL4 , PARSER_HOST_RESERVATION , PARSER_OPTION_DEFS ,
  PARSER_OPTION_DEF , PARSER_OPTION_DATA , PARSER_HOOKS_LIBRARY , PARSER_DHCP_DDNS ,
  PARSER_CONFIG_CONTROL
}
 Defines currently supported scopes. More...
 

Public Member Functions

 Parser4Context ()
 Default constructor.
 
virtual ~Parser4Context ()
 destructor
 
const std::string contextName ()
 Get the syntactic context name.
 
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.
 
void error (const std::string &what)
 Error handler.
 
void includeFile (const std::string &filename)
 Divert input to an include file.
 
void leave ()
 Leave a syntactic context.
 
isc::data::Element::Position loc2pos (isc::dhcp::location &loc)
 Converts bison's position to one understandable by isc::data::Element.
 
isc::data::ElementPtr parseFile (const std::string &filename, ParserType parser_type)
 Run the parser on the file specified.
 
isc::data::ElementPtr parseString (const std::string &str, ParserType parser_type)
 Run the parser on the string specified.
 
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.
 
void scanEnd ()
 Method called after the last tokens are scanned.
 
void scanFileBegin (FILE *f, const std::string &filename, ParserType type)
 Method called before scanning starts on a file.
 
void scanStringBegin (const std::string &str, ParserType type)
 Method called before scanning starts on a string.
 
void unique (const std::string &name, isc::data::Element::Position loc)
 Check if a parameter is already present.
 
void warnAboutExtraCommas (const isc::dhcp::location &loc)
 Warning for extra commas.
 
void warning (const isc::dhcp::location &loc, const std::string &what)
 Warning handler.
 

Static Public Member Functions

static void fatal (const std::string &what)
 Fatal error handler.
 

Public Attributes

ParserContext ctx_
 Current syntactic context.
 
std::string file_
 File name.
 
std::vector< std::string > files_
 File name stack.
 
isc::dhcp::location loc_
 Location of the current token.
 
std::vector< isc::dhcp::location > locs_
 Location stack.
 
FILE * sfile_
 sFile (aka FILE)
 
std::vector< FILE * > sfiles_
 sFile (aka FILE) stack
 
std::vector< isc::data::ElementPtrstack_
 JSON elements being parsed.
 
std::vector< struct yy_buffer_state * > states_
 Lexer state stack.
 

Detailed Description

Evaluation context, an interface to the expression evaluation.

Definition at line 35 of file dhcp4/parser_context.h.

Member Enumeration Documentation

◆ ParserContext

Defines syntactic contexts for lexical tie-ins.

Enumerator
NO_KEYWORD 

This one is used in pure JSON mode.

Used while parsing top level (that contains Dhcp4)

CONFIG 

Used while parsing content of Dhcp4.

DHCP4 
INTERFACES_CONFIG 

Used while parsing Dhcp4/interfaces structures.

SANITY_CHECKS 

Sanity checks.

DHCP_SOCKET_TYPE 

Used while parsing Dhcp4/interfaces/dhcp-socket-type structures.

OUTBOUND_INTERFACE 

Used while parsing Dhcp4/interfaces/outbound-interface structures.

LEASE_DATABASE 

Used while parsing Dhcp4/lease-database structures.

HOSTS_DATABASE 

Used while parsing Dhcp4/hosts-database[s] structures.

DATABASE_TYPE 

Used while parsing Dhcp4/*-database/type.

DATABASE_ON_FAIL 

Used while parsing Dhcp4/*-database/on-fail.

HOST_RESERVATION_IDENTIFIERS 

Used while parsing Dhcp4/host-reservation-identifiers.

HOOKS_LIBRARIES 

Used while parsing Dhcp4/hooks-libraries.

SUBNET4 

Used while parsing Dhcp4/Subnet4 structures.

SHARED_NETWORK 

Used while parsing shared-networks structures.

RESERVATION_MODE 

Used while parsing Dhcp4/reservation-mode.

OPTION_DEF 

Used while parsing Dhcp4/option-def structures.

OPTION_DATA 

Used while parsing Dhcp4/option-data, Dhcp4/subnet4/option-data or anywhere option-data is present (client classes, host reservations and possibly others).

CLIENT_CLASSES 

Used while parsing Dhcp4/client-classes structures.

EXPIRED_LEASES_PROCESSING 

Used while parsing Dhcp4/expired-leases-processing.

SERVER_ID 

Used while parsing Dhcp4/server-id structures.

CONTROL_SOCKET 

Used while parsing Dhcp4/control-socket structures.

DHCP_QUEUE_CONTROL 

Used while parsing Dhcp4/dhcp-queue-control structures.

DHCP_MULTI_THREADING 

Used while parsing Dhcp4/multi-threading structures.

POOLS 

Used while parsing Dhcp4/subnet4/pools structures.

RESERVATIONS 

Used while parsing Dhcp4/reservations structures.

RELAY 

Used while parsing Dhcp4/subnet4relay structures.

LOGGERS 

Used while parsing Dhcp4/loggers structures.

OUTPUT_OPTIONS 

Used while parsing Dhcp4/loggers/output-options structures.

DHCP_DDNS 

Used while parsing Dhcp4/dhcp-ddns.

NCR_PROTOCOL 

Used while parsing Dhcp4/dhcp-ddns/ncr-protocol.

NCR_FORMAT 

Used while parsing Dhcp4/dhcp-ddns/ncr-format.

REPLACE_CLIENT_NAME 

Used while parsing Dhcp4/dhcp-ddns/replace-client-name.

CONFIG_CONTROL 

Used while parsing Dhcp4/config-control.

CONFIG_DATABASE 

Used while parsing config-control/config-databases.

COMPATIBILITY 

Used while parsing compatibility parameters.

DDNS_CONFLICT_RESOLUTION_MODE 

Used while parsing Dhcp4/ib-ddns-conflict-resolution-mode.

Definition at line 230 of file dhcp4/parser_context.h.

◆ ParserType

Defines currently supported scopes.

Dhcp4Parser is able to parse several types of scope. Usually, when it parses a config file, it expects the data to have a map with Dhcp4 in it and all the parameters within that Dhcp4 map. However, sometimes the parser is expected to parse only a subset of that information. For example, it may be asked to parse a structure that is host-reservation only, without the global 'Dhcp4' or 'reservations' around it. In such case the parser is being told to start parsing as PARSER_HOST_RESERVATION4.

Enumerator
PARSER_JSON 

This parser will parse the content as generic JSON.

PARSER_DHCP4 

This parser will parse the content as Dhcp4 config wrapped in a map (that's the regular config file)

SUBPARSER_DHCP4 

This parser will parse the content of Dhcp4 (without outer { } and without "Dhcp4").

It is mostly used in unit-tests as most of the unit-tests do not define the outer map and Dhcp4 entity, just the contents of it.

PARSER_INTERFACES 

This will parse the input as interfaces content.

PARSER_SUBNET4 

This will parse the input as Subnet4 content.

PARSER_POOL4 

This will parse the input as pool4 content.

PARSER_HOST_RESERVATION 

This will parse the input as host-reservation.

PARSER_OPTION_DEFS 

This will parse the input option definitions (for tests).

PARSER_OPTION_DEF 

This will parse the input as option definition.

PARSER_OPTION_DATA 

This will parse the input as option data.

PARSER_HOOKS_LIBRARY 

This will parse the input as hooks-library.

PARSER_DHCP_DDNS 

This will parse the input as dhcp-ddns.

PARSER_CONFIG_CONTROL 

This will parse the input as config-control.

Definition at line 49 of file dhcp4/parser_context.h.

Constructor & Destructor Documentation

◆ Parser4Context()

isc::dhcp::Parser4Context::Parser4Context ( )

Default constructor.

Definition at line 22 of file dhcp4/parser_context.cc.

◆ ~Parser4Context()

isc::dhcp::Parser4Context::~Parser4Context ( )
virtual

destructor

Definition at line 27 of file dhcp4/parser_context.cc.

Member Function Documentation

◆ contextName()

◆ enter()

void isc::dhcp::Parser4Context::enter ( const ParserContext ctx)

Enter a new syntactic context.

Entering a new syntactic context is useful in several ways. First, it allows the parser to avoid conflicts. Second, it allows the lexer to return different tokens depending on context (e.g. if "renew-timer" string is detected, the lexer will return STRING token if in JSON mode or RENEW_TIMER if in DHCP4 mode. Finally, the syntactic context allows the error message to be more descriptive if the input string does not parse properly.

Parameters
ctxthe syntactic context to enter into

Definition at line 133 of file dhcp4/parser_context.cc.

References ctx_.

Referenced by isc::dhcp::Dhcp4Parser::parse().

◆ error() [1/2]

void isc::dhcp::Parser4Context::error ( const isc::dhcp::location &  loc,
const std::string &  what,
size_t  pos = 0 
)

Error handler.

Note
The optional position for an error in a string begins by 1 so the caller should add 1 to the position of the C++ string.
Parameters
loclocation within the parsed file where the problem was experienced.
whatstring explaining the nature of the error.
posoptional position for in string errors.
Exceptions
Dhcp4ParseError

Definition at line 72 of file dhcp4/parser_context.cc.

References isc_throw.

◆ error() [2/2]

void isc::dhcp::Parser4Context::error ( const std::string &  what)

Error handler.

This is a simplified error reporting tool for possible future cases when the Dhcp4Parser is not able to handle the packet.

Parameters
whatstring explaining the nature of the error.
Exceptions
Dhcp4ParseError

Definition at line 83 of file dhcp4/parser_context.cc.

References isc_throw.

◆ fatal()

void isc::dhcp::Parser4Context::fatal ( const std::string &  what)
static

Fatal error handler.

This is for should not happen but fatal errors. Used by YY_FATAL_ERROR macro so required to be static.

Parameters
whatstring explaining the nature of the error.
Exceptions
Dhcp4ParseError

Definition at line 88 of file dhcp4/parser_context.cc.

References isc_throw.

◆ includeFile()

void Parser4Context::includeFile ( const std::string &  filename)

Divert input to an include file.

Parameters
filenamefile to be included

Definition at line 6939 of file dhcp4_lexer.cc.

References BEGIN, isc::db::fatal, file_, files_, INITIAL, loc_, locs_, sfile_, sfiles_, states_, and YY_CURRENT_BUFFER.

◆ leave()

void isc::dhcp::Parser4Context::leave ( )

Leave a syntactic context.

Exceptions
isc::Unexpectedif unbalanced

Definition at line 139 of file dhcp4/parser_context.cc.

References ctx_, and isc::db::fatal.

Referenced by isc::dhcp::Dhcp4Parser::parse().

◆ loc2pos()

isc::data::Element::Position isc::dhcp::Parser4Context::loc2pos ( isc::dhcp::location &  loc)

Converts bison's position to one understandable by isc::data::Element.

Convert a bison location into an element position (take the begin, the end is lost)

Parameters
loclocation in bison format
Returns
Position in format accepted by Element

Definition at line 93 of file dhcp4/parser_context.cc.

Referenced by isc::dhcp::Dhcp4Parser::parse().

◆ parseFile()

isc::data::ElementPtr isc::dhcp::Parser4Context::parseFile ( const std::string &  filename,
ParserType  parser_type 
)

Run the parser on the file specified.

This method parses specified file. Depending on the value of parser_type, parser may either check only that the input is valid JSON, or may do more specific syntax checking. See ParserType for supported syntax checkers.

Parameters
filenamefile to be parsed
parser_typespecifies expected content (usually DHCP4 or generic JSON)
Returns
Element structure representing parsed text.

Definition at line 37 of file dhcp4/parser_context.cc.

References isc_throw, and scanFileBegin().

Referenced by isc::dhcp::ControlledDhcpv4Srv::loadConfigFile(), and main().

+ Here is the call graph for this function:

◆ parseString()

isc::data::ElementPtr isc::dhcp::Parser4Context::parseString ( const std::string &  str,
ParserType  parser_type 
)

Run the parser on the string specified.

This method parses specified string. Depending on the value of parser_type, parser may either check only that the input is valid JSON, or may do more specific syntax checking. See ParserType for supported syntax checkers.

Parameters
strstring to be parsed
parser_typespecifies expected content (usually DHCP4 or generic JSON)
Returns
Element structure representing parsed text.

Definition at line 31 of file dhcp4/parser_context.cc.

References scanStringBegin().

+ Here is the call graph for this function:

◆ require()

void isc::dhcp::Parser4Context::require ( const std::string &  name,
isc::data::Element::Position  open_loc,
isc::data::Element::Position  close_loc 
)

Check if a required parameter is present.

Check if a required parameter is present in the map at the top of the stack and raise an error when it is not.

Parameters
namename of the parameter to check
open_loclocation of the opening curly bracket
close_loclocation of the closing curly bracket
Exceptions
Dhcp4ParseError

Definition at line 101 of file dhcp4/parser_context.cc.

References contextName(), isc_throw, and stack_.

Referenced by isc::dhcp::Dhcp4Parser::parse().

+ Here is the call graph for this function:

◆ scanEnd()

void Parser4Context::scanEnd ( )

Method called after the last tokens are scanned.

Definition at line 6918 of file dhcp4_lexer.cc.

References sfile_, sfiles_, and states_.

◆ scanFileBegin()

void Parser4Context::scanFileBegin ( FILE *  f,
const std::string &  filename,
ParserType  type 
)

Method called before scanning starts on a file.

Parameters
fstdio FILE pointer
filenamefile to be parsed
typespecifies expected content

Definition at line 6896 of file dhcp4_lexer.cc.

References isc::db::fatal, file_, loc_, sfile_, and yy_flex_debug.

Referenced by parseFile().

◆ scanStringBegin()

void Parser4Context::scanStringBegin ( const std::string &  str,
ParserType  type 
)

Method called before scanning starts on a string.

Parameters
strstring to be parsed
typespecifies expected content

Definition at line 6878 of file dhcp4_lexer.cc.

References isc::db::fatal, file_, loc_, sfile_, and yy_flex_debug.

Referenced by parseString().

◆ unique()

void isc::dhcp::Parser4Context::unique ( const std::string &  name,
isc::data::Element::Position  loc 
)

Check if a parameter is already present.

Check if a parameter is already present in the map at the top of the stack and raise an error when it is.

Parameters
namename of the parameter to check
loclocation of the current parameter
Exceptions
Dhcp4ParseError

Definition at line 115 of file dhcp4/parser_context.cc.

References contextName(), ctx_, isc_throw, NO_KEYWORD, and stack_.

Referenced by isc::dhcp::Dhcp4Parser::parse().

+ Here is the call graph for this function:

◆ warnAboutExtraCommas()

void isc::dhcp::Parser4Context::warnAboutExtraCommas ( const isc::dhcp::location &  loc)

Warning for extra commas.

Parameters
loclocation within the parsed file of the extra comma
Exceptions
ParseError

Definition at line 241 of file dhcp4/parser_context.cc.

References warning().

Referenced by isc::dhcp::Dhcp4Parser::parse().

+ Here is the call graph for this function:

◆ warning()

void isc::dhcp::Parser4Context::warning ( const isc::dhcp::location &  loc,
const std::string &  what 
)

Warning handler.

Parameters
loclocation within the parsed file where the problem was experienced
whatstring explaining the nature of the error
Exceptions
ParseError

Definition at line 232 of file dhcp4/parser_context.cc.

References isc::dhcp::DHCP4_CONFIG_SYNTAX_WARNING, isc::dhcp::dhcp4_logger, and LOG_WARN.

Referenced by isc::dhcp::Dhcp4Parser::parse(), and warnAboutExtraCommas().

Member Data Documentation

◆ ctx_

ParserContext isc::dhcp::Parser4Context::ctx_

Current syntactic context.

Definition at line 374 of file dhcp4/parser_context.h.

Referenced by contextName(), enter(), leave(), isc::dhcp::Dhcp4Parser::parse(), and unique().

◆ file_

std::string isc::dhcp::Parser4Context::file_

File name.

Definition at line 346 of file dhcp4/parser_context.h.

Referenced by includeFile(), scanFileBegin(), and scanStringBegin().

◆ files_

std::vector<std::string> isc::dhcp::Parser4Context::files_

File name stack.

Definition at line 349 of file dhcp4/parser_context.h.

Referenced by includeFile().

◆ loc_

isc::dhcp::location isc::dhcp::Parser4Context::loc_

Location of the current token.

The lexer will keep updating it. This variable will be useful for logging errors.

Definition at line 355 of file dhcp4/parser_context.h.

Referenced by includeFile(), scanFileBegin(), and scanStringBegin().

◆ locs_

std::vector<isc::dhcp::location> isc::dhcp::Parser4Context::locs_

Location stack.

Definition at line 358 of file dhcp4/parser_context.h.

Referenced by includeFile().

◆ sfile_

FILE* isc::dhcp::Parser4Context::sfile_

sFile (aka FILE)

Definition at line 364 of file dhcp4/parser_context.h.

Referenced by includeFile(), scanEnd(), scanFileBegin(), and scanStringBegin().

◆ sfiles_

std::vector<FILE*> isc::dhcp::Parser4Context::sfiles_

sFile (aka FILE) stack

This is a stack of files. Typically there's only one file (the one being currently parsed), but there may be more if one file includes another.

Definition at line 371 of file dhcp4/parser_context.h.

Referenced by includeFile(), and scanEnd().

◆ stack_

std::vector<isc::data::ElementPtr> isc::dhcp::Parser4Context::stack_

JSON elements being parsed.

Definition at line 101 of file dhcp4/parser_context.h.

Referenced by isc::dhcp::Dhcp4Parser::parse(), require(), and unique().

◆ states_

std::vector<struct yy_buffer_state*> isc::dhcp::Parser4Context::states_

Lexer state stack.

Definition at line 361 of file dhcp4/parser_context.h.

Referenced by includeFile(), and scanEnd().


The documentation for this class was generated from the following files: