// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. #ifndef EVAL_CONTEXT_H #define EVAL_CONTEXT_H #include #include #include #include #include // Tell Flex the lexer's prototype ... #define YY_DECL isc::eval::EvalParser::symbol_type yylex (EvalContext& driver) // ... and declare it for the parser's sake. YY_DECL; namespace isc { namespace eval { /// @brief Evaluation error exception raised when trying to parse an axceptions. class EvalParseError : public isc::Exception { public: EvalParseError(const char* file, size_t line, const char* what) : isc::Exception(file, line, what) { }; }; /// @brief Evaluation context, an interface to the expression evaluation. class EvalContext { public: /// @brief Default constructor. /// /// @param option_universe Option universe: DHCPv4 or DHCPv6. This is used /// by the parser to determine which option definitions set should be used /// to map option names to option codes. EvalContext(const Option::Universe& option_universe); /// @brief destructor virtual ~EvalContext(); /// @brief Parsed expression (output tokens are stored here) isc::dhcp::Expression expression; /// @brief Method called before scanning starts on a string. void scanStringBegin(); /// @brief Method called after the last tokens are scanned from a string. void scanStringEnd(); /// @brief Run the parser on the string specified. /// /// @param str string to be written /// @return true on success. bool parseString(const std::string& str); /// @brief The name of the file being parsed. /// Used later to pass the file name to the location tracker. std::string file_; /// @brief The string being parsed. std::string string_; /// @brief Error handler /// /// @param loc location within the parsed file when experienced a problem. /// @param what string explaining the nature of the error. void error(const isc::eval::location& loc, const std::string& what); /// @brief Error handler /// /// This is a simplified error reporting tool for possible future /// cases when the EvalParser is not able to handle the packet. void error(const std::string& what); /// @brief Fatal error handler /// /// This is for should not happen but fatal errors static void fatal(const std::string& what); /// @brief Option code convertion /// /// @param option_code a string representing the integer code /// @param loc the location of the token /// @result the option code /// @throw calls the syntax error function if the value is no in /// the range 0..255 or 0..65535 uint16_t convertOptionCode(const std::string& option_code, const isc::eval::location& loc); /// @brief Option name convertion /// /// @param option_name the option name /// @param loc the location of the token /// @result the option code /// @throw calls the syntax error function if the name cannot be resolved uint16_t convertOptionName(const std::string& option_name, const isc::eval::location& loc); private: /// @brief Flag determining scanner debugging. bool trace_scanning_; /// @brief Flag determing parser debugging. bool trace_parsing_; /// @brief Option universe: DHCPv4 or DHCPv6. /// /// This is used by the parser to determine which option definitions /// set should be used to map option name to option code. Option::Universe option_universe_; }; }; // end of isc::eval namespace }; // end of isc namespace #endif