lsquic_frame_reader.h revision 3b55e6ae
1/* Copyright (c) 2017 - 2018 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
22
23enum frame_reader_flags
24{
25    FRF_SERVER      = (1 << 0),
26    FRF_HAVE_PREV   = (1 << 1),
27};
28
29
30/* Frame reader may hit some error conditions which are reported using
31 * callback fc_on_error.  These codes are later mapped stream- or
32 * connection-level errors.
33 */
34enum frame_reader_error
35{
36    FR_ERR_DUPLICATE_PSEH     =  LSQUIC_HDR_ERR_DUPLICATE_PSDO_HDR,
37    FR_ERR_INCOMPL_REQ_PSEH   =  LSQUIC_HDR_ERR_INCOMPL_REQ_PSDO_HDR,
38    FR_ERR_UNNEC_REQ_PSEH     =  LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR,
39    FR_ERR_INCOMPL_RESP_PSEH  =  LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR,
40    FR_ERR_UNNEC_RESP_PSEH    =  LSQUIC_HDR_ERR_UNNEC_RESP_PSDO_HDR,
41    FR_ERR_UNKNOWN_PSEH       =  LSQUIC_HDR_ERR_UNKNOWN_PSDO_HDR,
42    FR_ERR_UPPERCASE_HEADER   =  LSQUIC_HDR_ERR_UPPERCASE_HEADER,
43    FR_ERR_MISPLACED_PSEH     =  LSQUIC_HDR_ERR_MISPLACED_PSDO_HDR,
44    FR_ERR_MISSING_PSEH       =  LSQUIC_HDR_ERR_MISSING_PSDO_HDR,
45    FR_ERR_HEADERS_TOO_LARGE  =  LSQUIC_HDR_ERR_HEADERS_TOO_LARGE,
46    FR_ERR_NOMEM              =  LSQUIC_HDR_ERR_NOMEM,
47
48    FR_ERR_DECOMPRESS,
49    FR_ERR_INVALID_FRAME_SIZE,  /* E.g. a SETTINGS frame length is not a multiple
50                                 * of 6 (RFC 7540, Section 6.5.1).
51                                 */
52    FR_ERR_NONZERO_STREAM_ID,
53    FR_ERR_ZERO_STREAM_ID,
54    FR_ERR_SELF_DEP_STREAM,     /* A stream in priority frame cannot depend on
55                                 * itself (RFC 7540, Section 5.3.1).
56                                 */
57    FR_ERR_UNEXPECTED_PUSH,
58    FR_ERR_EXPECTED_CONTIN,     /* Expected continuation frame. */
59};
60
61
62struct frame_reader_callbacks
63{
64    void (*frc_on_headers)      (void *frame_cb_ctx, struct uncompressed_headers *);
65    void (*frc_on_push_promise) (void *frame_cb_ctx, struct uncompressed_headers *);
66    void (*frc_on_settings)     (void *frame_cb_ctx, uint16_t setting_id,
67                                 uint32_t setting_value);
68    void (*frc_on_priority)     (void *frame_cb_ctx, uint32_t stream_id,
69                                 int exclusive, uint32_t dep_stream_id,
70                                 unsigned weight);
71    void (*frc_on_error)        (void *frame_cb_ctx, uint32_t stream_id,
72                                 enum frame_reader_error);
73};
74
75typedef ssize_t (*fr_stream_read_f)(struct lsquic_stream *, void *, size_t);
76
77struct lsquic_frame_reader *
78lsquic_frame_reader_new (enum frame_reader_flags, unsigned max_headers_sz,
79                         struct lsquic_mm *, struct lsquic_stream *,
80                         fr_stream_read_f, struct lshpack_dec *,
81                         const struct frame_reader_callbacks *, void *fr_cb_ctx,
82                         const struct lsquic_hset_if *, void *hsi_ctx);
83
84int
85lsquic_frame_reader_read (struct lsquic_frame_reader *);
86
87void
88lsquic_frame_reader_destroy (struct lsquic_frame_reader *);
89
90size_t
91lsquic_frame_reader_mem_used (const struct lsquic_frame_reader *);
92
93#endif
94