lsquic_frame_reader.h revision 229fce07
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; 2150aadb33SDmitri Tikhonov 2250aadb33SDmitri Tikhonov 2350aadb33SDmitri Tikhonovenum frame_reader_flags 2450aadb33SDmitri Tikhonov{ 2550aadb33SDmitri Tikhonov FRF_SERVER = (1 << 0), 2650aadb33SDmitri Tikhonov FRF_HAVE_PREV = (1 << 1), 2750aadb33SDmitri Tikhonov}; 2850aadb33SDmitri Tikhonov 2950aadb33SDmitri Tikhonov 3050aadb33SDmitri Tikhonov/* Frame reader may hit some error conditions which are reported using 3150aadb33SDmitri Tikhonov * callback fc_on_error. These codes are later mapped stream- or 3250aadb33SDmitri Tikhonov * connection-level errors. 3350aadb33SDmitri Tikhonov */ 3450aadb33SDmitri Tikhonovenum frame_reader_error 3550aadb33SDmitri Tikhonov{ 363b55e6aeSDmitri Tikhonov FR_ERR_DUPLICATE_PSEH = LSQUIC_HDR_ERR_DUPLICATE_PSDO_HDR, 373b55e6aeSDmitri Tikhonov FR_ERR_INCOMPL_REQ_PSEH = LSQUIC_HDR_ERR_INCOMPL_REQ_PSDO_HDR, 383b55e6aeSDmitri Tikhonov FR_ERR_UNNEC_REQ_PSEH = LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR, 393b55e6aeSDmitri Tikhonov FR_ERR_INCOMPL_RESP_PSEH = LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR, 403b55e6aeSDmitri Tikhonov FR_ERR_UNNEC_RESP_PSEH = LSQUIC_HDR_ERR_UNNEC_RESP_PSDO_HDR, 413b55e6aeSDmitri Tikhonov FR_ERR_UNKNOWN_PSEH = LSQUIC_HDR_ERR_UNKNOWN_PSDO_HDR, 423b55e6aeSDmitri Tikhonov FR_ERR_UPPERCASE_HEADER = LSQUIC_HDR_ERR_UPPERCASE_HEADER, 433b55e6aeSDmitri Tikhonov FR_ERR_MISPLACED_PSEH = LSQUIC_HDR_ERR_MISPLACED_PSDO_HDR, 443b55e6aeSDmitri Tikhonov FR_ERR_MISSING_PSEH = LSQUIC_HDR_ERR_MISSING_PSDO_HDR, 453b55e6aeSDmitri Tikhonov FR_ERR_HEADERS_TOO_LARGE = LSQUIC_HDR_ERR_HEADERS_TOO_LARGE, 463b55e6aeSDmitri Tikhonov FR_ERR_NOMEM = LSQUIC_HDR_ERR_NOMEM, 473b55e6aeSDmitri Tikhonov 4850aadb33SDmitri Tikhonov FR_ERR_DECOMPRESS, 4950aadb33SDmitri Tikhonov FR_ERR_INVALID_FRAME_SIZE, /* E.g. a SETTINGS frame length is not a multiple 5050aadb33SDmitri Tikhonov * of 6 (RFC 7540, Section 6.5.1). 5150aadb33SDmitri Tikhonov */ 5250aadb33SDmitri Tikhonov FR_ERR_NONZERO_STREAM_ID, 5350aadb33SDmitri Tikhonov FR_ERR_ZERO_STREAM_ID, 5450aadb33SDmitri Tikhonov FR_ERR_SELF_DEP_STREAM, /* A stream in priority frame cannot depend on 5550aadb33SDmitri Tikhonov * itself (RFC 7540, Section 5.3.1). 5650aadb33SDmitri Tikhonov */ 5750aadb33SDmitri Tikhonov FR_ERR_UNEXPECTED_PUSH, 5850aadb33SDmitri Tikhonov FR_ERR_EXPECTED_CONTIN, /* Expected continuation frame. */ 5950aadb33SDmitri Tikhonov}; 6050aadb33SDmitri Tikhonov 6150aadb33SDmitri Tikhonov 6250aadb33SDmitri Tikhonovstruct frame_reader_callbacks 6350aadb33SDmitri Tikhonov{ 6450aadb33SDmitri Tikhonov void (*frc_on_headers) (void *frame_cb_ctx, struct uncompressed_headers *); 6550aadb33SDmitri Tikhonov void (*frc_on_push_promise) (void *frame_cb_ctx, struct uncompressed_headers *); 6650aadb33SDmitri Tikhonov void (*frc_on_settings) (void *frame_cb_ctx, uint16_t setting_id, 6750aadb33SDmitri Tikhonov uint32_t setting_value); 6850aadb33SDmitri Tikhonov void (*frc_on_priority) (void *frame_cb_ctx, uint32_t stream_id, 6950aadb33SDmitri Tikhonov int exclusive, uint32_t dep_stream_id, 7050aadb33SDmitri Tikhonov unsigned weight); 7150aadb33SDmitri Tikhonov void (*frc_on_error) (void *frame_cb_ctx, uint32_t stream_id, 7250aadb33SDmitri Tikhonov enum frame_reader_error); 7350aadb33SDmitri Tikhonov}; 7450aadb33SDmitri Tikhonov 7550aadb33SDmitri Tikhonovtypedef ssize_t (*fr_stream_read_f)(struct lsquic_stream *, void *, size_t); 7650aadb33SDmitri Tikhonov 7750aadb33SDmitri Tikhonovstruct lsquic_frame_reader * 7850aadb33SDmitri Tikhonovlsquic_frame_reader_new (enum frame_reader_flags, unsigned max_headers_sz, 7950aadb33SDmitri Tikhonov struct lsquic_mm *, struct lsquic_stream *, 80bea64822SDmitri Tikhonov fr_stream_read_f, struct lshpack_dec *, 813b55e6aeSDmitri Tikhonov const struct frame_reader_callbacks *, void *fr_cb_ctx, 823b55e6aeSDmitri Tikhonov const struct lsquic_hset_if *, void *hsi_ctx); 8350aadb33SDmitri Tikhonov 8450aadb33SDmitri Tikhonovint 8550aadb33SDmitri Tikhonovlsquic_frame_reader_read (struct lsquic_frame_reader *); 8650aadb33SDmitri Tikhonov 8750aadb33SDmitri Tikhonovvoid 8850aadb33SDmitri Tikhonovlsquic_frame_reader_destroy (struct lsquic_frame_reader *); 8950aadb33SDmitri Tikhonov 90c51ce338SDmitri Tikhonovsize_t 91c51ce338SDmitri Tikhonovlsquic_frame_reader_mem_used (const struct lsquic_frame_reader *); 92c51ce338SDmitri Tikhonov 9350aadb33SDmitri Tikhonov#endif 94