lsquic_hq.h revision 5392f7a3
1/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_hq.h -- HTTP over QUIC (HQ) types
4 */
5
6#ifndef LSQUIC_HQ_H
7#define LSQUIC_HQ_H 1
8
9/* [draft-ietf-quic-http-15] Section 4 */
10enum hq_frame_type
11{
12    HQFT_DATA           = 0,
13    HQFT_HEADERS        = 1,
14    HQFT_PRIORITY       = 2,
15    HQFT_CANCEL_PUSH    = 3,
16    HQFT_SETTINGS       = 4,
17    HQFT_PUSH_PROMISE   = 5,
18    HQFT_GOAWAY         = 7,
19    HQFT_MAX_PUSH_ID    = 0xD,
20    HQFT_DUPLICATE_PUSH = 0xE,
21    /* This frame is made up and its type is never written to stream.
22     * Nevertheless, just to be on the safe side, give it a value as
23     * described in [draft-ietf-quic-http-20] Section 4.2.10.
24     */
25    HQFT_PUSH_PREAMBLE  = 0x1F * 3 + 0x21,
26};
27
28
29enum h3_prio_el_type
30{
31    H3PET_REQ_STREAM    = 0,
32    H3PET_PUSH_STREAM   = 1,
33    H3PET_PLACEHOLDER   = 2,
34    H3PET_CUR_STREAM    = 3,
35};
36
37
38enum h3_dep_el_type
39{
40    H3DET_REQ_STREAM    = 0,
41    H3DET_PUSH_STREAM   = 1,
42    H3DET_PLACEHOLDER   = 2,
43    H3DET_ROOT          = 3,
44};
45
46
47#define HQ_PT_SHIFT 6
48#define HQ_DT_SHIFT 4
49
50
51enum hq_setting_id
52{
53    HQSID_QPACK_MAX_TABLE_CAPACITY  = 1,
54    HQSID_MAX_HEADER_LIST_SIZE      = 6,
55    HQSID_QPACK_BLOCKED_STREAMS     = 7,
56    HQSID_NUM_PLACEHOLDERS          = 9,
57};
58
59/* As of 12/18/2018: */
60#define HQ_DF_QPACK_MAX_TABLE_CAPACITY 0
61#define HQ_DF_NUM_PLACEHOLDERS 0
62#define HQ_DF_MAX_HEADER_LIST_SIZE 0
63#define HQ_DF_QPACK_BLOCKED_STREAMS 0
64
65struct hq_priority
66{
67    lsquic_stream_id_t      hqp_prio_id;
68    lsquic_stream_id_t      hqp_dep_id;
69    enum h3_prio_el_type    hqp_prio_type:8;
70    enum h3_dep_el_type     hqp_dep_type:8;
71    uint8_t                 hqp_weight;
72};
73
74#define HQP_WEIGHT(p) ((p)->hqp_weight + 1)
75
76/* [draft-ietf-quic-http-19] Section 10.6,
77 * [draft-ietf-quic-qpack-07] Section 8.2
78 */
79enum hq_uni_stream_type
80{
81    HQUST_CONTROL   = 0,
82    HQUST_PUSH      = 1,
83    HQUST_QPACK_ENC = 2,
84    HQUST_QPACK_DEC = 3,
85};
86
87extern const char *const lsquic_h3det2str[];
88extern const char *const lsquic_h3pet2str[];
89
90/* [draft-ietf-quic-http-22] Section 8.1 and
91 * [draft-ietf-quic-qpack-08], Section 8.3
92 */
93enum http_error_code
94{
95    HEC_NO_ERROR                 =  0x00,
96    HEC_GENERAL_PROTOCOL_ERROR   =  0x01,
97    /* Error code 0x2 is reserved and has no meaning */
98    HEC_INTERNAL_ERROR           =  0x03,
99    /* Error code 0x4 is reserved and has no meaning */
100    HEC_REQUEST_CANCELLED        =  0x05,
101    HEC_INCOMPLETE_REQUEST       =  0x06,
102    HEC_CONNECT_ERROR            =  0x07,
103    HEC_EXCESSIVE_LOAD           =  0x08,
104    HEC_VERSION_FALLBACK         =  0x09,
105    HEC_WRONG_STREAM             =  0x0A,
106    HEC_ID_ERROR                 =  0x0B,
107    /* Error code 0xC is reserved and has no meaning */
108    HEC_STREAM_CREATION_ERROR    =  0x0D,
109    /* Error code 0xE is reserved and has no meaning */
110    HEC_CLOSED_CRITICAL_STREAM   =  0x0F,
111    /* Error code 0x10 is reserved and has no meaning */
112    HEC_EARLY_RESPONSE           =  0x0011,
113    HEC_MISSING_SETTINGS         =  0x0012,
114    HEC_UNEXPECTED_FRAME         =  0x0013,
115    HEC_REQUEST_REJECTED         =  0x14,
116    HEC_SETTINGS_ERROR           =  0x00FF,
117    HEC_MALFORMED_FRAME          =  0x0100,    /* add frame type */
118    HEC_QPACK_DECOMPRESSION_FAILED  = 0x200,
119    HEC_QPACK_ENCODER_STREAM_ERROR  = 0x201,
120    HEC_QPACK_DECODER_STREAM_ERROR  = 0x202,
121};
122
123
124struct h3_prio_frame_read_state
125{
126    struct varint_read_state    h3pfrs_vint;
127    struct hq_priority          h3pfrs_prio;
128    enum {
129        H3PFRS_STATE_TYPE = 0,
130        H3PFRS_STATE_VINT_BEGIN,
131        H3PFRS_STATE_VINT_CONTINUE,
132        H3PFRS_STATE_WEIGHT,
133    }                           h3pfrs_state;
134    enum {
135        H3PFRS_FLAG_HAVE_PRIO_ID = 1 << 0,
136    }                           h3pfrs_flags;
137};
138
139
140enum h3_prio_frame_read_status
141{
142    H3PFR_STATUS_DONE,
143    H3PFR_STATUS_NEED,
144};
145
146
147/* When first called, h3pfrs_state should be set to 0 */
148enum h3_prio_frame_read_status
149lsquic_h3_prio_frame_read (const unsigned char **, size_t,
150                                            struct h3_prio_frame_read_state *);
151
152#endif
153