Kea  1.5.0
response_parser.h
Go to the documentation of this file.
1 // Copyright (C) 2017-2018 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef HTTP_RESPONSE_PARSER_H
8 #define HTTP_RESPONSE_PARSER_H
9 
11 #include <http/response.h>
12 #include <boost/shared_ptr.hpp>
13 
14 namespace isc {
15 namespace http {
16 
17 class HttpResponseParser;
18 
20 typedef boost::shared_ptr<HttpResponseParser> HttpResponseParserPtr;
21 
44 public:
45 
48 
49 
51  static const int RECEIVE_START_ST = SM_DERIVED_STATE_MIN + 101;
52 
54  static const int HTTP_VERSION_H_ST = SM_DERIVED_STATE_MIN + 102;
55 
57  static const int HTTP_VERSION_T1_ST = SM_DERIVED_STATE_MIN + 103;
58 
60  static const int HTTP_VERSION_T2_ST = SM_DERIVED_STATE_MIN + 104;
61 
63  static const int HTTP_VERSION_P_ST = SM_DERIVED_STATE_MIN + 105;
64 
66  static const int HTTP_VERSION_SLASH_ST = SM_DERIVED_STATE_MIN + 106;
67 
70 
72  static const int HTTP_VERSION_MAJOR_ST = SM_DERIVED_STATE_MIN + 108;
73 
76 
78  static const int HTTP_VERSION_MINOR_ST = SM_DERIVED_STATE_MIN + 110;
79 
82 
84  static const int HTTP_STATUS_CODE_ST = SM_DERIVED_STATE_MIN + 112;
85 
87  static const int HTTP_PHRASE_START_ST = SM_DERIVED_STATE_MIN + 113;
88 
90  static const int HTTP_PHRASE_ST = SM_DERIVED_STATE_MIN + 114;
91 
93  static const int EXPECTING_NEW_LINE1_ST = SM_DERIVED_STATE_MIN + 115;
94 
95  static const int HEADER_LINE_START_ST = SM_DERIVED_STATE_MIN + 116;
96 
99  static const int HEADER_LWS_ST = SM_DERIVED_STATE_MIN + 117;
100 
102  static const int HEADER_NAME_ST = SM_DERIVED_STATE_MIN + 118;
103 
106 
108  static const int HEADER_VALUE_ST = SM_DERIVED_STATE_MIN + 120;
109 
112 
115 
117  static const int HTTP_BODY_ST = SM_DERIVED_STATE_MIN + 123;
118 
120 
128  explicit HttpResponseParser(HttpResponse& response);
129 
135  void initModel();
136 
137 private:
138 
140  virtual void defineStates();
141 
144 
145 
147  void receiveStartHandler();
148 
155  void versionHTTPHandler(const char expected_letter,
156  const unsigned int next_state);
157 
170  void numberStartHandler(const unsigned int next_state,
171  const std::string& number_name,
172  unsigned int* const storage);
173 
188  void numberHandler(const char following_character,
189  const unsigned int next_state,
190  const std::string& number_name,
191  unsigned int* const storage);
192 
194  void phraseStartHandler();
195 
197  void phraseHandler();
198 
211  void expectingNewLineHandler(const unsigned int next_state);
212 
214  void headerLineStartHandler();
215 
217  void headerLwsHandler();
218 
220  void headerNameHandler();
221 
223  void spaceBeforeHeaderValueHandler();
224 
226  void headerValueHandler();
227 
229  void bodyHandler();
230 
232 
234  HttpResponse& response_;
235 
237  HttpResponseContextPtr context_;
238 };
239 
240 } // end of namespace isc::http
241 } // end of namespace isc
242 
243 #endif
isc::http::HttpResponseParser::HttpResponseParser
HttpResponseParser(HttpResponse &response)
Constructor.
Definition: response_parser.cc:41
isc::http::HttpResponseParser::HTTP_VERSION_H_ST
static const int HTTP_VERSION_H_ST
Parsing letter "H" of "HTTP".
Definition: response_parser.h:54
isc::http::HttpResponseParser::HTTP_VERSION_T1_ST
static const int HTTP_VERSION_T1_ST
Parsing first occurrence of "T" in "HTTP".
Definition: response_parser.h:57
isc::util::StateModel::SM_DERIVED_STATE_MIN
static const int SM_DERIVED_STATE_MIN
Value at which custom states in a derived class should begin.
Definition: state_model.h:282
isc::http::HttpResponseParser::HTTP_PHRASE_ST
static const int HTTP_PHRASE_ST
Parsing HTTP status phrase.
Definition: response_parser.h:90
isc::http::HttpResponseParser::HTTP_STATUS_CODE_START_ST
static const int HTTP_STATUS_CODE_START_ST
Starting to parse HTTP status code.
Definition: response_parser.h:81
isc::http::HttpResponseParser::HTTP_STATUS_CODE_ST
static const int HTTP_STATUS_CODE_ST
Parsing HTTP status code.
Definition: response_parser.h:84
isc::http::HttpResponseParser::HTTP_BODY_ST
static const int HTTP_BODY_ST
Parsing body of a HTTP message.
Definition: response_parser.h:117
response.h
isc::http::HttpResponseParser::SPACE_BEFORE_HEADER_VALUE_ST
static const int SPACE_BEFORE_HEADER_VALUE_ST
Parsing space before header value.
Definition: response_parser.h:105
isc::http::HttpMessageParserBase
Base class for the HTTP message parsers.
Definition: http_message_parser_base.h:64
isc::http::HttpResponseParser::HTTP_VERSION_SLASH_ST
static const int HTTP_VERSION_SLASH_ST
Parsing slash character in "HTTP/Y.X".
Definition: response_parser.h:66
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::http::HttpResponse
Represents HTTP response message.
Definition: response.h:98
isc::http::HttpResponseParser::HTTP_VERSION_MINOR_START_ST
static const int HTTP_VERSION_MINOR_START_ST
Starting to parse minor HTTP version number.
Definition: response_parser.h:75
isc::http::HttpResponseParser::HTTP_VERSION_MINOR_ST
static const int HTTP_VERSION_MINOR_ST
Parsing minor HTTP version number.
Definition: response_parser.h:78
isc::http::HttpResponseParser::HTTP_VERSION_P_ST
static const int HTTP_VERSION_P_ST
Parsing letter "P" in "HTTP".
Definition: response_parser.h:63
isc::http::HttpResponseParser::HTTP_VERSION_MAJOR_ST
static const int HTTP_VERSION_MAJOR_ST
Parsing major HTTP version number.
Definition: response_parser.h:72
isc::http::HttpResponseParser::EXPECTING_NEW_LINE1_ST
static const int EXPECTING_NEW_LINE1_ST
Parsing first new line (after HTTP status phrase).
Definition: response_parser.h:93
isc::http::HttpResponseParser::HTTP_PHRASE_START_ST
static const int HTTP_PHRASE_START_ST
Starting to parse HTTP status phrase.
Definition: response_parser.h:87
isc::http::HttpResponseParser::EXPECTING_NEW_LINE2_ST
static const int EXPECTING_NEW_LINE2_ST
Expecting new line after parsing header value.
Definition: response_parser.h:111
isc::http::HttpResponseParserPtr
boost::shared_ptr< HttpResponseParser > HttpResponseParserPtr
Pointer to the HttpResponseParser.
Definition: response_parser.h:17
isc::http::HttpResponseParser::RECEIVE_START_ST
static const int RECEIVE_START_ST
State indicating a beginning of parsing.
Definition: response_parser.h:51
http_message_parser_base.h
isc::http::HttpResponseParser::HEADER_LINE_START_ST
static const int HEADER_LINE_START_ST
Definition: response_parser.h:95
isc::http::HttpResponseParser
A generic parser for HTTP responses.
Definition: response_parser.h:43
isc::http::HttpResponseParser::HTTP_VERSION_T2_ST
static const int HTTP_VERSION_T2_ST
Parsing second occurrence of "T" in "HTTP".
Definition: response_parser.h:60
isc::http::HttpResponseParser::HEADER_NAME_ST
static const int HEADER_NAME_ST
Parsing header name.
Definition: response_parser.h:102
isc::http::HttpResponseContextPtr
boost::shared_ptr< HttpResponseContext > HttpResponseContextPtr
Pointer to the HttpResponseContext.
Definition: response_context.h:39
isc::http::HttpResponseParser::EXPECTING_NEW_LINE3_ST
static const int EXPECTING_NEW_LINE3_ST
Expecting second new line marking end of HTTP headers.
Definition: response_parser.h:114
isc::http::HttpResponseParser::HTTP_VERSION_MAJOR_START_ST
static const int HTTP_VERSION_MAJOR_START_ST
Starting to parse major HTTP version number.
Definition: response_parser.h:69
isc::http::HttpResponseParser::initModel
void initModel()
Initialize the state model for parsing.
Definition: response_parser.cc:47
isc::http::HttpResponseParser::HEADER_LWS_ST
static const int HEADER_LWS_ST
Parsing LWS (Linear White Space), i.e.
Definition: response_parser.h:99
isc::http::HttpResponseParser::HEADER_VALUE_ST
static const int HEADER_VALUE_ST
Parsing header value.
Definition: response_parser.h:108