70.00% Lines (28/40)
100.00% Functions (2/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/buffers_front.hpp> | 13 | #include <boost/capy/buffers/buffers_front.hpp> | |||||
| 14 | #include <boost/http/io/buffer_param.hpp> | 14 | #include <boost/http/io/buffer_param.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> | |||||
| HITCBC | 25 | 2 | bool single_or_empty(Slice& s) | 25 | 2 | bool single_or_empty(Slice& s) | ||
| 26 | { | 26 | { | |||||
| HITCBC | 27 | 2 | auto d = s.data(); | 27 | 2 | auto d = s.data(); | ||
| HITCBC | 28 | 2 | auto it = d.begin(); | 28 | 2 | auto it = d.begin(); | ||
| HITCBC | 29 | 2 | auto const end_it = d.end(); | 29 | 2 | auto const end_it = d.end(); | ||
| HITCBC | 30 | 2 | if(it == end_it) | 30 | 2 | if(it == end_it) | ||
| HITCBC | 31 | 1 | return true; | 31 | 1 | return true; | ||
| HITCBC | 32 | 1 | ++it; | 32 | 1 | ++it; | ||
| HITCBC | 33 | 1 | return it == end_it; | 33 | 1 | return it == end_it; | ||
| 34 | } | 34 | } | |||||
| 35 | 35 | |||||||
| 36 | } // anonymous | 36 | } // anonymous | |||||
| 37 | 37 | |||||||
| 38 | auto | 38 | auto | |||||
| HITCBC | 39 | 2 | filter:: | 39 | 2 | 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 | { | |||||
| HITCBC | 45 | 2 | buffer_param out(out_seq); | 45 | 2 | buffer_param out(out_seq); | ||
| HITCBC | 46 | 2 | buffer_param in(in_seq); | 46 | 2 | buffer_param in(in_seq); | ||
| 47 | 47 | |||||||
| 48 | // data() spans only the current window, so track totals separately | 48 | // data() spans only the current window, so track totals separately | |||||
| HITCBC | 49 | 2 | std::size_t out_left = capy::buffer_size(out_seq); | 49 | 2 | std::size_t out_left = capy::buffer_size(out_seq); | ||
| HITCBC | 50 | 2 | std::size_t in_left = capy::buffer_size(in_seq); | 50 | 2 | std::size_t in_left = capy::buffer_size(in_seq); | ||
| 51 | 51 | |||||||
| HITCBC | 52 | 2 | results rv; | 52 | 2 | results rv; | ||
| HITCBC | 53 | 2 | bool p_more = true; | 53 | 2 | bool p_more = true; | ||
| 54 | for(;;) | 54 | for(;;) | |||||
| 55 | { | 55 | { | |||||
| HITCBC | 56 | 2 | if(!more && p_more && single_or_empty(in)) | 56 | 2 | if(!more && p_more && single_or_empty(in)) | ||
| 57 | { | 57 | { | |||||
| HITCBC | 58 | 2 | if(out_left < min_out_buffer()) | 58 | 2 | if(out_left < min_out_buffer()) | ||
| 59 | { | 59 | { | |||||
| MISUBC | 60 | ✗ | rv.out_short = true; | 60 | ✗ | rv.out_short = true; | ||
| HITCBC | 61 | 2 | return rv; | 61 | 2 | return rv; | ||
| 62 | } | 62 | } | |||||
| HITCBC | 63 | 2 | p_more = false; | 63 | 2 | p_more = false; | ||
| 64 | } | 64 | } | |||||
| 65 | 65 | |||||||
| HITCBC | 66 | 2 | auto ob = capy::buffers_front(out.data()); | 66 | 2 | auto ob = capy::buffers_front(out.data()); | ||
| HITCBC | 67 | 2 | auto ib = capy::buffers_front(in.data()); | 67 | 2 | auto ib = capy::buffers_front(in.data()); | ||
| HITCBC | 68 | 2 | auto rs = do_process(ob, ib, p_more); | 68 | 2 | auto rs = do_process(ob, ib, p_more); | ||
| 69 | 69 | |||||||
| HITCBC | 70 | 2 | rv.in_bytes += rs.in_bytes; | 70 | 2 | rv.in_bytes += rs.in_bytes; | ||
| HITCBC | 71 | 2 | rv.out_bytes += rs.out_bytes; | 71 | 2 | rv.out_bytes += rs.out_bytes; | ||
| 72 | 72 | |||||||
| HITCBC | 73 | 2 | if(rs.ec) | 73 | 2 | if(rs.ec) | ||
| 74 | { | 74 | { | |||||
| MISUBC | 75 | ✗ | rv.ec = rs.ec; | 75 | ✗ | rv.ec = rs.ec; | ||
| MISUBC | 76 | ✗ | return rv; | 76 | ✗ | return rv; | ||
| 77 | } | 77 | } | |||||
| 78 | 78 | |||||||
| HITCBC | 79 | 2 | if(rs.finished) | 79 | 2 | if(rs.finished) | ||
| 80 | { | 80 | { | |||||
| HITCBC | 81 | 2 | rv.finished = true; | 81 | 2 | rv.finished = true; | ||
| HITCBC | 82 | 2 | return rv; | 82 | 2 | return rv; | ||
| 83 | } | 83 | } | |||||
| 84 | 84 | |||||||
| MISUBC | 85 | ✗ | out.consume(rs.out_bytes); | 85 | ✗ | out.consume(rs.out_bytes); | ||
| MISUBC | 86 | ✗ | in.consume(rs.in_bytes); | 86 | ✗ | in.consume(rs.in_bytes); | ||
| MISUBC | 87 | ✗ | out_left -= rs.out_bytes; | 87 | ✗ | out_left -= rs.out_bytes; | ||
| MISUBC | 88 | ✗ | in_left -= rs.in_bytes; | 88 | ✗ | in_left -= rs.in_bytes; | ||
| 89 | 89 | |||||||
| MISUBC | 90 | ✗ | if(out_left == 0) | 90 | ✗ | if(out_left == 0) | ||
| MISUBC | 91 | ✗ | return rv; | 91 | ✗ | return rv; | ||
| 92 | 92 | |||||||
| MISUBC | 93 | ✗ | if(in_left == 0 && rs.out_bytes < ob.size()) | 93 | ✗ | if(in_left == 0 && rs.out_bytes < ob.size()) | ||
| MISUBC | 94 | ✗ | return rv; | 94 | ✗ | return rv; | ||
| MISUBC | 95 | ✗ | } | 95 | ✗ | } | ||
| 96 | } | 96 | } | |||||
| 97 | 97 | |||||||
| 98 | } // detail | 98 | } // detail | |||||
| 99 | } // http | 99 | } // http | |||||
| 100 | } // boost | 100 | } // boost | |||||