18 const int HttpMessageParserBase::HTTP_PARSE_OK_ST;
19 const int HttpMessageParserBase::HTTP_PARSE_FAILED_ST;
21 const int HttpMessageParserBase::DATA_READ_OK_EVT;
22 const int HttpMessageParserBase::NEED_MORE_DATA_EVT;
23 const int HttpMessageParserBase::MORE_DATA_PROVIDED_EVT;
24 const int HttpMessageParserBase::HTTP_PARSE_OK_EVT;
25 const int HttpMessageParserBase::HTTP_PARSE_FAILED_EVT;
28 HttpMessageParserBase::HttpMessageParserBase(
HttpMessage& message)
43 }
catch (
const std::exception& ex) {
71 static_cast<const char*>(buf) + buf_size);
84 if ((limit > 0) && !message.empty()) {
85 if (limit < message.size()) {
87 s << message.substr(0, limit)
88 <<
".........\n(truncating HTTP message larger than "
89 << limit <<
" characters)\n";
102 StateModel::defineEvents();
114 StateModel::verifyEvents();
126 StateModel::defineStates();
137 std::function<
void(
const char c)>
146 after_read_logic(bytes[0]);
156 std::function<
void(
const std::string&)>
165 after_read_logic(bytes);
196 "HTTP request parser requires new data to progress, but no data"
197 " have been provided. The transaction is aborted to avoid"
198 " a deadlock. This is a Kea HTTP server logic error!");
208 "HTTP server state indicates that new data have been"
209 " provided to be parsed, but the transaction buffer"
210 " contains no new data. This is a Kea HTTP server logic"
224 const unsigned int event) {
271 return (((c >= 0) && (c <= 31)) || (c == 127));
void defineState(unsigned int value, const std::string &label, StateHandler handler, const StatePausing &state_pausing=STATE_PAUSE_NEVER)
Adds an state value and associated label to the set of states.
static const int NOP_EVT
Signifies that no event has occurred.
Implements a finite state machine.
std::string getBufferAsString(const size_t limit=0) const
Returns parser's input buffer as string.
static const int MORE_DATA_PROVIDED_EVT
New data provided and parsing should continue.
static const int DATA_READ_OK_EVT
Chunk of data successfully read and parsed.
void defineEvent(unsigned int value, const std::string &label)
Adds an event value and associated label to the set of events.
static std::string logFormatHttpMessage(const std::string &message, const size_t limit=0)
Formats provided HTTP message for logging.
const StatePtr getState(unsigned int value)
Fetches the state referred to by value.
virtual void defineStates()
Defines states of the parser.
std::string error_message_
Error message set by onModelFailure.
void parseEndedHandler()
Handler for HTTP_PARSE_OK_ST and HTTP_PARSE_FAILED_ST.
void abortModel(const std::string &explanation)
Aborts model execution.
static const int START_EVT
Event issued to start the model execution.
unsigned int getLastEvent() const
Fetches the model's last event.
HttpMessage & message_
Reference to the parsed HTTP message.
static const int HTTP_PARSE_OK_ST
Parsing successfully completed.
bool httpParseOk() const
Returns true if the message has been parsed successfully.
virtual void onModelFailure(const std::string &explanation)
A method called when parsing fails.
unsigned int getCurrState() const
Fetches the model's current state.
bool isSpecial(const char c) const
Checks if specified value is a special character.
static const int HTTP_PARSE_OK_EVT
Parsing HTTP request successful.
bool needData() const
Returns true if the parser needs more data to continue.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
void stateWithReadHandler(const std::string &handler_name, std::function< void(const char c)> after_read_logic)
Generic parser handler which reads a single byte of data and parses it using specified callback funct...
size_t buffer_pos_
Position of the next character to read from the buffer.
Base class for HttpRequest and HttpResponse.
const OutputBuffer * buffer_
static const int NEED_MORE_DATA_EVT
Unable to proceed with parsing until new data is provided.
std::string getEventLabel(const int event) const
Fetches the label associated with an event value.
void invalidEventError(const std::string &handler_name, const unsigned int event)
This method is called when invalid event occurred in a particular parser state.
bool isCtl(const char c) const
Checks if specified value is a control value.
virtual void verifyEvents()
Verifies events used by the parser.
void parseFailure(const std::string &error_msg)
Transition parser to failure state.
std::string getContextStr() const
Convenience method which returns a string rendition of the current state and next event...
bool isChar(const char c) const
Checks if specified value is a character.
std::string buffer_
Internal buffer from which parser reads data.
Defines the logger used by the top-level component of kea-dhcp-ddns.
bool popNextFromBuffer(std::string &next, const size_t limit=1)
Tries to read next byte from buffer.
virtual void finalize()=0
Complete parsing HTTP message or creating an HTTP outbound message.
void transition(unsigned int state, unsigned int event)
Sets up the model to transition into given state with a given event.
virtual void defineEvents()
Define events used by the parser.
void getNextFromBuffer(std::string &bytes, const size_t limit=1)
Retrieves next bytes of data from the buffer.
static const int HTTP_PARSE_FAILED_EVT
Parsing HTTP request failed.
static const int END_ST
Final state, all the state model has reached its conclusion.
bool isModelDone() const
Returns whether or not the model has finished execution.
void poll()
Run the parser as long as the amount of data is sufficient.
const EventPtr & getEvent(unsigned int value)
Fetches the event referred to by value.
unsigned int getNextEvent() const
Fetches the model's next event.
static const int HTTP_PARSE_FAILED_ST
Parsing failed.
Exception thrown when an error during parsing HTTP message has occurred.
static const int END_EVT
Event issued to end the model execution.
void postNextEvent(unsigned int event)
Sets the next event to the given event value.
void postBuffer(const void *buf, const size_t buf_size)
Provides more input data to the parser.
void stateWithMultiReadHandler(const std::string &handler_name, std::function< void(const std::string &)> after_read_logic)
Generic parser handler which reads multiple bytes of data and parses it using specified callback func...