1 /* 2 * Copyright 2022-2026 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 #ifndef OSSL_QUIC_STRM_REAS_H 11 #define OSSL_QUIC_STRM_REAS_H 12 13 #include "internal/common.h" 14 #include "internal/uint_set.h" 15 #include "internal/quic_record_rx.h" 16 17 #ifndef OPENSSL_NO_QUIC 18 #include "internal/ossl_rbtree.h" 19 20 typedef struct sframe_set_t { 21 OSSL_RBT_HEAD(srange, sframe_set_t) 22 ranges; 23 /* Is the tail frame final. */ 24 unsigned int fin; 25 uint64_t fin_off; 26 /* Number of stream frames in the list. */ 27 size_t stream_ranges; 28 size_t stream_chunks; 29 /* Offset of data not yet dropped */ 30 uint64_t offset; 31 /* Cleanse data on release? */ 32 int cleanse; 33 int move_buffers; 34 QUIC_RSTREAM_QPARM *rsqp; 35 } SFRAME_SET; 36 37 /* 38 * Initializes the stream frame list fs. 39 */ 40 void ossl_sframe_set_init(SFRAME_SET *fs, QUIC_RSTREAM_QPARM *rsqp); 41 42 /* 43 * Destroys the stream frame list fs releasing any data 44 * still present inside it. 45 */ 46 void ossl_sframe_set_destroy_ranges(SFRAME_SET *fs); 47 48 /* 49 * Insert a stream frame data into the list. 50 * The data covers an offset range (range.start is inclusive, 51 * range.end is exclusive). 52 * fin should be set if this is the final frame of the stream. 53 * Returns an error if a frame cannot be inserted - due to 54 * STREAM_FRAME allocation error, or in case of erroneous 55 * fin flag. 56 */ 57 int ossl_sframe_set_insert(SFRAME_SET *fs, UINT_RANGE *range, 58 OSSL_QRX_PKT *pkt, 59 const unsigned char *data, int fin); 60 61 /* 62 * Iterator to peek at the contiguous frames at the beginning 63 * of the frame set (the first stream range). 64 * The *data covers an offset range (range.start is inclusive, 65 * range.end is exclusive). 66 * *fin is set if this is the final frame of the stream. 67 * Opaque iterator *iter can be used to peek at the subsequent 68 * frame if there is any without any gap before it. 69 * Returns 1 on success. 70 * Returns 0 if there is no further contiguous frame. In that 71 * case *fin is set, if the end of the stream is reached. 72 */ 73 int ossl_sframe_set_peek(SFRAME_SET *fs, void **iter, 74 UINT_RANGE *range, const unsigned char **data, 75 int *fin); 76 77 /* 78 * moves reading offset to new position, discarding all consumed 79 * chunks (which end offset is less than offset). 80 */ 81 int ossl_sframe_set_move_offset(SFRAME_SET *fs, uint64_t offset); 82 83 /* 84 * returns how many bytes is available to read from stream. 85 */ 86 int ossl_sframe_set_avail(SFRAME_SET *fs, uint64_t *avail, int *fin); 87 88 #endif 89 90 #endif 91