xref: /lighttpd1.4/src/h2.h (revision 9a3f6c52)
1 #ifndef LI_H2_H
2 #define LI_H2_H
3 #include "first.h"
4 
5 #include "sys-time.h"
6 
7 #include "base_decls.h"
8 #include "buffer.h"
9 
10 #include "ls-hpack/lshpack.h"
11 
12 struct chunkqueue;      /* declaration */
13 
14 typedef enum {
15     H2_FTYPE_DATA                = 0x00
16    ,H2_FTYPE_HEADERS             = 0x01
17    ,H2_FTYPE_PRIORITY            = 0x02
18    ,H2_FTYPE_RST_STREAM          = 0x03
19    ,H2_FTYPE_SETTINGS            = 0x04
20    ,H2_FTYPE_PUSH_PROMISE        = 0x05
21    ,H2_FTYPE_PING                = 0x06
22    ,H2_FTYPE_GOAWAY              = 0x07
23    ,H2_FTYPE_WINDOW_UPDATE       = 0x08
24    ,H2_FTYPE_CONTINUATION        = 0x09
25    ,H2_FTYPE_PRIORITY_UPDATE     = 0x10
26 } request_h2ftype_t;
27 
28 typedef enum {
29     H2_SETTINGS_HEADER_TABLE_SIZE          = 0x01
30    ,H2_SETTINGS_ENABLE_PUSH                = 0x02
31    ,H2_SETTINGS_MAX_CONCURRENT_STREAMS     = 0x03
32    ,H2_SETTINGS_INITIAL_WINDOW_SIZE        = 0x04
33    ,H2_SETTINGS_MAX_FRAME_SIZE             = 0x05
34    ,H2_SETTINGS_MAX_HEADER_LIST_SIZE       = 0x06
35    ,H2_SETTINGS_ENABLE_CONNECT_PROTOCOL    = 0x08
36    ,H2_SETTINGS_NO_RFC7540_PRIORITIES      = 0x09
37 } request_h2settings_t;
38 
39 typedef enum {
40     H2_FLAG_END_STREAM  = 0x01   /* DATA HEADERS */
41    ,H2_FLAG_END_HEADERS = 0x04   /*      HEADERS PUSH_PROMISE CONTINUATION */
42    ,H2_FLAG_PADDED      = 0x08   /* DATA HEADERS PUSH_PROMISE */
43    ,H2_FLAG_PRIORITY    = 0x20   /*      HEADERS */
44    ,H2_FLAG_ACK         = 0x01   /* PING SETTINGS*/
45 } request_h2flag_t;
46 
47 typedef enum {
48     H2_E_NO_ERROR            = 0x00
49    ,H2_E_PROTOCOL_ERROR      = 0x01
50    ,H2_E_INTERNAL_ERROR      = 0x02
51    ,H2_E_FLOW_CONTROL_ERROR  = 0x03
52    ,H2_E_SETTINGS_TIMEOUT    = 0x04
53    ,H2_E_STREAM_CLOSED       = 0x05
54    ,H2_E_FRAME_SIZE_ERROR    = 0x06
55    ,H2_E_REFUSED_STREAM      = 0x07
56    ,H2_E_CANCEL              = 0x08
57    ,H2_E_COMPRESSION_ERROR   = 0x09
58    ,H2_E_CONNECT_ERROR       = 0x0a
59    ,H2_E_ENHANCE_YOUR_CALM   = 0x0b
60    ,H2_E_INADEQUATE_SECURITY = 0x0c
61    ,H2_E_HTTP_1_1_REQUIRED   = 0x0d
62 } request_h2error_t;
63 
64 typedef enum {
65     H2_STATE_IDLE,
66     H2_STATE_RESERVED_LOCAL,
67     H2_STATE_RESERVED_REMOTE,
68     H2_STATE_OPEN,
69     H2_STATE_HALF_CLOSED_LOCAL,
70     H2_STATE_HALF_CLOSED_REMOTE,
71     H2_STATE_CLOSED
72 } request_h2state_t;
73 
74 struct h2con {
75     request_st *r[8];
76     uint32_t rused;
77 
78     uint32_t h2_cid;
79     uint32_t h2_sid;
80      int32_t sent_goaway;
81     unix_time64_t sent_settings;
82     uint32_t s_header_table_size;      /* SETTINGS_HEADER_TABLE_SIZE      */
83     uint32_t s_enable_push;            /* SETTINGS_ENABLE_PUSH            */
84     uint32_t s_max_concurrent_streams; /* SETTINGS_MAX_CONCURRENT_STREAMS */
85      int32_t s_initial_window_size;    /* SETTINGS_INITIAL_WINDOW_SIZE    */
86     uint32_t s_max_frame_size;         /* SETTINGS_MAX_FRAME_SIZE         */
87     uint32_t s_max_header_list_size;   /* SETTINGS_MAX_HEADER_LIST_SIZE   */
88     struct lshpack_dec decoder;
89     struct lshpack_enc encoder;
90     unix_time64_t half_closed_ts;
91 };
92 
93 void h2_send_goaway (connection *con, request_h2error_t e);
94 
95 int h2_parse_frames (connection *con);
96 
97 int h2_want_read (connection *con);
98 
99 void h2_init_con (request_st * restrict h2r, connection * restrict con, const buffer * restrict http2_settings);
100 
101 int h2_send_1xx (request_st *r, connection *con);
102 
103 void h2_send_100_continue (request_st *r, connection *con);
104 
105 void h2_send_headers (request_st *r, connection *con);
106 
107 uint32_t h2_send_cqdata (request_st *r, connection *con, struct chunkqueue *cq, uint32_t dlen);
108 
109 void h2_send_end_stream (request_st *r, connection *con);
110 
111 void h2_retire_stream (request_st *r, connection *con);
112 
113 void h2_retire_con (request_st *h2r, connection *con);
114 
115 __attribute_cold__
116 __attribute_noinline__
117 int h2_check_con_upgrade_h2c (request_st *r);
118 
119 #endif
120