mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 15:35:17 +00:00
[5036] Improved parser and include files
This commit is contained in:
@@ -295,7 +295,7 @@ unknown_map_entry: STRING COLON {
|
|||||||
const std::string& keyword = $1;
|
const std::string& keyword = $1;
|
||||||
error(@1,
|
error(@1,
|
||||||
"got unexpected keyword \"" + keyword + "\" in " + where + " map.");
|
"got unexpected keyword \"" + keyword + "\" in " + where + " map.");
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
// This defines the top-level { } that holds Dhcp6, Dhcp4, DhcpDdns or Logging
|
// This defines the top-level { } that holds Dhcp6, Dhcp4, DhcpDdns or Logging
|
||||||
@@ -620,10 +620,12 @@ sub_hooks_library: LCURLY_BRACKET {
|
|||||||
|
|
||||||
hooks_params: hooks_param
|
hooks_params: hooks_param
|
||||||
| hooks_params COMMA hooks_param
|
| hooks_params COMMA hooks_param
|
||||||
|
| unknown_map_entry
|
||||||
;
|
;
|
||||||
|
|
||||||
hooks_param: library
|
hooks_param: library
|
||||||
| parameters;
|
| parameters
|
||||||
|
;
|
||||||
|
|
||||||
library: LIBRARY {
|
library: LIBRARY {
|
||||||
ctx.enter(ctx.NO_KEYWORD);
|
ctx.enter(ctx.NO_KEYWORD);
|
||||||
@@ -638,7 +640,7 @@ parameters: PARAMETERS {
|
|||||||
} COLON value {
|
} COLON value {
|
||||||
ctx.stack_.back()->set("parameters", $4);
|
ctx.stack_.back()->set("parameters", $4);
|
||||||
ctx.leave();
|
ctx.leave();
|
||||||
}
|
};
|
||||||
|
|
||||||
// --- expired-leases-processing ------------------------
|
// --- expired-leases-processing ------------------------
|
||||||
expired_leases_processing: EXPIRED_LEASES_PROCESSING {
|
expired_leases_processing: EXPIRED_LEASES_PROCESSING {
|
||||||
@@ -661,7 +663,7 @@ expired_leases_params: expired_leases_param
|
|||||||
expired_leases_param: STRING COLON INTEGER {
|
expired_leases_param: STRING COLON INTEGER {
|
||||||
ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
|
ElementPtr value(new IntElement($3, ctx.loc2pos(@3)));
|
||||||
ctx.stack_.back()->set($1, value);
|
ctx.stack_.back()->set($1, value);
|
||||||
}
|
};
|
||||||
|
|
||||||
// --- subnet6 ------------------------------------------
|
// --- subnet6 ------------------------------------------
|
||||||
// This defines subnet6 as a list of maps.
|
// This defines subnet6 as a list of maps.
|
||||||
@@ -1107,12 +1109,12 @@ pd_prefix: PREFIX {
|
|||||||
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
|
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
|
||||||
ctx.stack_.back()->set("prefix", prf);
|
ctx.stack_.back()->set("prefix", prf);
|
||||||
ctx.leave();
|
ctx.leave();
|
||||||
}
|
};
|
||||||
|
|
||||||
pd_prefix_len: PREFIX_LEN COLON INTEGER {
|
pd_prefix_len: PREFIX_LEN COLON INTEGER {
|
||||||
ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
|
ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
|
||||||
ctx.stack_.back()->set("prefix-len", prf);
|
ctx.stack_.back()->set("prefix-len", prf);
|
||||||
}
|
};
|
||||||
|
|
||||||
excluded_prefix: EXCLUDED_PREFIX {
|
excluded_prefix: EXCLUDED_PREFIX {
|
||||||
ctx.enter(ctx.NO_KEYWORD);
|
ctx.enter(ctx.NO_KEYWORD);
|
||||||
@@ -1120,17 +1122,17 @@ excluded_prefix: EXCLUDED_PREFIX {
|
|||||||
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
|
ElementPtr prf(new StringElement($4, ctx.loc2pos(@4)));
|
||||||
ctx.stack_.back()->set("excluded-prefix", prf);
|
ctx.stack_.back()->set("excluded-prefix", prf);
|
||||||
ctx.leave();
|
ctx.leave();
|
||||||
}
|
};
|
||||||
|
|
||||||
excluded_prefix_len: EXCLUDED_PREFIX_LEN COLON INTEGER {
|
excluded_prefix_len: EXCLUDED_PREFIX_LEN COLON INTEGER {
|
||||||
ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
|
ElementPtr prf(new IntElement($3, ctx.loc2pos(@3)));
|
||||||
ctx.stack_.back()->set("excluded-prefix-len", prf);
|
ctx.stack_.back()->set("excluded-prefix-len", prf);
|
||||||
}
|
};
|
||||||
|
|
||||||
pd_delegated_len: DELEGATED_LEN COLON INTEGER {
|
pd_delegated_len: DELEGATED_LEN COLON INTEGER {
|
||||||
ElementPtr deleg(new IntElement($3, ctx.loc2pos(@3)));
|
ElementPtr deleg(new IntElement($3, ctx.loc2pos(@3)));
|
||||||
ctx.stack_.back()->set("delegated-len", deleg);
|
ctx.stack_.back()->set("delegated-len", deleg);
|
||||||
}
|
};
|
||||||
|
|
||||||
// --- end of pd-pools ---------------------------------------
|
// --- end of pd-pools ---------------------------------------
|
||||||
|
|
||||||
@@ -1230,7 +1232,7 @@ hostname: HOSTNAME {
|
|||||||
ElementPtr host(new StringElement($4, ctx.loc2pos(@4)));
|
ElementPtr host(new StringElement($4, ctx.loc2pos(@4)));
|
||||||
ctx.stack_.back()->set("hostname", host);
|
ctx.stack_.back()->set("hostname", host);
|
||||||
ctx.leave();
|
ctx.leave();
|
||||||
}
|
};
|
||||||
|
|
||||||
reservation_client_classes: CLIENT_CLASSES {
|
reservation_client_classes: CLIENT_CLASSES {
|
||||||
ElementPtr c(new ListElement(ctx.loc2pos(@1)));
|
ElementPtr c(new ListElement(ctx.loc2pos(@1)));
|
||||||
@@ -1310,7 +1312,7 @@ client_class_test: TEST {
|
|||||||
ElementPtr test(new StringElement($4, ctx.loc2pos(@4)));
|
ElementPtr test(new StringElement($4, ctx.loc2pos(@4)));
|
||||||
ctx.stack_.back()->set("test", test);
|
ctx.stack_.back()->set("test", test);
|
||||||
ctx.leave();
|
ctx.leave();
|
||||||
}
|
};
|
||||||
|
|
||||||
// --- end of client classes ---------------------------------
|
// --- end of client classes ---------------------------------
|
||||||
|
|
||||||
|
@@ -39,13 +39,14 @@ public:
|
|||||||
|
|
||||||
/// @brief Defines currently supported scopes
|
/// @brief Defines currently supported scopes
|
||||||
///
|
///
|
||||||
/// Dhcp6Parser is able to parse several types of scope. Usually, when it
|
/// Dhcp6Parser is able to parse several types of scope. Usually,
|
||||||
/// parses a config file, it expects the data to have a map with Dhcp6 in it
|
/// when it parses a config file, it expects the data to have a map
|
||||||
/// and all the parameters within that Dhcp6 map. However, sometimes the
|
/// with Dhcp6 in it and all the parameters within that Dhcp6 map.
|
||||||
/// parser is expected to parse only a subset of that information. For example,
|
/// However, sometimes the parser is expected to parse only a subset
|
||||||
/// it may be asked to parse a structure that is host-reservation only, without
|
/// of that information. For example, it may be asked to parse
|
||||||
/// the global 'Dhcp6' or 'reservations' around it. In such case the parser
|
/// a structure that is host-reservation only, without the global
|
||||||
/// is being told to start parsing as SUBPARSER_HOST_RESERVATION6.
|
/// 'Dhcp6' or 'reservations' around it. In such case the parser
|
||||||
|
/// is being told to start parsing as PARSER_HOST_RESERVATION6.
|
||||||
typedef enum {
|
typedef enum {
|
||||||
/// This parser will parse the content as generic JSON.
|
/// This parser will parse the content as generic JSON.
|
||||||
PARSER_JSON,
|
PARSER_JSON,
|
||||||
@@ -60,15 +61,15 @@ public:
|
|||||||
/// contents of it.
|
/// contents of it.
|
||||||
SUBPARSER_DHCP6,
|
SUBPARSER_DHCP6,
|
||||||
|
|
||||||
|
/// This will parse the input as interfaces content.
|
||||||
|
PARSER_INTERFACES,
|
||||||
|
|
||||||
/// This will parse the input as Subnet6 content.
|
/// This will parse the input as Subnet6 content.
|
||||||
PARSER_SUBNET6,
|
PARSER_SUBNET6,
|
||||||
|
|
||||||
/// This will parse the input as pool6 content.
|
/// This will parse the input as pool6 content.
|
||||||
PARSER_POOL6,
|
PARSER_POOL6,
|
||||||
|
|
||||||
/// This will parse the input as interfaces content.
|
|
||||||
PARSER_INTERFACES,
|
|
||||||
|
|
||||||
/// This will parse the input as pd-pool content.
|
/// This will parse the input as pd-pool content.
|
||||||
PARSER_PD_POOL,
|
PARSER_PD_POOL,
|
||||||
|
|
||||||
@@ -95,15 +96,24 @@ public:
|
|||||||
std::vector<isc::data::ElementPtr> stack_;
|
std::vector<isc::data::ElementPtr> stack_;
|
||||||
|
|
||||||
/// @brief Method called before scanning starts on a string.
|
/// @brief Method called before scanning starts on a string.
|
||||||
|
///
|
||||||
|
/// @param str string to be parsed
|
||||||
|
/// @param parser_type specifies expected content
|
||||||
void scanStringBegin(const std::string& str, ParserType type);
|
void scanStringBegin(const std::string& str, ParserType type);
|
||||||
|
|
||||||
/// @brief Method called before scanning starts on a file.
|
/// @brief Method called before scanning starts on a file.
|
||||||
void scanFileBegin(FILE * f, const std::string& filename, ParserType type);
|
///
|
||||||
|
/// @param f stdio FILE pointer
|
||||||
|
/// @param filename file to be parsed
|
||||||
|
/// @param parser_type specifies expected content
|
||||||
|
void scanFileBegin(FILE* f, const std::string& filename, ParserType type);
|
||||||
|
|
||||||
/// @brief Method called after the last tokens are scanned.
|
/// @brief Method called after the last tokens are scanned.
|
||||||
void scanEnd();
|
void scanEnd();
|
||||||
|
|
||||||
/// @brief Divert input to an include file.
|
/// @brief Divert input to an include file.
|
||||||
|
///
|
||||||
|
/// @param filename file to be included
|
||||||
void includeFile(const std::string& filename);
|
void includeFile(const std::string& filename);
|
||||||
|
|
||||||
/// @brief Run the parser on the string specified.
|
/// @brief Run the parser on the string specified.
|
||||||
@@ -136,25 +146,33 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param loc location within the parsed file when experienced a problem.
|
/// @param loc location within the parsed file when experienced a problem.
|
||||||
/// @param what string explaining the nature of the error.
|
/// @param what string explaining the nature of the error.
|
||||||
|
/// @throw Dhcp6ParseError
|
||||||
void error(const isc::dhcp::location& loc, const std::string& what);
|
void error(const isc::dhcp::location& loc, const std::string& what);
|
||||||
|
|
||||||
/// @brief Error handler
|
/// @brief Error handler
|
||||||
///
|
///
|
||||||
/// This is a simplified error reporting tool for possible future
|
/// This is a simplified error reporting tool for possible future
|
||||||
/// cases when the Dhcp6Parser is not able to handle the packet.
|
/// cases when the Dhcp6Parser is not able to handle the packet.
|
||||||
|
///
|
||||||
|
/// @param what string explaining the nature of the error.
|
||||||
|
/// @throw Dhcp6ParseError
|
||||||
void error(const std::string& what);
|
void error(const std::string& what);
|
||||||
|
|
||||||
/// @brief Fatal error handler
|
/// @brief Fatal error handler
|
||||||
///
|
///
|
||||||
/// This is for should not happen but fatal errors.
|
/// This is for should not happen but fatal errors.
|
||||||
/// Used by YY_FATAL_ERROR macro so required to be static.
|
/// Used by YY_FATAL_ERROR macro so required to be static.
|
||||||
|
///
|
||||||
|
/// @param what string explaining the nature of the error.
|
||||||
|
/// @throw Dhcp6ParseError
|
||||||
static void fatal(const std::string& what);
|
static void fatal(const std::string& what);
|
||||||
|
|
||||||
/// @brief Converts bison's position to one understandable by isc::data::Element
|
/// @brief Converts bison's position to one understandable by isc::data::Element
|
||||||
///
|
///
|
||||||
/// Convert a bison location into an element position
|
/// Convert a bison location into an element position
|
||||||
/// (take the begin, the end is lost)
|
/// (take the begin, the end is lost)
|
||||||
/// @brief loc location in bison format
|
///
|
||||||
|
/// @param loc location in bison format
|
||||||
/// @return Position in format accepted by Element
|
/// @return Position in format accepted by Element
|
||||||
isc::data::Element::Position loc2pos(isc::dhcp::location& loc);
|
isc::data::Element::Position loc2pos(isc::dhcp::location& loc);
|
||||||
|
|
||||||
@@ -178,12 +196,12 @@ public:
|
|||||||
/// Used while parsing Dhcp6/interfaces structures.
|
/// Used while parsing Dhcp6/interfaces structures.
|
||||||
INTERFACES_CONFIG,
|
INTERFACES_CONFIG,
|
||||||
|
|
||||||
/// Used while parsing Dhcp6/hosts-database structures.
|
|
||||||
HOSTS_DATABASE,
|
|
||||||
|
|
||||||
/// Used while parsing Dhcp6/lease-database structures.
|
/// Used while parsing Dhcp6/lease-database structures.
|
||||||
LEASE_DATABASE,
|
LEASE_DATABASE,
|
||||||
|
|
||||||
|
/// Used while parsing Dhcp6/hosts-database structures.
|
||||||
|
HOSTS_DATABASE,
|
||||||
|
|
||||||
/// Used while parsing Dhcp6/mac-sources structures.
|
/// Used while parsing Dhcp6/mac-sources structures.
|
||||||
MAC_SOURCES,
|
MAC_SOURCES,
|
||||||
|
|
||||||
@@ -275,13 +293,17 @@ public:
|
|||||||
/// will return STRING token if in JSON mode or RENEW_TIMER if
|
/// will return STRING token if in JSON mode or RENEW_TIMER if
|
||||||
/// in DHCP6 mode. Finally, the stntactic context allows the
|
/// in DHCP6 mode. Finally, the stntactic context allows the
|
||||||
/// error message to be more descriptive.
|
/// error message to be more descriptive.
|
||||||
|
///
|
||||||
|
/// @param ctx the syntactic context to enter into
|
||||||
void enter(const ParserContext& ctx);
|
void enter(const ParserContext& ctx);
|
||||||
|
|
||||||
/// @brief Leave a syntactic context
|
/// @brief Leave a syntactic context
|
||||||
|
///
|
||||||
/// @throw isc::Unexpected if unbalanced
|
/// @throw isc::Unexpected if unbalanced
|
||||||
void leave();
|
void leave();
|
||||||
|
|
||||||
/// @brief Get the syntactix context name
|
/// @brief Get the syntactix context name
|
||||||
|
///
|
||||||
/// @return printable name of the context.
|
/// @return printable name of the context.
|
||||||
const std::string contextName();
|
const std::string contextName();
|
||||||
|
|
||||||
@@ -296,6 +318,8 @@ public:
|
|||||||
std::vector<ParserContext> cstack_;
|
std::vector<ParserContext> cstack_;
|
||||||
|
|
||||||
/// @brief Common part of parseXXX
|
/// @brief Common part of parseXXX
|
||||||
|
///
|
||||||
|
/// @return Element structure representing parsed text.
|
||||||
isc::data::ConstElementPtr parseCommon();
|
isc::data::ConstElementPtr parseCommon();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user