1  
//
1  
//
2  
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com)
3  
// Copyright (c) 2024 Mohammad Nejati
3  
// Copyright (c) 2024 Mohammad Nejati
4  
//
4  
//
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  
//
7  
//
8  
// Official repository: https://github.com/cppalliance/http
8  
// Official repository: https://github.com/cppalliance/http
9  
//
9  
//
10  

10  

11  
#ifndef BOOST_HTTP_DETAIL_FILTER_HPP
11  
#ifndef BOOST_HTTP_DETAIL_FILTER_HPP
12  
#define BOOST_HTTP_DETAIL_FILTER_HPP
12  
#define BOOST_HTTP_DETAIL_FILTER_HPP
13  

13  

14  
#include <boost/capy/buffers/buffer_pair.hpp>
14  
#include <boost/capy/buffers/buffer_pair.hpp>
15  
#include <boost/capy/buffers/slice.hpp>
15  
#include <boost/capy/buffers/slice.hpp>
16  
#include <boost/core/span.hpp>
16  
#include <boost/core/span.hpp>
17  
#include <boost/system/error_code.hpp>
17  
#include <boost/system/error_code.hpp>
18  

18  

19  
namespace boost {
19  
namespace boost {
20  
namespace http {
20  
namespace http {
21  
namespace detail {
21  
namespace detail {
22  

22  

23  
/** Base class for all filters
23  
/** Base class for all filters
24  
*/
24  
*/
25  
class filter
25  
class filter
26  
{
26  
{
27  
public:
27  
public:
28  
    virtual ~filter() = default;
28  
    virtual ~filter() = default;
29  

29  

30  
    /** The results of processing the filter.
30  
    /** The results of processing the filter.
31  
    */
31  
    */
32  
    struct results
32  
    struct results
33  
    {
33  
    {
34  
        /** The error, if any occurred.
34  
        /** The error, if any occurred.
35  
        */
35  
        */
36  
        system::error_code ec;
36  
        system::error_code ec;
37  

37  

38  
        /** The number of bytes produced in the output.
38  
        /** The number of bytes produced in the output.
39  

39  

40  
            This may be less than the total number
40  
            This may be less than the total number
41  
            of bytes available for writing in the
41  
            of bytes available for writing in the
42  
            destination buffers.
42  
            destination buffers.
43  
        */
43  
        */
44  
        std::size_t out_bytes = 0;
44  
        std::size_t out_bytes = 0;
45  

45  

46  
        /** The number of bytes consumed from the input.
46  
        /** The number of bytes consumed from the input.
47  

47  

48  
            This may be less than the total number
48  
            This may be less than the total number
49  
            of bytes available for reading in the
49  
            of bytes available for reading in the
50  
            source buffers.
50  
            source buffers.
51  
        */
51  
        */
52  
        std::size_t in_bytes = 0;
52  
        std::size_t in_bytes = 0;
53  

53  

54  
        /** True if the output buffer is too
54  
        /** True if the output buffer is too
55  
            small to make progress.
55  
            small to make progress.
56  

56  

57  
            This can only happen in deflate operation.
57  
            This can only happen in deflate operation.
58  
        */
58  
        */
59  
        bool out_short = false;
59  
        bool out_short = false;
60  

60  

61  
        /** True if there will be no more output.
61  
        /** True if there will be no more output.
62  
        */
62  
        */
63  
        bool finished = false;
63  
        bool finished = false;
64  
    };
64  
    };
65  

65  

66  
    results
66  
    results
67  
    process(
67  
    process(
68  
        capy::slice_of<
68  
        capy::slice_of<
69  
            boost::span<const capy::mutable_buffer>> out,
69  
            boost::span<const capy::mutable_buffer>> out,
70  
        capy::const_buffer_pair in,
70  
        capy::const_buffer_pair in,
71  
        bool more);
71  
        bool more);
72  

72  

73  
protected:
73  
protected:
74  
    virtual
74  
    virtual
75  
    std::size_t
75  
    std::size_t
76  
    min_out_buffer() const noexcept
76  
    min_out_buffer() const noexcept
77  
    {
77  
    {
78  
        return 0;
78  
        return 0;
79  
    }
79  
    }
80  

80  

81  
    virtual
81  
    virtual
82  
    results
82  
    results
83  
    do_process(
83  
    do_process(
84  
        capy::mutable_buffer,
84  
        capy::mutable_buffer,
85  
        capy::const_buffer,
85  
        capy::const_buffer,
86  
        bool) noexcept = 0;
86  
        bool) noexcept = 0;
87  
};
87  
};
88  

88  

89  
} // detail
89  
} // detail
90  
} // http
90  
} // http
91  
} // boost
91  
} // boost
92  

92  

93  
#endif
93  
#endif