29 :
StateModel(), message_(message), buffer_(), buffer_pos_(0),
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 getNextFromBuffer(std::string &bytes, const size_t limit=1)
Retrieves next bytes of data from the buffer.
static const int DATA_READ_OK_EVT
Chunk of data successfully read and parsed.
virtual void verifyEvents()
Verifies events used by the parser.
static const int NEED_MORE_DATA_EVT
Unable to proceed with parsing until new data is provided.
void parseFailure(const std::string &error_msg)
Transition parser to failure state.
bool isCtl(const char c) const
Checks if specified value is a control value.
void parseEndedHandler()
Handler for HTTP_PARSE_OK_ST and HTTP_PARSE_FAILED_ST.
static const int MORE_DATA_PROVIDED_EVT
New data provided and parsing should continue.
bool isChar(const char c) const
Checks if specified value is a character.
bool needData() const
Returns true if the parser needs more data to continue.
void poll()
Run the parser as long as the amount of data is sufficient.
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...
std::string error_message_
Error message set by onModelFailure.
virtual void onModelFailure(const std::string &explanation)
A method called when parsing fails.
void invalidEventError(const std::string &handler_name, const unsigned int event)
This method is called when invalid event occurred in a particular parser state.
static const int HTTP_PARSE_OK_ST
Parsing successfully completed.
bool popNextFromBuffer(std::string &next, const size_t limit=1)
Tries to read next byte from buffer.
HttpMessageParserBase(HttpMessage &message)
Constructor.
HttpMessage & message_
Reference to the parsed HTTP message.
std::string buffer_
Internal buffer from which parser reads data.
virtual void defineEvents()
Define events used by the parser.
static const int HTTP_PARSE_FAILED_EVT
Parsing HTTP request failed.
bool httpParseOk() const
Returns true if the message has been parsed successfully.
size_t buffer_pos_
Position of the next character to read from the buffer.
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...
static std::string logFormatHttpMessage(const std::string &message, const size_t limit=0)
Formats provided HTTP message for logging.
std::string getBufferAsString(const size_t limit=0) const
Returns parser's input buffer as string.
bool isSpecial(const char c) const
Checks if specified value is a special character.
void postBuffer(const void *buf, const size_t buf_size)
Provides more input data to the parser.
static const int HTTP_PARSE_OK_EVT
Parsing HTTP request successful.
virtual void defineStates()
Defines states of the parser.
static const int HTTP_PARSE_FAILED_ST
Parsing failed.
Base class for HttpRequest and HttpResponse.
virtual void finalize()=0
Complete parsing HTTP message or creating an HTTP outbound message.
Exception thrown when an error during parsing HTTP message has occurred.
Implements a finite state machine.
const EventPtr & getEvent(unsigned int value)
Fetches the event referred to by value.
bool isModelDone() const
Returns whether or not the model has finished execution.
void postNextEvent(unsigned int event)
Sets the next event to the given event value.
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.
const StatePtr getState(unsigned int value)
Fetches the state referred to by value.
unsigned int getNextEvent() const
Fetches the model's next event.
void defineEvent(unsigned int value, const std::string &label)
Adds an event value and associated label to the set of events.
void transition(unsigned int state, unsigned int event)
Sets up the model to transition into given state with a given event.
static const int END_EVT
Event issued to end the model execution.
static const int NOP_EVT
Signifies that no event has occurred.
static const int START_EVT
Event issued to start the model execution.
void abortModel(const std::string &explanation)
Aborts model execution.
std::string getEventLabel(const int event) const
Fetches the label associated with an event value.
std::string getContextStr() const
Convenience method which returns a string rendition of the current state and next event.
static const int END_ST
Final state, all the state model has reached its conclusion.
unsigned int getLastEvent() const
Fetches the model's last event.
unsigned int getCurrState() const
Fetches the model's current state.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-lfc.