lsquic_frame_reader.h revision 19f667fb
1/* Copyright (c) 2017 - 2019 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_INCOMPL_RESP_PSEH  =  LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR,
43    FR_ERR_UNNEC_RESP_PSEH    =  LSQUIC_HDR_ERR_UNNEC_RESP_PSDO_HDR,
44    FR_ERR_UNKNOWN_PSEH       =  LSQUIC_HDR_ERR_UNKNOWN_PSDO_HDR,
45    FR_ERR_UPPERCASE_HEADER   =  LSQUIC_HDR_ERR_UPPERCASE_HEADER,
46    FR_ERR_MISPLACED_PSEH     =  LSQUIC_HDR_ERR_MISPLACED_PSDO_HDR,
47    FR_ERR_MISSING_PSEH       =  LSQUIC_HDR_ERR_MISSING_PSDO_HDR,
48    FR_ERR_HEADERS_TOO_LARGE  =  LSQUIC_HDR_ERR_HEADERS_TOO_LARGE,
49    FR_ERR_NOMEM              =  LSQUIC_HDR_ERR_NOMEM,
50
51    FR_ERR_DECOMPRESS,
52    FR_ERR_INVALID_FRAME_SIZE,  /* E.g. a SETTINGS frame length is not a multiple
53                                 * of 6 (RFC 7540, Section 6.5.1).
54                                 */
55    FR_ERR_NONZERO_STREAM_ID,
56    FR_ERR_ZERO_STREAM_ID,
57    FR_ERR_SELF_DEP_STREAM,     /* A stream in priority frame cannot depend on
58                                 * itself (RFC 7540, Section 5.3.1).
59                                 */
60    FR_ERR_UNEXPECTED_PUSH,
61    FR_ERR_EXPECTED_CONTIN,     /* Expected continuation frame. */
62};
63
64
65struct frame_reader_callbacks
66{
67    void (*frc_on_headers)      (void *frame_cb_ctx, struct uncompressed_headers *);
68    void (*frc_on_push_promise) (void *frame_cb_ctx, struct uncompressed_headers *);
69    void (*frc_on_settings)     (void *frame_cb_ctx, uint16_t setting_id,
70                                 uint32_t setting_value);
71    void (*frc_on_priority)     (void *frame_cb_ctx, uint32_t stream_id,
72                                 int exclusive, uint32_t dep_stream_id,
73                                 unsigned weight);
74    void (*frc_on_error)        (void *frame_cb_ctx, uint32_t stream_id,
75                                 enum frame_reader_error);
76};
77
78typedef ssize_t (*fr_stream_read_f)(struct lsquic_stream *, void *, size_t);
79
80struct lsquic_frame_reader *
81lsquic_frame_reader_new (enum frame_reader_flags, unsigned max_headers_sz,
82                         struct lsquic_mm *, struct lsquic_stream *,
83                         fr_stream_read_f, struct lshpack_dec *,
84                         const struct frame_reader_callbacks *, void *fr_cb_ctx,
85#if LSQUIC_CONN_STATS
86                         struct conn_stats *conn_stats,
87#endif
88                         const struct lsquic_hset_if *, void *hsi_ctx);
89
90int
91lsquic_frame_reader_read (struct lsquic_frame_reader *);
92
93void
94lsquic_frame_reader_destroy (struct lsquic_frame_reader *);
95
96size_t
97lsquic_frame_reader_mem_used (const struct lsquic_frame_reader *);
98
99#endif
100