14#include <boost/lexical_cast.hpp> 
   24      trace_parsing_(false) {
 
 
   33    return (parseCommon());
 
 
   38    FILE* f = fopen(filename.c_str(), 
"r");
 
   43    return (parseCommon());
 
 
   47Parser4Context::parseCommon() {
 
   51    parser.set_debug_level(trace_parsing_);
 
   53        int res = parser.parse();
 
   65        isc_throw(Dhcp4ParseError, 
"Expected exactly one terminal Element, found " 
   72                      const std::string& what,
 
 
   93    const std::string& 
file = *loc.begin.filename;
 
   94    const uint32_t line = loc.begin.line;
 
   95    const uint32_t pos = loc.begin.column;
 
 
  106                  "missing parameter '" << name << 
"' (" 
  107                  << 
stack_.back()->getPosition() << 
") [" 
  109                  << open_loc << 
" and " << close_loc << 
"]");
 
 
  121                      << 
" map (previous at " << value->getPosition() << 
")");
 
  124                      << 
" entries in JSON" 
  125                      << 
" map (previous at " << value->getPosition() << 
")");
 
 
  133    cstack_.push_back(
ctx_);
 
 
  140    if (cstack_.empty()) {
 
  141        fatal(
"unbalanced syntactic context");
 
  144    ctx_ = cstack_.back();
 
 
  152        return (
"__no keyword__");
 
  158        return (
"interfaces-config");
 
  160        return (
"dhcp-socket-type");
 
  162        return (
"outbound-interface");
 
  164        return (
"lease-database");
 
  166        return (
"hosts-database");
 
  168        return (
"database-on-fail");
 
  172        return (
"host-reservation-identifiers");
 
  174        return (
"hooks-libraries");
 
  178        return (
"option-def");
 
  180        return (
"option-data");
 
  182        return (
"client-classes");
 
  184        return (
"expired-leases-processing");
 
  186        return (
"server-id");
 
  188        return (
"control-socket");
 
  190        return (
"control-socket-type");
 
  192        return (
"authentication");
 
  194        return (
"auth-type");
 
  198        return (
"http-headers");
 
  200        return (
"dhcp-queue-control");
 
  202        return (
"multi-threading");
 
  206        return (
"reservations");
 
  212        return (
"output-options");
 
  214        return (
"dhcp-ddns");
 
  216        return (
"ncr-protocol");
 
  218        return (
"ncr-format");
 
  220        return (
"replace-client-name");
 
  222        return (
"shared-networks");
 
  224        return (
"sanity-checks");
 
  226        return (
"config-control");
 
  228        return (
"config-database");
 
  230        return (
"compatibility");
 
  232        return (
"ddns-conflict-resolution-mode");
 
  234        return (
"__unknown__");
 
 
  240                        const std::string& what) {
 
  241    std::ostringstream msg;
 
  242    msg << loc << 
": " << what;
 
 
  249    warning(loc, 
"Extraneous comma. A piece of configuration may have been omitted.");
 
 
Evaluation error exception raised when trying to parse.
void scanFileBegin(FILE *f, const std::string &filename, ParserType type)
Method called before scanning starts on a file.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file 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.
isc::data::Element::Position loc2pos(isc::dhcp::location &loc)
Converts bison's position to one understandable by isc::data::Element.
void leave()
Leave a syntactic context.
isc::data::ElementPtr parseString(const std::string &str, ParserType parser_type)
Run the parser on the string specified.
void unique(const std::string &name, isc::data::Element::Position loc)
Check if a parameter is already present.
void scanEnd()
Method called after the last tokens are scanned.
void enter(const ParserContext &ctx)
Enter a new syntactic context.
Parser4Context()
Default constructor.
void warning(const isc::dhcp::location &loc, const std::string &what)
Warning handler.
void warnAboutExtraCommas(const isc::dhcp::location &loc)
Warning for extra commas.
const std::string contextName()
Get the syntactic context name.
ParserContext
Defines syntactic contexts for lexical tie-ins.
@ SUBNET4
Used while parsing Dhcp4/Subnet4 structures.
@ POOLS
Used while parsing Dhcp4/subnet4/pools structures.
@ CLIENT_CLASSES
Used while parsing Dhcp4/client-classes structures.
@ RESERVATIONS
Used while parsing Dhcp4/reservations structures.
@ HOSTS_DATABASE
Used while parsing Dhcp4/hosts-database[s] structures.
@ NCR_PROTOCOL
Used while parsing Dhcp4/dhcp-ddns/ncr-protocol.
@ LOGGERS
Used while parsing Dhcp4/loggers structures.
@ DATABASE_ON_FAIL
Used while parsing Dhcp4/*-database/on-fail.
@ NCR_FORMAT
Used while parsing Dhcp4/dhcp-ddns/ncr-format.
@ SERVER_ID
Used while parsing Dhcp4/server-id structures.
@ DDNS_CONFLICT_RESOLUTION_MODE
Used while parsing Dhcp4/ib-ddns-conflict-resolution-mode.
@ COMPATIBILITY
Used while parsing compatibility parameters.
@ OUTBOUND_INTERFACE
Used while parsing Dhcp4/interfaces/outbound-interface structures.
@ CONFIG
Used while parsing content of Dhcp4.
@ OUTPUT_OPTIONS
Used while parsing Dhcp4/loggers/output-options structures.
@ CONTROL_SOCKET
Used while parsing Dhcp4/control-socket structures.
@ DHCP_DDNS
Used while parsing Dhcp4/dhcp-ddns.
@ OPTION_DATA
Used while parsing Dhcp4/option-data, Dhcp4/subnet4/option-data or anywhere option-data is present (c...
@ AUTH_TYPE
Used while parsing Dhcp4/control-socket/authentication/type structures.
@ DHCP_MULTI_THREADING
Used while parsing Dhcp4/multi-threading structures.
@ LEASE_DATABASE
Used while parsing Dhcp4/lease-database structures.
@ SHARED_NETWORK
Used while parsing shared-networks structures.
@ EXPIRED_LEASES_PROCESSING
Used while parsing Dhcp4/expired-leases-processing.
@ CLIENTS
Used while parsing Dhcp4/control-socket/authentication/clients structures.
@ SANITY_CHECKS
Sanity checks.
@ CONFIG_CONTROL
Used while parsing Dhcp4/config-control.
@ INTERFACES_CONFIG
Used while parsing Dhcp4/interfaces structures.
@ HOST_RESERVATION_IDENTIFIERS
Used while parsing Dhcp4/host-reservation-identifiers.
@ CONTROL_SOCKET_TYPE
Used while parsing Dhcp4/control-socket/socket-type structures.
@ OPTION_DEF
Used while parsing Dhcp4/option-def structures.
@ CONFIG_DATABASE
Used while parsing config-control/config-databases.
@ NO_KEYWORD
This one is used in pure JSON mode.
@ HOOKS_LIBRARIES
Used while parsing Dhcp4/hooks-libraries.
@ DHCP_QUEUE_CONTROL
Used while parsing Dhcp4/dhcp-queue-control structures.
@ AUTHENTICATION
Used while parsing Dhcp4/control-socket/authentication structures.
@ REPLACE_CLIENT_NAME
Used while parsing Dhcp4/dhcp-ddns/replace-client-name.
@ RELAY
Used while parsing Dhcp4/subnet4relay structures.
@ SSL_MODE
Used while parsing Dhcp4/*-database/ssl-mode.
@ DHCP_SOCKET_TYPE
Used while parsing Dhcp4/interfaces/dhcp-socket-type structures.
ParserType
Defines currently supported scopes.
static void fatal(const std::string &what)
Fatal error handler.
FILE * sfile_
sFile (aka FILE)
std::vector< isc::data::ElementPtr > stack_
JSON elements being parsed.
void scanStringBegin(const std::string &str, ParserType type)
Method called before scanning starts on a string.
ParserContext ctx_
Current syntactic context.
void error(const isc::dhcp::location &loc, const std::string &what, size_t pos=0)
Error handler.
virtual ~Parser4Context()
destructor
Contains declarations for loggers used by the DHCPv4 server component.
Define the isc::dhcp::parser class.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< Element > ElementPtr
const isc::log::MessageID DHCP4_CONFIG_SYNTAX_WARNING
isc::log::Logger dhcp4_logger(DHCP4_APP_LOGGER_NAME)
Base logger for DHCPv4 server.
Defines the logger used by the top-level component of kea-lfc.
Represents the position of the data element within a configuration string.