lsquic_frame_reader.h revision 7d09751d
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_frame_reader.h -- Read HTTP frames from stream 4 */ 5 6#ifndef LSQUIC_FRAME_READER_H 7#define LSQUIC_FRAME_READER_H 1 8 9#include <stddef.h> 10#include <stdint.h> 11#ifdef WIN32 12#include <vc_compat.h> 13#endif 14 15struct lshpack_dec; 16struct lsquic_mm; 17struct lsquic_stream; 18struct lsquic_frame_reader; 19struct lsquic_hset_if; 20struct uncompressed_headers; 21#if LSQUIC_CONN_STATS 22struct conn_stats; 23#endif 24 25 26enum frame_reader_flags 27{ 28 FRF_SERVER = (1 << 0), 29 FRF_HAVE_PREV = (1 << 1), 30}; 31 32 33/* Frame reader may hit some error conditions which are reported using 34 * callback fc_on_error. These codes are later mapped stream- or 35 * connection-level errors. 36 */ 37enum frame_reader_error 38{ 39 FR_ERR_DUPLICATE_PSEH = LSQUIC_HDR_ERR_DUPLICATE_PSDO_HDR, 40 FR_ERR_INCOMPL_REQ_PSEH = LSQUIC_HDR_ERR_INCOMPL_REQ_PSDO_HDR, 41 FR_ERR_UNNEC_REQ_PSEH = LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR, 42 FR_ERR_BAD_REQ_HEADER = LSQUIC_HDR_ERR_BAD_REQ_HEADER, 43 FR_ERR_INCOMPL_RESP_PSEH = LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR, 44 FR_ERR_UNNEC_RESP_PSEH = LSQUIC_HDR_ERR_UNNEC_RESP_PSDO_HDR, 45 FR_ERR_UNKNOWN_PSEH = LSQUIC_HDR_ERR_UNKNOWN_PSDO_HDR, 46 FR_ERR_UPPERCASE_HEADER = LSQUIC_HDR_ERR_UPPERCASE_HEADER, 47 FR_ERR_MISPLACED_PSEH = LSQUIC_HDR_ERR_MISPLACED_PSDO_HDR, 48 FR_ERR_MISSING_PSEH = LSQUIC_HDR_ERR_MISSING_PSDO_HDR, 49 FR_ERR_HEADERS_TOO_LARGE = LSQUIC_HDR_ERR_HEADERS_TOO_LARGE, 50 FR_ERR_NOMEM = LSQUIC_HDR_ERR_NOMEM, 51 52 FR_ERR_DECOMPRESS, 53 FR_ERR_INVALID_FRAME_SIZE, /* E.g. a SETTINGS frame length is not a multiple 54 * of 6 (RFC 7540, Section 6.5.1). 55 */ 56 FR_ERR_NONZERO_STREAM_ID, 57 FR_ERR_ZERO_STREAM_ID, 58 FR_ERR_SELF_DEP_STREAM, /* A stream in priority frame cannot depend on 59 * itself (RFC 7540, Section 5.3.1). 60 */ 61 FR_ERR_UNEXPECTED_PUSH, 62 FR_ERR_EXPECTED_CONTIN, /* Expected continuation frame. */ 63}; 64 65 66struct frame_reader_callbacks 67{ 68 void (*frc_on_headers) (void *frame_cb_ctx, struct uncompressed_headers *); 69 void (*frc_on_push_promise) (void *frame_cb_ctx, struct uncompressed_headers *); 70 void (*frc_on_settings) (void *frame_cb_ctx, uint16_t setting_id, 71 uint32_t setting_value); 72 void (*frc_on_priority) (void *frame_cb_ctx, lsquic_stream_id_t stream_id, 73 int exclusive, lsquic_stream_id_t dep_stream_id, 74 unsigned weight); 75 void (*frc_on_error) (void *frame_cb_ctx, lsquic_stream_id_t stream_id, 76 enum frame_reader_error); 77}; 78 79typedef ssize_t (*fr_stream_read_f)(struct lsquic_stream *, void *, size_t); 80 81struct lsquic_frame_reader * 82lsquic_frame_reader_new (enum frame_reader_flags, unsigned max_headers_sz, 83 struct lsquic_mm *, struct lsquic_stream *, 84 fr_stream_read_f, struct lshpack_dec *, 85 const struct frame_reader_callbacks *, void *fr_cb_ctx, 86#if LSQUIC_CONN_STATS 87 struct conn_stats *conn_stats, 88#endif 89 const struct lsquic_hset_if *, void *hsi_ctx); 90 91int 92lsquic_frame_reader_read (struct lsquic_frame_reader *); 93 94void 95lsquic_frame_reader_destroy (struct lsquic_frame_reader *); 96 97size_t 98lsquic_frame_reader_mem_used (const struct lsquic_frame_reader *); 99 100#endif 101