From 00ebd903e0a21af79ccc569263727b4d576264d8 Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Thu, 8 Feb 2024 10:28:27 -0800 Subject: [PATCH] field parsing rules defined in private headers --- include/boost/http_proto/rfc/detail/rules.hpp | 30 --------- src/fields_base.cpp | 3 + src/rfc/detail/rules.cpp | 4 +- src/rfc/detail/rules.hpp | 61 +++++++++++++++++++ 4 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 src/rfc/detail/rules.hpp diff --git a/include/boost/http_proto/rfc/detail/rules.hpp b/include/boost/http_proto/rfc/detail/rules.hpp index 72ef172d..0addca92 100644 --- a/include/boost/http_proto/rfc/detail/rules.hpp +++ b/include/boost/http_proto/rfc/detail/rules.hpp @@ -229,36 +229,6 @@ status_line_rule = //------------------------------------------------ -// header-field = field-name ":" OWS field-value OWS -struct field_name_rule_t -{ - using value_type = core::string_view; - - system::result - parse( - char const *&it, - char const *end) const noexcept; -}; - -constexpr field_name_rule_t field_name_rule{}; - -struct field_value_rule_t -{ - struct value_type - { - core::string_view value; - bool has_obs_fold = false; - bool has_crlf = false; - }; - - system::result - parse( - char const *&it, - char const *end) const noexcept; -}; - -constexpr field_value_rule_t field_value_rule{}; - struct field_rule_t { struct value_type diff --git a/src/fields_base.cpp b/src/fields_base.cpp index e6872627..aabfc300 100644 --- a/src/fields_base.cpp +++ b/src/fields_base.cpp @@ -21,12 +21,15 @@ #include #include +#include + #include #include #include #include #include "detail/move_chars.hpp" +#include "rfc/detail/rules.hpp" namespace boost { namespace http_proto { diff --git a/src/rfc/detail/rules.cpp b/src/rfc/detail/rules.cpp index 0437ee1d..41033b7e 100644 --- a/src/rfc/detail/rules.cpp +++ b/src/rfc/detail/rules.cpp @@ -21,6 +21,8 @@ #include #include +#include "rules.hpp" + namespace boost { namespace http_proto { namespace detail { @@ -271,10 +273,8 @@ parse( goto done; if( end - it < 3 ) - { BOOST_HTTP_PROTO_RETURN_EC( grammar::error::need_more); - } if(! ws(it[2]) ) { diff --git a/src/rfc/detail/rules.hpp b/src/rfc/detail/rules.hpp new file mode 100644 index 00000000..990ceabe --- /dev/null +++ b/src/rfc/detail/rules.hpp @@ -0,0 +1,61 @@ +// +// Copyright (c) 2024 Christian Mazakas +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/cppalliance/http_proto +// + +#ifndef BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP +#define BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP + +#include +#include + +namespace boost +{ +namespace http_proto +{ +namespace detail +{ + +// header-field = field-name ":" OWS field-value OWS +struct field_name_rule_t +{ + using value_type = core::string_view; + + system::result + parse( + char const*& it, + char const* end) const noexcept; +}; + +constexpr field_name_rule_t field_name_rule{}; + +struct field_value_rule_t +{ + struct value_type + { + core::string_view value; + // detected occurrence of `\r\n `, `\r\n\t` + bool has_obs_fold = false; + // detected `\r\nX`, attempt at field termination + bool has_crlf = false; + }; + + system::result + parse( + char const*& it, + char const* end) const noexcept; +}; + +constexpr field_value_rule_t field_value_rule{}; + +} // namespace detail +} // namespace http_proto +} // namespace boost + + + +#endif // BOOST_HTTP_PROTO_SRC_RFC_DETAIL_RULES_HPP