0.00% Lines (0/36)
0.00% Functions (0/2)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 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 | #include "src/detail/filter.hpp" | 11 | #include "src/detail/filter.hpp" | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/capy/buffers/buffer_slice.hpp> | 13 | #include <boost/capy/buffers/buffer_slice.hpp> | |||||
| 14 | #include <boost/capy/buffers/front.hpp> | 14 | #include <boost/capy/buffers/front.hpp> | |||||
| 15 | 15 | |||||||
| 16 | namespace boost { | 16 | namespace boost { | |||||
| 17 | namespace http { | 17 | namespace http { | |||||
| 18 | namespace detail { | 18 | namespace detail { | |||||
| 19 | 19 | |||||||
| 20 | namespace { | 20 | namespace { | |||||
| 21 | 21 | |||||||
| 22 | // Returns true if the slice's current data view contains at most one | 22 | // Returns true if the slice's current data view contains at most one | |||||
| 23 | // non-empty buffer (i.e., we are processing the last logical chunk). | 23 | // non-empty buffer (i.e., we are processing the last logical chunk). | |||||
| 24 | template<class Slice> | 24 | template<class Slice> | |||||
| MISUBC | 25 | ✗ | bool single_or_empty(Slice const& s) | 25 | ✗ | bool single_or_empty(Slice const& s) | ||
| 26 | { | 26 | { | |||||
| MISUBC | 27 | ✗ | auto d = s.data(); | 27 | ✗ | auto d = s.data(); | ||
| MISUBC | 28 | ✗ | auto it = d.begin(); | 28 | ✗ | auto it = d.begin(); | ||
| MISUBC | 29 | ✗ | auto const end_it = d.end(); | 29 | ✗ | auto const end_it = d.end(); | ||
| MISUBC | 30 | ✗ | if(it == end_it) | 30 | ✗ | if(it == end_it) | ||
| MISUBC | 31 | ✗ | return true; | 31 | ✗ | return true; | ||
| MISUBC | 32 | ✗ | ++it; | 32 | ✗ | ++it; | ||
| MISUBC | 33 | ✗ | return it == end_it; | 33 | ✗ | return it == end_it; | ||
| 34 | } | 34 | } | |||||
| 35 | 35 | |||||||
| 36 | } // anonymous | 36 | } // anonymous | |||||
| 37 | 37 | |||||||
| 38 | auto | 38 | auto | |||||
| MISUBC | 39 | ✗ | filter:: | 39 | ✗ | filter:: | ||
| 40 | process( | 40 | process( | |||||
| 41 | boost::span<const capy::mutable_buffer> out_seq, | 41 | boost::span<const capy::mutable_buffer> out_seq, | |||||
| 42 | std::array<capy::const_buffer, 2> in_seq, | 42 | std::array<capy::const_buffer, 2> in_seq, | |||||
| 43 | bool more) -> results | 43 | bool more) -> results | |||||
| 44 | { | 44 | { | |||||
| MISUBC | 45 | ✗ | auto out = capy::buffer_slice(out_seq); | 45 | ✗ | auto out = capy::buffer_slice(out_seq); | ||
| MISUBC | 46 | ✗ | auto in = capy::buffer_slice(in_seq); | 46 | ✗ | auto in = capy::buffer_slice(in_seq); | ||
| 47 | 47 | |||||||
| MISUBC | 48 | ✗ | results rv; | 48 | ✗ | results rv; | ||
| MISUBC | 49 | ✗ | bool p_more = true; | 49 | ✗ | bool p_more = true; | ||
| 50 | for(;;) | 50 | for(;;) | |||||
| 51 | { | 51 | { | |||||
| MISUBC | 52 | ✗ | if(!more && p_more && single_or_empty(in)) | 52 | ✗ | if(!more && p_more && single_or_empty(in)) | ||
| 53 | { | 53 | { | |||||
| MISUBC | 54 | ✗ | if(capy::buffer_size(out.data()) < min_out_buffer()) | 54 | ✗ | if(capy::buffer_size(out.data()) < min_out_buffer()) | ||
| 55 | { | 55 | { | |||||
| MISUBC | 56 | ✗ | rv.out_short = true; | 56 | ✗ | rv.out_short = true; | ||
| MISUBC | 57 | ✗ | return rv; | 57 | ✗ | return rv; | ||
| 58 | } | 58 | } | |||||
| MISUBC | 59 | ✗ | p_more = false; | 59 | ✗ | p_more = false; | ||
| 60 | } | 60 | } | |||||
| 61 | 61 | |||||||
| MISUBC | 62 | ✗ | auto ob = capy::front(out.data()); | 62 | ✗ | auto ob = capy::front(out.data()); | ||
| MISUBC | 63 | ✗ | auto ib = capy::front(in.data()); | 63 | ✗ | auto ib = capy::front(in.data()); | ||
| MISUBC | 64 | ✗ | auto rs = do_process(ob, ib, p_more); | 64 | ✗ | auto rs = do_process(ob, ib, p_more); | ||
| 65 | 65 | |||||||
| MISUBC | 66 | ✗ | rv.in_bytes += rs.in_bytes; | 66 | ✗ | rv.in_bytes += rs.in_bytes; | ||
| MISUBC | 67 | ✗ | rv.out_bytes += rs.out_bytes; | 67 | ✗ | rv.out_bytes += rs.out_bytes; | ||
| 68 | 68 | |||||||
| MISUBC | 69 | ✗ | if(rs.ec) | 69 | ✗ | if(rs.ec) | ||
| 70 | { | 70 | { | |||||
| MISUBC | 71 | ✗ | rv.ec = rs.ec; | 71 | ✗ | rv.ec = rs.ec; | ||
| MISUBC | 72 | ✗ | return rv; | 72 | ✗ | return rv; | ||
| 73 | } | 73 | } | |||||
| 74 | 74 | |||||||
| MISUBC | 75 | ✗ | if(rs.finished) | 75 | ✗ | if(rs.finished) | ||
| 76 | { | 76 | { | |||||
| MISUBC | 77 | ✗ | rv.finished = true; | 77 | ✗ | rv.finished = true; | ||
| MISUBC | 78 | ✗ | return rv; | 78 | ✗ | return rv; | ||
| 79 | } | 79 | } | |||||
| 80 | 80 | |||||||
| MISUBC | 81 | ✗ | out.remove_prefix(rs.out_bytes); | 81 | ✗ | out.remove_prefix(rs.out_bytes); | ||
| MISUBC | 82 | ✗ | in.remove_prefix(rs.in_bytes); | 82 | ✗ | in.remove_prefix(rs.in_bytes); | ||
| 83 | 83 | |||||||
| MISUBC | 84 | ✗ | if(capy::buffer_size(out.data()) == 0) | 84 | ✗ | if(capy::buffer_size(out.data()) == 0) | ||
| MISUBC | 85 | ✗ | return rv; | 85 | ✗ | return rv; | ||
| 86 | 86 | |||||||
| MISUBC | 87 | ✗ | if(capy::buffer_size(in.data()) == 0 && rs.out_bytes < ob.size()) | 87 | ✗ | if(capy::buffer_size(in.data()) == 0 && rs.out_bytes < ob.size()) | ||
| MISUBC | 88 | ✗ | return rv; | 88 | ✗ | return rv; | ||
| MISUBC | 89 | ✗ | } | 89 | ✗ | } | ||
| 90 | } | 90 | } | |||||
| 91 | 91 | |||||||
| 92 | } // detail | 92 | } // detail | |||||
| 93 | } // http | 93 | } // http | |||||
| 94 | } // boost | 94 | } // boost | |||||