diff --git a/beast/http/HTTP.unity.cpp b/beast/http/HTTP.unity.cpp index c1de909440..ea2c3a518b 100644 --- a/beast/http/HTTP.unity.cpp +++ b/beast/http/HTTP.unity.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include diff --git a/beast/http/basic_parser.h b/beast/http/basic_parser.h index d0ee4dcffb..f23a36c4ee 100644 --- a/beast/http/basic_parser.h +++ b/beast/http/basic_parser.h @@ -74,6 +74,8 @@ private: cb_t on_headers_complete; data_cb_t on_body; cb_t on_message_complete; + cb_t on_chunk_header; + cb_t on_chunk_complete; }; char state_ [sizeof(state_t)]; @@ -221,6 +223,8 @@ private: int do_headers_complete (); int do_body (char const* in, std::size_t bytes); int do_message_complete (); + int do_chunk_header(); + int do_chunk_complete(); static int cb_message_start (joyent::http_parser*); static int cb_url (joyent::http_parser*, char const*, std::size_t); @@ -230,6 +234,8 @@ private: static int cb_headers_complete (joyent::http_parser*); static int cb_body (joyent::http_parser*, char const*, std::size_t); static int cb_message_complete (joyent::http_parser*); + static int cb_chunk_header (joyent::http_parser*); + static int cb_chunk_complete (joyent::http_parser*); }; template diff --git a/beast/http/impl/basic_parser.cpp b/beast/http/impl/basic_parser.cpp index 0d02380b33..f49598357c 100644 --- a/beast/http/impl/basic_parser.cpp +++ b/beast/http/impl/basic_parser.cpp @@ -93,6 +93,8 @@ basic_parser::basic_parser (bool request) noexcept h->on_headers_complete = &basic_parser::cb_headers_complete; h->on_body = &basic_parser::cb_body; h->on_message_complete = &basic_parser::cb_message_complete; + h->on_chunk_header = &basic_parser::cb_chunk_header; + h->on_chunk_complete = &basic_parser::cb_chunk_complete; joyent::http_parser_init (s, request ? joyent::http_parser_type::HTTP_REQUEST @@ -231,6 +233,18 @@ basic_parser::do_message_complete () return 0; } +int +basic_parser::do_chunk_header() +{ + return 0; +} + +int +basic_parser::do_chunk_complete() +{ + return 0; +} + //------------------------------------------------------------------------------ int @@ -295,5 +309,19 @@ basic_parser::cb_message_complete (joyent::http_parser* p) p->data)->do_message_complete(); } +int +basic_parser::cb_chunk_header (joyent::http_parser* p) +{ + return reinterpret_cast ( + p->data)->do_chunk_header(); +} + +int +basic_parser::cb_chunk_complete (joyent::http_parser* p) +{ + return reinterpret_cast ( + p->data)->do_chunk_complete(); +} + } // http } // beast diff --git a/beast/http/impl/joyent_parser.cpp b/beast/http/impl/joyent_parser.cpp index 2c268717be..4e29f7bc4d 100644 --- a/beast/http/impl/joyent_parser.cpp +++ b/beast/http/impl/joyent_parser.cpp @@ -83,6 +83,10 @@ convert_http_method (joyent::http_method m) case HTTP_PROPPATCH: return http::method_t::http_proppatch; case HTTP_SEARCH: return http::method_t::http_search; case HTTP_UNLOCK: return http::method_t::http_unlock; + case HTTP_BIND: return http::method_t::http_bind; + case HTTP_REBIND: return http::method_t::http_rebind; + case HTTP_UNBIND: return http::method_t::http_unbind; + case HTTP_ACL: return http::method_t::http_acl; // subversion case HTTP_REPORT: return http::method_t::http_report; @@ -99,6 +103,13 @@ convert_http_method (joyent::http_method m) // RFC-5789 case HTTP_PATCH: return http::method_t::http_patch; case HTTP_PURGE: return http::method_t::http_purge; + + // CalDav + case HTTP_MKCALENDAR: return http::method_t::http_mkcalendar; + + // RFC-2068, section 19.6.1.2 + case HTTP_LINK: return http::method_t::http_link; + case HTTP_UNLINK: return http::method_t::http_unlink; }; return http::method_t::http_get; diff --git a/beast/http/impl/raw_parser.cpp b/beast/http/impl/raw_parser.cpp deleted file mode 100644 index 340a777c9b..0000000000 --- a/beast/http/impl/raw_parser.cpp +++ /dev/null @@ -1,292 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#include - -#include - -#include - -namespace beast { -namespace http { - -raw_parser::raw_parser (callback& cb) - : m_cb (cb) -{ - static_assert (sizeof(joyent::http_parser) == sizeof(state_t), - "state_t size must match http_parser size"); - - static_assert (sizeof(joyent::http_parser_settings) == sizeof(hooks_t), - "hooks_t size must match http_parser_settings size"); - - auto s (reinterpret_cast (&m_state)); - s->data = this; - - auto h (reinterpret_cast (&m_hooks)); - h->on_message_begin = &raw_parser::on_message_start; - h->on_url = &raw_parser::on_url; - h->on_status = &raw_parser::on_status; - h->on_header_field = &raw_parser::on_header_field; - h->on_header_value = &raw_parser::on_header_value; - h->on_headers_complete = &raw_parser::on_headers_done; - h->on_body = &raw_parser::on_body; - h->on_message_complete = &raw_parser::on_message_complete; -} - -raw_parser::~raw_parser() -{ -} - -void -raw_parser::reset (message_type type) -{ - auto s (reinterpret_cast (&m_state)); - http_parser_init (s, (type == request) - ? joyent::HTTP_REQUEST : joyent::HTTP_RESPONSE); -} - -auto -raw_parser::process_data (void const* buf, std::size_t bytes) -> - std::pair -{ - auto s (reinterpret_cast (&m_state)); - auto h (reinterpret_cast (&m_hooks)); - std::size_t const bytes_used (joyent::http_parser_execute (s, h, - static_cast (buf), bytes)); - return std::make_pair (m_ec, bytes_used);; -} - -auto -raw_parser::process_eof () -> - error_code -{ - auto s (reinterpret_cast (&m_state)); - auto h (reinterpret_cast (&m_hooks)); - joyent::http_parser_execute (s, h, nullptr, 0); - return m_ec; -} - -//------------------------------------------------------------------------------ - -int -raw_parser::do_message_start () -{ - auto const p (reinterpret_cast (&m_state)); - if (p->type == joyent::HTTP_REQUEST) - m_ec = m_cb.get().on_request (); - else if (p->type == joyent::HTTP_RESPONSE) - m_ec = m_cb.get().on_response (); - return m_ec ? 1 : 0; -} - -int -raw_parser::do_url (char const* in, std::size_t bytes) -{ - m_ec = m_cb.get().on_url (in, bytes); - return m_ec ? 1 : 0; -} - -int -raw_parser::do_status (char const* in, std::size_t bytes) -{ - auto const p (reinterpret_cast (&m_state)); - m_ec = m_cb.get().on_status (p->status_code, in, bytes); - return m_ec ? 1 : 0; -} - -int -raw_parser::do_header_field (char const* in, std::size_t bytes) -{ - m_ec = m_cb.get().on_header_field (in, bytes); - return m_ec ? 1 : 0; -} - -int -raw_parser::do_header_value (char const* in, std::size_t bytes) -{ - m_ec = m_cb.get().on_header_value (in, bytes); - return m_ec ? 1 : 0; -} - -int -raw_parser::do_headers_done () -{ - auto const p (reinterpret_cast (&m_state)); - bool const keep_alive (joyent::http_should_keep_alive (p) != 0); - m_ec = m_cb.get().on_headers_done (keep_alive); - return m_ec ? 1 : 0; -} - -int -raw_parser::do_body (char const* in, std::size_t bytes) -{ - auto const p (reinterpret_cast (&m_state)); - bool const is_final ( - joyent::http_body_is_final (p) != 0); - m_ec = m_cb.get().on_body (is_final, in, bytes); - return m_ec ? 1 : 0; -} - -int -raw_parser::do_message_complete () -{ - auto const p (reinterpret_cast (&m_state)); - bool const keep_alive (joyent::http_should_keep_alive (p) != 0); - m_ec = m_cb.get().on_message_complete (keep_alive); - return m_ec ? 1 : 0; -} - -//------------------------------------------------------------------------------ - -int -raw_parser::on_message_start (joyent::http_parser* p) -{ - return reinterpret_cast ( - p->data)->do_message_start(); -} - -int -raw_parser::on_url (joyent::http_parser* p, - char const* in, std::size_t bytes) -{ - return reinterpret_cast ( - p->data)->do_url (in, bytes); -} - -int -raw_parser::on_status (joyent::http_parser* p, - char const* in, std::size_t bytes) -{ - return reinterpret_cast ( - p->data)->do_status (in, bytes); -} - -int -raw_parser::on_header_field (joyent::http_parser* p, - char const* in, std::size_t bytes) -{ - return reinterpret_cast ( - p->data)->do_header_field (in, bytes); -} - -int -raw_parser::on_header_value (joyent::http_parser* p, - char const* in, std::size_t bytes) -{ - return reinterpret_cast ( - p->data)->do_header_value (in, bytes); -} - -int -raw_parser::on_headers_done (joyent::http_parser* p) -{ - return reinterpret_cast ( - p->data)->do_headers_done(); -} - -int -raw_parser::on_body (joyent::http_parser* p, - char const* in, std::size_t bytes) -{ - return reinterpret_cast ( - p->data)->do_body ( - in, bytes); -} - -int -raw_parser::on_message_complete (joyent::http_parser* p) -{ - return reinterpret_cast ( - p->data)->do_message_complete(); -} - -//------------------------------------------------------------------------------ - -auto -raw_parser::callback::on_request () -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_response () -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_url( - void const*, std::size_t) -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_status (int, - void const*, std::size_t) -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_header_field ( - void const*, std::size_t) -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_header_value ( - void const*, std::size_t) -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_headers_done ( - bool) -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_body ( - bool, void const*, std::size_t) -> - error_code -{ - return error_code(); -} - -auto -raw_parser::callback::on_message_complete ( - bool) -> - error_code -{ - return error_code(); -} - -} -} diff --git a/beast/http/method.h b/beast/http/method.h index e7f7d63c11..0e145eb88f 100644 --- a/beast/http/method.h +++ b/beast/http/method.h @@ -48,6 +48,10 @@ enum class method_t http_proppatch, http_search, http_unlock, + http_bind, + http_rebind, + http_unbind, + http_acl, // subversion http_report, @@ -63,7 +67,14 @@ enum class method_t // RFC-5789 http_patch, - http_purge + http_purge, + + // CalDav + http_mkcalendar, + + // RFC-2068, section 19.6.1.2 + http_link, + http_unlink }; std::string diff --git a/beast/http/raw_parser.h b/beast/http/raw_parser.h deleted file mode 100644 index 47e4b20697..0000000000 --- a/beast/http/raw_parser.h +++ /dev/null @@ -1,202 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_HTTP_RAW_PARSER_H_INCLUDED -#define BEAST_HTTP_RAW_PARSER_H_INCLUDED - -#include - -#include // change to soon - -#include -#include -#include - -namespace beast { - -namespace joyent { -struct http_parser; -}; - -namespace http { - -/** Raw HTTP message parser. - This is implemented using a zero-allocation state machine. The caller - is responsible for all buffer management. -*/ -class raw_parser -{ -private: - using error_code = boost::system::error_code; - -public: - enum message_type - { - request, - response - }; - - struct callback - { - /** Called when the first byte of an HTTP request is received. */ - virtual - error_code - on_request (); - - /** Called when the first byte of an HTTP response is received. */ - virtual - error_code - on_response (); - - /** Called repeatedly to provide parts of the URL. - This is only for requests. - */ - virtual - error_code - on_url ( - void const* in, std::size_t bytes); - - /** Called when the status is received. - This is only for responses. - */ - virtual - error_code - on_status (int status_code, - void const* in, std::size_t bytes); - - /** Called repeatedly to provide parts of a field. */ - virtual - error_code - on_header_field ( - void const* in, std::size_t bytes); - - /** Called repeatedly to provide parts of a value. */ - virtual - error_code - on_header_value ( - void const* in, std::size_t bytes); - - /** Called when there are no more bytes of headers remaining. */ - virtual - error_code - on_headers_done ( - bool keep_alive); - - /** Called repeatedly to provide parts of the body. */ - virtual - error_code - on_body (bool is_final, - void const* in, std::size_t bytes); - - /** Called when there are no more bytes of body remaining. */ - virtual - error_code on_message_complete ( - bool keep_alive); - }; - - explicit raw_parser (callback& cb); - - ~raw_parser(); - - /** Prepare to parse a new message. - The previous state information, if any, is discarded. - */ - void - reset (message_type type); - - /** Processs message data. - The return value includes the error code if any, - and the number of bytes consumed in the input sequence. - */ - std::pair - process_data (void const* in, std::size_t bytes); - - /** Notify the parser the end of the data is reached. - Normally this will be called in response to the remote - end closing down its half of the connection. - */ - error_code - process_eof (); - -private: - int do_message_start (); - int do_url (char const* in, std::size_t bytes); - int do_status (char const* in, std::size_t bytes); - int do_header_field (char const* in, std::size_t bytes); - int do_header_value (char const* in, std::size_t bytes); - int do_headers_done (); - int do_body (char const* in, std::size_t bytes); - int do_message_complete (); - - static int on_message_start (joyent::http_parser*); - static int on_url (joyent::http_parser*, char const*, std::size_t); - static int on_status (joyent::http_parser*, char const*, std::size_t); - static int on_header_field (joyent::http_parser*, char const*, std::size_t); - static int on_header_value (joyent::http_parser*, char const*, std::size_t); - static int on_headers_done (joyent::http_parser*); - static int on_body (joyent::http_parser*, char const*, std::size_t); - static int on_message_complete (joyent::http_parser*); - - // These structures must exactly match the - // declarations in joyent http_parser.h include - // - struct state_t - { - unsigned int type : 2; - unsigned int flags : 6; - unsigned int state : 8; - unsigned int header_state : 8; - unsigned int index : 8; - std::uint32_t nread; - std::uint64_t content_length; - unsigned short http_major; - unsigned short http_minor; - unsigned int status_code : 16; - unsigned int method : 8; - unsigned int http_errno : 7; - unsigned int upgrade : 1; - void *data; - }; - - using data_cb_t = int (*) ( - state_t*, const char *at, size_t length); - using cb_t = int (*) (state_t*); - - struct hooks_t - { - cb_t on_message_begin; - data_cb_t on_url; - data_cb_t on_status; - data_cb_t on_header_field; - data_cb_t on_header_value; - cb_t on_headers_complete; - data_cb_t on_body; - cb_t on_message_complete; - }; - - std::reference_wrapper m_cb; - error_code m_ec; - char m_state [sizeof(state_t)]; - char m_hooks [sizeof(hooks_t)]; -}; - -} -} - -#endif