1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */ 250aadb33SDmitri Tikhonov/* 350aadb33SDmitri Tikhonov * lsquic_frame_reader.h -- Read HTTP frames from stream 450aadb33SDmitri Tikhonov */ 550aadb33SDmitri Tikhonov 650aadb33SDmitri Tikhonov#ifndef LSQUIC_FRAME_READER_H 750aadb33SDmitri Tikhonov#define LSQUIC_FRAME_READER_H 1 850aadb33SDmitri Tikhonov 950aadb33SDmitri Tikhonov#include <stddef.h> 1050aadb33SDmitri Tikhonov#include <stdint.h> 11ab5c8df2SBob Perper#ifdef WIN32 12ab5c8df2SBob Perper#include <vc_compat.h> 13ab5c8df2SBob Perper#endif 1450aadb33SDmitri Tikhonov 15bea64822SDmitri Tikhonovstruct lshpack_dec; 1650aadb33SDmitri Tikhonovstruct lsquic_mm; 1750aadb33SDmitri Tikhonovstruct lsquic_stream; 1850aadb33SDmitri Tikhonovstruct lsquic_frame_reader; 193b55e6aeSDmitri Tikhonovstruct lsquic_hset_if; 203b55e6aeSDmitri Tikhonovstruct uncompressed_headers; 2119f667fbSDmitri Tikhonov#if LSQUIC_CONN_STATS 2219f667fbSDmitri Tikhonovstruct conn_stats; 2319f667fbSDmitri Tikhonov#endif 2450aadb33SDmitri Tikhonov 2550aadb33SDmitri Tikhonov 2650aadb33SDmitri Tikhonovenum frame_reader_flags 2750aadb33SDmitri Tikhonov{ 2850aadb33SDmitri Tikhonov FRF_SERVER = (1 << 0), 2950aadb33SDmitri Tikhonov FRF_HAVE_PREV = (1 << 1), 3050aadb33SDmitri Tikhonov}; 3150aadb33SDmitri Tikhonov 3250aadb33SDmitri Tikhonov 3350aadb33SDmitri Tikhonov/* Frame reader may hit some error conditions which are reported using 3450aadb33SDmitri Tikhonov * callback fc_on_error. These codes are later mapped stream- or 3550aadb33SDmitri Tikhonov * connection-level errors. 3650aadb33SDmitri Tikhonov */ 3750aadb33SDmitri Tikhonovenum frame_reader_error 3850aadb33SDmitri Tikhonov{ 39a5fa05f9SDmitri Tikhonov FR_ERR_BAD_HEADER, 40a5fa05f9SDmitri Tikhonov FR_ERR_OTHER_ERROR, 413b55e6aeSDmitri Tikhonov 4250aadb33SDmitri Tikhonov FR_ERR_DECOMPRESS, 4350aadb33SDmitri Tikhonov FR_ERR_INVALID_FRAME_SIZE, /* E.g. a SETTINGS frame length is not a multiple 4450aadb33SDmitri Tikhonov * of 6 (RFC 7540, Section 6.5.1). 4550aadb33SDmitri Tikhonov */ 4650aadb33SDmitri Tikhonov FR_ERR_NONZERO_STREAM_ID, 4750aadb33SDmitri Tikhonov FR_ERR_ZERO_STREAM_ID, 4850aadb33SDmitri Tikhonov FR_ERR_SELF_DEP_STREAM, /* A stream in priority frame cannot depend on 4950aadb33SDmitri Tikhonov * itself (RFC 7540, Section 5.3.1). 5050aadb33SDmitri Tikhonov */ 5150aadb33SDmitri Tikhonov FR_ERR_UNEXPECTED_PUSH, 5250aadb33SDmitri Tikhonov FR_ERR_EXPECTED_CONTIN, /* Expected continuation frame. */ 5350aadb33SDmitri Tikhonov}; 5450aadb33SDmitri Tikhonov 5550aadb33SDmitri Tikhonov 5650aadb33SDmitri Tikhonovstruct frame_reader_callbacks 5750aadb33SDmitri Tikhonov{ 5850aadb33SDmitri Tikhonov void (*frc_on_headers) (void *frame_cb_ctx, struct uncompressed_headers *); 5950aadb33SDmitri Tikhonov void (*frc_on_push_promise) (void *frame_cb_ctx, struct uncompressed_headers *); 6050aadb33SDmitri Tikhonov void (*frc_on_settings) (void *frame_cb_ctx, uint16_t setting_id, 6150aadb33SDmitri Tikhonov uint32_t setting_value); 625392f7a3SLiteSpeed Tech void (*frc_on_priority) (void *frame_cb_ctx, lsquic_stream_id_t stream_id, 635392f7a3SLiteSpeed Tech int exclusive, lsquic_stream_id_t dep_stream_id, 6450aadb33SDmitri Tikhonov unsigned weight); 655392f7a3SLiteSpeed Tech void (*frc_on_error) (void *frame_cb_ctx, lsquic_stream_id_t stream_id, 6650aadb33SDmitri Tikhonov enum frame_reader_error); 6750aadb33SDmitri Tikhonov}; 6850aadb33SDmitri Tikhonov 6950aadb33SDmitri Tikhonovtypedef ssize_t (*fr_stream_read_f)(struct lsquic_stream *, void *, size_t); 7050aadb33SDmitri Tikhonov 7150aadb33SDmitri Tikhonovstruct lsquic_frame_reader * 7250aadb33SDmitri Tikhonovlsquic_frame_reader_new (enum frame_reader_flags, unsigned max_headers_sz, 7350aadb33SDmitri Tikhonov struct lsquic_mm *, struct lsquic_stream *, 74bea64822SDmitri Tikhonov fr_stream_read_f, struct lshpack_dec *, 753b55e6aeSDmitri Tikhonov const struct frame_reader_callbacks *, void *fr_cb_ctx, 7619f667fbSDmitri Tikhonov#if LSQUIC_CONN_STATS 7719f667fbSDmitri Tikhonov struct conn_stats *conn_stats, 7819f667fbSDmitri Tikhonov#endif 793b55e6aeSDmitri Tikhonov const struct lsquic_hset_if *, void *hsi_ctx); 8050aadb33SDmitri Tikhonov 8150aadb33SDmitri Tikhonovint 8250aadb33SDmitri Tikhonovlsquic_frame_reader_read (struct lsquic_frame_reader *); 8350aadb33SDmitri Tikhonov 8450aadb33SDmitri Tikhonovvoid 8550aadb33SDmitri Tikhonovlsquic_frame_reader_destroy (struct lsquic_frame_reader *); 8650aadb33SDmitri Tikhonov 87c51ce338SDmitri Tikhonovsize_t 88c51ce338SDmitri Tikhonovlsquic_frame_reader_mem_used (const struct lsquic_frame_reader *); 89c51ce338SDmitri Tikhonov 9050aadb33SDmitri Tikhonov#endif 91