lsquic_frame_reader.h revision 5392f7a3
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 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{ 393b55e6aeSDmitri Tikhonov FR_ERR_DUPLICATE_PSEH = LSQUIC_HDR_ERR_DUPLICATE_PSDO_HDR, 403b55e6aeSDmitri Tikhonov FR_ERR_INCOMPL_REQ_PSEH = LSQUIC_HDR_ERR_INCOMPL_REQ_PSDO_HDR, 413b55e6aeSDmitri Tikhonov FR_ERR_UNNEC_REQ_PSEH = LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR, 425392f7a3SLiteSpeed Tech FR_ERR_BAD_REQ_HEADER = LSQUIC_HDR_ERR_BAD_REQ_HEADER, 433b55e6aeSDmitri Tikhonov FR_ERR_INCOMPL_RESP_PSEH = LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR, 443b55e6aeSDmitri Tikhonov FR_ERR_UNNEC_RESP_PSEH = LSQUIC_HDR_ERR_UNNEC_RESP_PSDO_HDR, 453b55e6aeSDmitri Tikhonov FR_ERR_UNKNOWN_PSEH = LSQUIC_HDR_ERR_UNKNOWN_PSDO_HDR, 463b55e6aeSDmitri Tikhonov FR_ERR_UPPERCASE_HEADER = LSQUIC_HDR_ERR_UPPERCASE_HEADER, 473b55e6aeSDmitri Tikhonov FR_ERR_MISPLACED_PSEH = LSQUIC_HDR_ERR_MISPLACED_PSDO_HDR, 483b55e6aeSDmitri Tikhonov FR_ERR_MISSING_PSEH = LSQUIC_HDR_ERR_MISSING_PSDO_HDR, 493b55e6aeSDmitri Tikhonov FR_ERR_HEADERS_TOO_LARGE = LSQUIC_HDR_ERR_HEADERS_TOO_LARGE, 503b55e6aeSDmitri Tikhonov FR_ERR_NOMEM = LSQUIC_HDR_ERR_NOMEM, 513b55e6aeSDmitri Tikhonov 5250aadb33SDmitri Tikhonov FR_ERR_DECOMPRESS, 5350aadb33SDmitri Tikhonov FR_ERR_INVALID_FRAME_SIZE, /* E.g. a SETTINGS frame length is not a multiple 5450aadb33SDmitri Tikhonov * of 6 (RFC 7540, Section 6.5.1). 5550aadb33SDmitri Tikhonov */ 5650aadb33SDmitri Tikhonov FR_ERR_NONZERO_STREAM_ID, 5750aadb33SDmitri Tikhonov FR_ERR_ZERO_STREAM_ID, 5850aadb33SDmitri Tikhonov FR_ERR_SELF_DEP_STREAM, /* A stream in priority frame cannot depend on 5950aadb33SDmitri Tikhonov * itself (RFC 7540, Section 5.3.1). 6050aadb33SDmitri Tikhonov */ 6150aadb33SDmitri Tikhonov FR_ERR_UNEXPECTED_PUSH, 6250aadb33SDmitri Tikhonov FR_ERR_EXPECTED_CONTIN, /* Expected continuation frame. */ 6350aadb33SDmitri Tikhonov}; 6450aadb33SDmitri Tikhonov 6550aadb33SDmitri Tikhonov 6650aadb33SDmitri Tikhonovstruct frame_reader_callbacks 6750aadb33SDmitri Tikhonov{ 6850aadb33SDmitri Tikhonov void (*frc_on_headers) (void *frame_cb_ctx, struct uncompressed_headers *); 6950aadb33SDmitri Tikhonov void (*frc_on_push_promise) (void *frame_cb_ctx, struct uncompressed_headers *); 7050aadb33SDmitri Tikhonov void (*frc_on_settings) (void *frame_cb_ctx, uint16_t setting_id, 7150aadb33SDmitri Tikhonov uint32_t setting_value); 725392f7a3SLiteSpeed Tech void (*frc_on_priority) (void *frame_cb_ctx, lsquic_stream_id_t stream_id, 735392f7a3SLiteSpeed Tech int exclusive, lsquic_stream_id_t dep_stream_id, 7450aadb33SDmitri Tikhonov unsigned weight); 755392f7a3SLiteSpeed Tech void (*frc_on_error) (void *frame_cb_ctx, lsquic_stream_id_t stream_id, 7650aadb33SDmitri Tikhonov enum frame_reader_error); 7750aadb33SDmitri Tikhonov}; 7850aadb33SDmitri Tikhonov 7950aadb33SDmitri Tikhonovtypedef ssize_t (*fr_stream_read_f)(struct lsquic_stream *, void *, size_t); 8050aadb33SDmitri Tikhonov 8150aadb33SDmitri Tikhonovstruct lsquic_frame_reader * 8250aadb33SDmitri Tikhonovlsquic_frame_reader_new (enum frame_reader_flags, unsigned max_headers_sz, 8350aadb33SDmitri Tikhonov struct lsquic_mm *, struct lsquic_stream *, 84bea64822SDmitri Tikhonov fr_stream_read_f, struct lshpack_dec *, 853b55e6aeSDmitri Tikhonov const struct frame_reader_callbacks *, void *fr_cb_ctx, 8619f667fbSDmitri Tikhonov#if LSQUIC_CONN_STATS 8719f667fbSDmitri Tikhonov struct conn_stats *conn_stats, 8819f667fbSDmitri Tikhonov#endif 893b55e6aeSDmitri Tikhonov const struct lsquic_hset_if *, void *hsi_ctx); 9050aadb33SDmitri Tikhonov 9150aadb33SDmitri Tikhonovint 9250aadb33SDmitri Tikhonovlsquic_frame_reader_read (struct lsquic_frame_reader *); 9350aadb33SDmitri Tikhonov 9450aadb33SDmitri Tikhonovvoid 9550aadb33SDmitri Tikhonovlsquic_frame_reader_destroy (struct lsquic_frame_reader *); 9650aadb33SDmitri Tikhonov 97c51ce338SDmitri Tikhonovsize_t 98c51ce338SDmitri Tikhonovlsquic_frame_reader_mem_used (const struct lsquic_frame_reader *); 99c51ce338SDmitri Tikhonov 10050aadb33SDmitri Tikhonov#endif 101