parser.hpp
// ---------------------------------------------------------------------
// pion: a Boost C++ framework for building lightweight HTTP interfaces
// ---------------------------------------------------------------------
// Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//
#ifndef __PION_SPDYPARSER_HEADER__
#define __PION_SPDYPARSER_HEADER__
#include <boost/shared_ptr.hpp>
#include <boost/logic/tribool.hpp>
#include <boost/system/error_code.hpp>
#include <boost/thread/once.hpp>
#include <pion/config.hpp>
#include <pion/logger.hpp>
#include <pion/spdy/types.hpp>
#include <pion/spdy/decompressor.hpp>
#ifndef BOOST_SYSTEM_NOEXCEPT
#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
#endif
namespace pion { // begin namespace pion
namespace spdy { // begin namespace spdy
class PION_API parser
{
public:
enum error_value_t {
ERROR_INVALID_SPDY_FRAME = 1,
ERROR_INVALID_SPDY_VERSION,
ERROR_DECOMPRESSION,
ERROR_PROTOCOL_ERROR,
ERROR_INTERNAL_SPDY_ERROR,
ERROR_MISSING_HEADER_DATA
};
class error_category_t
: public boost::system::error_category
{
public:
const char *name() const BOOST_SYSTEM_NOEXCEPT { return "SPDYParser"; }
std::string message(int ev) const {
switch (ev) {
case ERROR_INVALID_SPDY_FRAME:
return "invalid spdy frame";
case ERROR_INVALID_SPDY_VERSION:
return "invalid spdy version";
case ERROR_DECOMPRESSION:
return "error in decompression";
case ERROR_MISSING_HEADER_DATA:
return "missing header data";
}
return "SPDYParser error";
}
};
parser();
~parser() {}
boost::tribool parse(http_protocol_info& http_headers,
boost::system::error_code& ec,
const decompressor_ptr& decompressor,
const char *packet_ptr,
boost::uint32_t& length_packet,
boost::uint32_t current_stream_count);
const char * get_spdy_data_content( ) { return m_last_data_chunk_ptr; }
const char * get_spdy_read_pointer( ) { return m_read_ptr; }
static spdy_frame_type get_spdy_frame_type(const char *ptr);
static bool is_spdy_control_frame(const char *ptr);
static boost::uint32_t get_control_frame_stream_id(const char *ptr);
protected:
inline void set_read_ptr(const char *ptr) { m_read_ptr = m_current_data_chunk_ptr = ptr; }
bool populate_frame(boost::system::error_code& ec,
spdy_control_frame_info& frame,
boost::uint32_t& length_packet,
boost::uint32_t& stream_id,
http_protocol_info& http_headers);
static void create_error_category(void);
static inline error_category_t& get_error_category(void) {
boost::call_once(parser::create_error_category, m_instance_flag);
return *m_error_category_ptr;
}
static inline void set_error(boost::system::error_code& ec, error_value_t ev) {
ec = boost::system::error_code(static_cast<int>(ev), get_error_category());
}
void parse_header_payload(boost::system::error_code& ec,
const decompressor_ptr& decompressor,
const spdy_control_frame_info& frame,
http_protocol_info& http_headers,
boost::uint32_t current_stream_count);
void parse_spdy_data(boost::system::error_code& ec,
const spdy_control_frame_info& frame,
boost::uint32_t stream_id,
http_protocol_info& http_info);
void parse_spdy_settings_frame(boost::system::error_code& ec,
const spdy_control_frame_info& frame);
void parse_spdy_rst_stream(boost::system::error_code& ec,
const spdy_control_frame_info& frame);
void parse_spdy_ping_frame(boost::system::error_code& ec,
const spdy_control_frame_info& frame);
void parse_spdy_goaway_frame(boost::system::error_code& ec,
const spdy_control_frame_info& frame);
void parse_spdy_window_update_frame(boost::system::error_code& ec,
const spdy_control_frame_info& frame);
boost::tribool parse_spdy_frame(boost::system::error_code& ec,
const decompressor_ptr& decompressor,
http_protocol_info& http_headers,
boost::uint32_t& length_packet,
boost::uint32_t current_stream_count);
private:
const char * m_read_ptr;
const char * m_uncompressed_ptr;
const char * m_current_data_chunk_ptr;
const char * m_last_data_chunk_ptr;
mutable logger m_logger;
static error_category_t * m_error_category_ptr;
static boost::once_flag m_instance_flag;
};
typedef boost::shared_ptr<parser> parser_ptr;
} // end namespace spdy
} // end namespace pion
#endif
pion::spdy::parser::create_error_category
static void create_error_category(void)
creates the unique parser error_category_t
Definition: spdy_parser.cpp:258
pion::spdy::parser::set_read_ptr
void set_read_ptr(const char *ptr)
resets the read pointer
Definition: parser.hpp:124
pion::spdy::parser::get_error_category
static error_category_t & get_error_category(void)
returns an instance of parser::error_category_t
Definition: parser.hpp:138
pion::spdy::parser::get_spdy_data_content
const char * get_spdy_data_content()
Get the pointer to the first character to the spdy data contect.
Definition: parser.hpp:94
pion::spdy::_http_protocol_info_t
This structure contains the HTTP Protocol information.
Definition: types.hpp:69
pion::spdy::decompressor
Definition: decompressor.hpp:29
pion::spdy::parser::error_category_t
class-specific error category
Definition: parser.hpp:51
pion::spdy::parser::error_value_t
error_value_t
class-specific error code values
Definition: parser.hpp:41
pion::spdy::parser::~parser
~parser()
destructor
Definition: parser.hpp:76
pion::spdy::parser
Definition: parser.hpp:36
pion::logger
Definition: logger.hpp:238
pion
Definition: admin_rights.hpp:19
pion::spdy::parser::set_error
static void set_error(boost::system::error_code &ec, error_value_t ev)
Definition: parser.hpp:149
pion::spdy::spdy_control_frame_info
This structure will be tied to each SPDY frame.
Definition: types.hpp:48
pion::spdy::parser::get_spdy_read_pointer
const char * get_spdy_read_pointer()
Get the pointer to the first character to the spdy data contect.
Definition: parser.hpp:97