pion  5.0.6
parser.hpp
1 // ---------------------------------------------------------------------
2 // pion: a Boost C++ framework for building lightweight HTTP interfaces
3 // ---------------------------------------------------------------------
4 // Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // See http://www.boost.org/LICENSE_1_0.txt
8 //
9 
10 #ifndef __PION_SPDYPARSER_HEADER__
11 #define __PION_SPDYPARSER_HEADER__
12 
13 
14 #include <boost/shared_ptr.hpp>
15 #include <boost/logic/tribool.hpp>
16 #include <boost/system/error_code.hpp>
17 #include <boost/thread/once.hpp>
18 #include <pion/config.hpp>
19 #include <pion/logger.hpp>
20 #include <pion/spdy/types.hpp>
21 #include <pion/spdy/decompressor.hpp>
22 
23 #ifndef BOOST_SYSTEM_NOEXCEPT
24  #define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
25 #endif
26 
27 
28 namespace pion { // begin namespace pion
29 namespace spdy { // begin namespace spdy
30 
31 
35 
36 class PION_API parser
37 {
38 public:
39 
42  ERROR_INVALID_SPDY_FRAME = 1,
43  ERROR_INVALID_SPDY_VERSION,
44  ERROR_DECOMPRESSION,
45  ERROR_PROTOCOL_ERROR,
46  ERROR_INTERNAL_SPDY_ERROR,
47  ERROR_MISSING_HEADER_DATA
48  };
49 
52  : public boost::system::error_category
53  {
54  public:
55  const char *name() const BOOST_SYSTEM_NOEXCEPT { return "SPDYParser"; }
56  std::string message(int ev) const {
57  switch (ev) {
58  case ERROR_INVALID_SPDY_FRAME:
59  return "invalid spdy frame";
60  case ERROR_INVALID_SPDY_VERSION:
61  return "invalid spdy version";
62  case ERROR_DECOMPRESSION:
63  return "error in decompression";
64  case ERROR_MISSING_HEADER_DATA:
65  return "missing header data";
66 
67  }
68  return "SPDYParser error";
69  }
70  };
71 
73  parser();
74 
76  ~parser() {}
77 
86  boost::tribool parse(http_protocol_info& http_headers,
87  boost::system::error_code& ec,
88  decompressor_ptr& decompressor,
89  const char *packet_ptr,
90  boost::uint32_t& length_packet,
91  boost::uint32_t current_stream_count);
92 
94  const char * get_spdy_data_content( ) { return m_last_data_chunk_ptr; }
95 
97  const char * get_spdy_read_pointer( ) { return m_read_ptr; }
98 
104  static spdy_frame_type get_spdy_frame_type(const char *ptr);
105 
111  static bool is_spdy_control_frame(const char *ptr);
112 
118  static boost::uint32_t get_control_frame_stream_id(const char *ptr);
119 
120 
121 protected:
122 
124  inline void set_read_ptr(const char *ptr) { m_read_ptr = m_current_data_chunk_ptr = ptr; }
125 
128  bool populate_frame(boost::system::error_code& ec,
130  boost::uint32_t& length_packet,
131  boost::uint32_t& stream_id,
132  http_protocol_info& http_headers);
133 
135  static void create_error_category(void);
136 
138  static inline error_category_t& get_error_category(void) {
139  boost::call_once(parser::create_error_category, m_instance_flag);
140  return *m_error_category_ptr;
141  }
142 
149  static inline void set_error(boost::system::error_code& ec, error_value_t ev) {
150  ec = boost::system::error_code(static_cast<int>(ev), get_error_category());
151  }
152 
157  void parse_header_payload(boost::system::error_code& ec,
158  decompressor_ptr& decompressor,
159  const spdy_control_frame_info& frame,
160  http_protocol_info& http_headers,
161  boost::uint32_t current_stream_count);
162 
167  void parse_spdy_data(boost::system::error_code& ec,
168  const spdy_control_frame_info& frame,
169  boost::uint32_t stream_id,
170  http_protocol_info& http_info);
171 
176  void parse_spdy_settings_frame(boost::system::error_code& ec,
177  const spdy_control_frame_info& frame);
178 
183  void parse_spdy_rst_stream(boost::system::error_code& ec,
184  const spdy_control_frame_info& frame);
185 
190  void parse_spdy_ping_frame(boost::system::error_code& ec,
191  const spdy_control_frame_info& frame);
192 
197  void parse_spdy_goaway_frame(boost::system::error_code& ec,
198  const spdy_control_frame_info& frame);
199 
204  void parse_spdy_window_update_frame(boost::system::error_code& ec,
205  const spdy_control_frame_info& frame);
206 
215  boost::tribool parse_spdy_frame(boost::system::error_code& ec,
216  decompressor_ptr& decompressor,
217  http_protocol_info& http_headers,
218  boost::uint32_t& length_packet,
219  boost::uint32_t current_stream_count);
220 
221 private:
222 
224  const char * m_read_ptr;
225 
227  const char * m_uncompressed_ptr;
228 
230  const char * m_current_data_chunk_ptr;
231 
233  const char * m_last_data_chunk_ptr;
234 
236  mutable logger m_logger;
237 
239  static error_category_t * m_error_category_ptr;
240 
242  static boost::once_flag m_instance_flag;
243 };
244 
246 typedef boost::shared_ptr<parser> parser_ptr;
247 
248 
249 } // end namespace spdy
250 } // end namespace pion
251 
252 #endif
253 
static void create_error_category(void)
creates the unique parser error_category_t
void set_read_ptr(const char *ptr)
resets the read pointer
Definition: parser.hpp:124
static error_category_t & get_error_category(void)
returns an instance of parser::error_category_t
Definition: parser.hpp:138
const char * get_spdy_data_content()
Get the pointer to the first character to the spdy data contect.
Definition: parser.hpp:94
This structure contains the HTTP Protocol information.
Definition: types.hpp:69
class-specific error category
Definition: parser.hpp:51
error_value_t
class-specific error code values
Definition: parser.hpp:41
~parser()
destructor
Definition: parser.hpp:76
static void set_error(boost::system::error_code &ec, error_value_t ev)
Definition: parser.hpp:149
This structure will be tied to each SPDY frame.
Definition: types.hpp:48
const char * get_spdy_read_pointer()
Get the pointer to the first character to the spdy data contect.
Definition: parser.hpp:97