VLC  4.0.0-dev
h2frame.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * h2frame.h: HTTP/2 frame formatting
3  *****************************************************************************
4  * Copyright (C) 2015 RĂ©mi Denis-Courmont
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19  *****************************************************************************/
20 
21 #include <stdbool.h>
22 #include <stdint.h>
23 
24 /**
25  * \defgroup h2_frames HTTP/2 frames
26  * \ingroup h2
27  * @{
28  */
29 
31 {
32  struct vlc_h2_frame *next;
33  uint8_t data[];
34 };
35 
36 size_t vlc_h2_frame_size(const struct vlc_h2_frame *);
37 
38 struct vlc_h2_frame *
39 vlc_h2_frame_headers(uint_fast32_t stream_id, uint_fast32_t mtu, bool eos,
40  unsigned count, const char *const headers[][2]);
41 struct vlc_h2_frame *
42 vlc_h2_frame_data(uint_fast32_t stream_id, const void *buf, size_t len,
43  bool eos);
44 struct vlc_h2_frame *
45 vlc_h2_frame_rst_stream(uint_fast32_t stream_id, uint_fast32_t error_code);
48 struct vlc_h2_frame *vlc_h2_frame_ping(uint64_t opaque);
49 struct vlc_h2_frame *vlc_h2_frame_pong(uint64_t opaque);
50 struct vlc_h2_frame *
51 vlc_h2_frame_goaway(uint_fast32_t last_stream_id, uint_fast32_t error_code);
52 struct vlc_h2_frame *
53 vlc_h2_frame_window_update(uint_fast32_t stream_id, uint_fast32_t credit);
54 
55 void vlc_h2_frame_dump(void *, const struct vlc_h2_frame *, const char *);
56 
72 };
73 
74 const char *vlc_h2_strerror(uint_fast32_t);
75 
83 };
84 
85 const char *vlc_h2_setting_name(uint_fast16_t);
86 
87 /* Our settings */
88 #define VLC_H2_MAX_HEADER_TABLE 4096 /* Header (compression) table size */
89 #define VLC_H2_MAX_STREAMS 0 /* Concurrent peer-initiated streams */
90 #define VLC_H2_INIT_WINDOW 1048575 /* Initial congestion window size */
91 #define VLC_H2_MAX_FRAME 1048576 /* Frame size */
92 #define VLC_H2_MAX_HEADER_LIST 65536 /* Header (decompressed) list size */
93 
94 /* Protocol default settings */
95 #define VLC_H2_DEFAULT_MAX_HEADER_TABLE 4096
96 #define VLC_H2_DEFAULT_INIT_WINDOW 65535
97 #define VLC_H2_DEFAULT_MAX_FRAME 16384
98 
99 struct vlc_h2_parser;
101 {
102  void (*setting)(void *ctx, uint_fast16_t id, uint_fast32_t value);
103  int (*settings_done)(void *ctx);
104  int (*ping)(void *ctx, uint_fast64_t opaque);
105  void (*error)(void *ctx, uint_fast32_t code);
106  int (*reset)(void *ctx, uint_fast32_t last_seq, uint_fast32_t code);
107  void (*window_status)(void *ctx, uint32_t *rcwd);
108  void (*window_update)(void *ctx, uint_fast32_t credit);
109 
110  void *(*stream_lookup)(void *ctx, uint_fast32_t id);
111  int (*stream_error)(void *ctx, uint_fast32_t id, uint_fast32_t code);
112  void (*stream_headers)(void *ctx, unsigned count,
113  const char *const headers[][2]);
114  int (*stream_data)(void *ctx, struct vlc_h2_frame *f);
115  void (*stream_end)(void *ctx);
116  int (*stream_reset)(void *ctx, uint_fast32_t code);
117  void (*stream_window_update)(void *ctx, uint_fast32_t credit);
118 };
119 
120 struct vlc_h2_parser *vlc_h2_parse_init(void *ctx,
121  const struct vlc_h2_parser_cbs *cbs);
122 int vlc_h2_parse(struct vlc_h2_parser *, struct vlc_h2_frame *);
123 void vlc_h2_parse_destroy(struct vlc_h2_parser *);
124 
125 #define VLC_H2_MAX_HEADERS 255
126 
127 const uint8_t *vlc_h2_frame_data_get(const struct vlc_h2_frame *f,
128  size_t *restrict len);
129 #define vlc_h2_frame_data_get(f, l) \
130  _Generic((f), \
131  const struct vlc_h2_frame *: (vlc_h2_frame_data_get)(f, l), \
132  struct vlc_h2_frame *: (uint8_t *)(vlc_h2_frame_data_get)(f, l))
133 
134 /** @} */
struct vlc_h2_parser * vlc_h2_parse_init(void *ctx, const struct vlc_h2_parser_cbs *cbs)
Definition: h2frame.c:1032
uint8_t data[]
Definition: h2frame.h:33
Definition: h2frame.h:58
size_t vlc_h2_frame_size(const struct vlc_h2_frame *)
Definition: h2frame.c:72
void vlc_h2_parse_destroy(struct vlc_h2_parser *)
Definition: h2frame.c:1055
struct vlc_h2_frame * vlc_h2_frame_ping(uint64_t opaque)
Definition: h2frame.c:336
Definition: h2frame.h:71
Definition: h2frame.h:66
Definition: h2frame.h:64
Definition: h2frame.h:60
const char * vlc_h2_strerror(uint_fast32_t)
Definition: h2frame.c:383
Definition: h2frame.h:81
const struct vlc_h2_parser_cbs * cbs
Definition: h2frame.c:452
struct vlc_h2_frame * vlc_h2_frame_settings_ack(void)
Definition: h2frame.c:313
size_t len
Definition: h2frame.c:460
Definition: h2frame.h:67
const char * vlc_h2_setting_name(uint_fast16_t)
Definition: h2frame.c:319
struct vlc_h2_frame * vlc_h2_frame_data(uint_fast32_t stream_id, const void *buf, size_t len, bool eos)
Definition: h2frame.c:228
struct vlc_h2_frame * vlc_h2_frame_goaway(uint_fast32_t last_stream_id, uint_fast32_t error_code)
Definition: h2frame.c:354
Definition: h2frame.h:80
struct vlc_h2_frame * vlc_h2_frame_pong(uint64_t opaque)
Definition: h2frame.c:344
int vlc_h2_parse(struct vlc_h2_parser *, struct vlc_h2_frame *)
Definition: h2frame.c:1012
Definition: h2frame.h:70
Definition: h2frame.h:68
void vlc_h2_frame_dump(void *, const struct vlc_h2_frame *, const char *)
Definition: h2frame.c:407
Definition: h2frame.h:82
Definition: h2frame.h:77
vlc_h2_error
Definition: h2frame.h:57
size_t count
Definition: core.c:402
HTTP/2 incoming frames parser.
Definition: h2frame.c:449
struct vlc_h2_frame * vlc_h2_frame_rst_stream(uint_fast32_t stream_id, uint_fast32_t error_code)
Definition: h2frame.c:241
Definition: h2frame.h:61
vlc_h2_setting
Definition: h2frame.h:76
Definition: h2frame.h:62
#define vlc_h2_frame_data_get(f, l)
Definition: h2frame.h:129
Definition: h2frame.h:100
struct vlc_h2_frame * vlc_h2_frame_headers(uint_fast32_t stream_id, uint_fast32_t mtu, bool eos, unsigned count, const char *const headers[][2])
Definition: h2frame.c:155
struct vlc_h2_frame * next
Definition: h2frame.h:32
Definition: h2frame.h:78
struct vlc_h2_frame * vlc_h2_frame_settings(void)
Definition: h2frame.c:250
struct vlc_h2_frame * vlc_h2_frame_window_update(uint_fast32_t stream_id, uint_fast32_t credit)
Definition: h2frame.c:368
Definition: h2frame.h:63
Definition: h2frame.h:30
Definition: h2frame.h:65
Definition: h2frame.h:69
Definition: h2frame.h:59