libwebsockets
Lightweight C library for HTML5 websockets
Loading...
Searching...
No Matches
lws-qpack.h
Go to the documentation of this file.
1/*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2026 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25#ifndef _LWS_QPACK_H
26#define _LWS_QPACK_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#define LWS_QPACK_IGNORE_ENTRY 0xff
33
40
53
54/* TX Encoder structures */
56 char *name;
57 char *value;
60 uint16_t hdr_len; /* 32 + name_len + value_len */
61 uint32_t insert_index; /* Absolute insert index */
62};
63
77
82
94
98
99 uint64_t ric;
100 uint64_t base;
101 uint64_t int_val;
103
105 uint8_t is_name; /* 1 if currently parsing name, 0 for value */
108 uint8_t huff_pad; /* bits consumed since the last complete symbol */
109 uint8_t huff_pad_zero; /* a 0 bit was seen in those (not valid padding) */
110
111 uint64_t str_len;
112 uint64_t str_pos;
113
114 /*
115 * the index a field line or insert refers to, as sent: it is checked
116 * against the table it is for before it is used, so it may not be
117 * narrowed first, or a huge index can alias a small one
118 */
119 uint64_t hdr_idx;
120 /* the largest absolute dynamic index the field section used, plus 1 */
121 uint64_t ref_top;
122 uint8_t base_sign; /* the S bit of a Delta Base sent as a long int */
123 /*
124 * how much of its input lws_qpack_decode_header_block() took before
125 * it returned LWS_QPACK_DEC_BLOCKED
126 */
127 size_t used;
128 char name_buf[128];
129 size_t name_pos;
130 char val_buf[4096];
131 size_t val_pos;
132 uint8_t skip; /* this field's name or value is too big to keep */
133};
134
135/*
136 * The name_idx a header block's field line is reported with when its name or
137 * value is too big for the decoder to keep (name_buf / val_buf): name and
138 * value are NULL. The field line was consumed, so the rest of the block
139 * still decodes; what to do about the field is the callback's decision.
140 */
141#define LWS_QPACK_FIELD_TOO_LARGE (-2)
142
143typedef int (*lws_qpack_header_cb)(void *user, int name_idx, const char *name, size_t name_len, const char *value, size_t value_len);
144
147
150 struct lws_qpack_context *ctx,
151 const unsigned char *in, size_t in_len);
152
153/*
154 * lws_qpack_decode_header_block() returns this when the section's prefix
155 * requires inserts the table doesn't have yet (RFC 9204 2.1.2). It took
156 * state->used bytes of its input, up to the end of the prefix: call it again
157 * with the rest once the encoder stream has brought the table up to
158 * state->ric. Like any nonzero return, it is not a decoded section.
159 */
160#define LWS_QPACK_DEC_BLOCKED 2
161
164 struct lws_qpack_context *ctx,
165 const unsigned char *in, size_t in_len,
166 lws_qpack_header_cb cb, void *user);
167
168/*
169 * lws_qpack_decode_header_block_done() - the field section is all decoded
170 *
171 * \param state: the stream state lws_qpack_decode_header_block() decoded with
172 *
173 * Call it when the whole of the field section has been through
174 * lws_qpack_decode_header_block(). It returns nonzero, a
175 * QPACK_DECOMPRESSION_FAILED, if the section ended part way through its
176 * prefix or a field line, or if it declared a Required Insert Count it did
177 * not need (RFC 9204 4.5.1.1).
178 */
181
183lws_qpack_find_static_index(int lws_hdr_idx, const char *value, int value_len);
184
186lws_qpack_get_static_token(int index, int *lws_hdr_idx, const char **value);
187
189lws_qpack_encode_static(unsigned char *buf, size_t buf_len, int index);
190
192lws_qpack_encode_int(unsigned char *buf, size_t buf_len, uint64_t val,
193 uint8_t prefix_bits, uint8_t prefix_mask);
194
196lws_qpack_encode_string(unsigned char *buf, size_t buf_len, const char *str, size_t len);
197
199lws_qpack_encode_prefix(unsigned char *buf, size_t buf_len, uint64_t ric, uint64_t base, uint64_t max_entries);
200
202lws_qpack_encode_literal_with_name_ref(unsigned char *buf, size_t buf_len, int index, const char *val, size_t val_len);
203
205lws_qpack_encode_literal_with_literal_name(unsigned char *buf, size_t buf_len, const char *name, size_t name_len, const char *val, size_t val_len);
206
207/* TX Encoder Stream Instructions */
209lws_qpack_tx_encode_insert_name_ref(unsigned char *buf, size_t buf_len, int is_static, int index, const char *val, size_t val_len);
210
212lws_qpack_tx_encode_insert_literal(unsigned char *buf, size_t buf_len, const char *name, size_t name_len, const char *val, size_t val_len);
213
215lws_qpack_tx_encode_set_capacity(unsigned char *buf, size_t buf_len, uint32_t capacity);
216
219
221lws_qpack_tx_encode_dynamic_index(unsigned char *buf, size_t buf_len, uint32_t insert_index, uint32_t base);
222
224lws_qpack_tx_encode_dynamic_name_ref(unsigned char *buf, size_t buf_len, uint32_t insert_index, uint32_t base, const char *val, size_t val_len);
225
226LWS_VISIBLE LWS_EXTERN struct lws *
227lws_create_h3_dummy_wsi(struct lws_context *ctx, struct lws_qpack_tx_encoder *tx_enc);
228
231
234
237
240
242lws_add_http3_header_by_name(struct lws *wsi, const unsigned char *name,
243 const unsigned char *value, int length,
244 unsigned char **p, unsigned char *end);
245
248 const unsigned char *value, int length,
249 unsigned char **p, unsigned char *end);
250
252lws_add_http3_header_status(struct lws *wsi, unsigned int code,
253 unsigned char **p, unsigned char *end);
254
255#ifdef __cplusplus
256}
257#endif
258
259#endif
lws_token_indexes
Definition lws-http.h:244
unsigned short uint16_t
unsigned int uint32_t
#define LWS_EXTERN
unsigned char uint8_t
#define LWS_VISIBLE
LWS_VISIBLE LWS_EXTERN int lws_qpack_encode_literal_with_literal_name(unsigned char *buf, size_t buf_len, const char *name, size_t name_len, const char *val, size_t val_len)
LWS_VISIBLE LWS_EXTERN void lws_qpack_set_wsi_base_and_ric(struct lws *wsi, uint32_t base, uint32_t ric)
LWS_VISIBLE LWS_EXTERN struct lws * lws_create_h3_dummy_wsi(struct lws_context *ctx, struct lws_qpack_tx_encoder *tx_enc)
LWS_VISIBLE LWS_EXTERN int lws_qpack_huftable_decode(int pos, char c)
LWS_VISIBLE LWS_EXTERN int lws_add_http3_header_by_name(struct lws *wsi, const unsigned char *name, const unsigned char *value, int length, unsigned char **p, unsigned char *end)
LWS_VISIBLE LWS_EXTERN int lws_qpack_get_static_token(int index, int *lws_hdr_idx, const char **value)
struct lws_buflist * tx_bl
Definition lws-qpack.h:74
LWS_VISIBLE LWS_EXTERN int lws_qpack_tx_encode_insert_name_ref(unsigned char *buf, size_t buf_len, int is_static, int index, const char *val, size_t val_len)
struct lws * wsi_qpack_enc
Definition lws-qpack.h:75
LWS_VISIBLE LWS_EXTERN int lws_qpack_encode_int(unsigned char *buf, size_t buf_len, uint64_t val, uint8_t prefix_bits, uint8_t prefix_mask)
uint32_t insert_count
Definition lws-qpack.h:68
uint32_t virtual_payload_usage
Definition lws-qpack.h:43
LWS_VISIBLE LWS_EXTERN int lws_qpack_find_static_index(int lws_hdr_idx, const char *value, int value_len)
LWS_VISIBLE LWS_EXTERN int lws_add_http3_header_by_token(struct lws *wsi, enum lws_token_indexes token, const unsigned char *value, int length, unsigned char **p, unsigned char *end)
LWS_VISIBLE LWS_EXTERN void lws_qpack_tx_encoder_destroy(struct lws_qpack_tx_encoder *enc)
LWS_VISIBLE LWS_EXTERN int lws_qpack_encode_literal_with_name_ref(unsigned char *buf, size_t buf_len, int index, const char *val, size_t val_len)
LWS_VISIBLE LWS_EXTERN int lws_qpack_decode_header_block(struct lws_qpack_stream_state *state, struct lws_qpack_context *ctx, const unsigned char *in, size_t in_len, lws_qpack_header_cb cb, void *user)
LWS_VISIBLE LWS_EXTERN int lws_qpack_tx_encode_dynamic_name_ref(unsigned char *buf, size_t buf_len, uint32_t insert_index, uint32_t base, const char *val, size_t val_len)
LWS_VISIBLE LWS_EXTERN int lws_qpack_decode_encoder_stream(struct lws_qpack_stream_state *state, struct lws_qpack_context *ctx, const unsigned char *in, size_t in_len)
LWS_VISIBLE LWS_EXTERN int lws_qpack_tx_encode_set_capacity(unsigned char *buf, size_t buf_len, uint32_t capacity)
LWS_VISIBLE LWS_EXTERN int lws_qpack_encode_string(unsigned char *buf, size_t buf_len, const char *str, size_t len)
LWS_VISIBLE LWS_EXTERN int lws_qpack_encode_static(unsigned char *buf, size_t buf_len, int index)
struct lws_qpack_dynamic_table_entry * entries
Definition lws-qpack.h:42
LWS_VISIBLE LWS_EXTERN int lws_qpack_tx_encode_dynamic_index(unsigned char *buf, size_t buf_len, uint32_t insert_index, uint32_t base)
LWS_VISIBLE LWS_EXTERN int lws_qpack_dynamic_size(struct lws_qpack_context *ctx, int size)
uint32_t virtual_payload_max
Definition lws-qpack.h:67
struct lws_qpack_tx_table_entry * entries
Definition lws-qpack.h:65
int(* lws_qpack_header_cb)(void *user, int name_idx, const char *name, size_t name_len, const char *value, size_t value_len)
Definition lws-qpack.h:143
uint32_t known_received_count
Definition lws-qpack.h:47
uint32_t known_received_count
Definition lws-qpack.h:69
uint16_t used_entries
Definition lws-qpack.h:71
uint32_t virtual_payload_usage
Definition lws-qpack.h:66
LWS_VISIBLE LWS_EXTERN int lws_qpack_decode_header_block_done(const struct lws_qpack_stream_state *state)
enum lws_qpack_dec_state next_state
Definition lws-qpack.h:97
LWS_VISIBLE LWS_EXTERN int lws_qpack_encode_prefix(unsigned char *buf, size_t buf_len, uint64_t ric, uint64_t base, uint64_t max_entries)
lws_qpack_dec_state
Definition lws-qpack.h:83
@ LQP_DEC_PREFIX_BASE
Definition lws-qpack.h:85
@ LQP_DEC_EMIT
Definition lws-qpack.h:92
@ LQP_DEC_STR_DATA
Definition lws-qpack.h:89
@ LQP_DEC_STR_DATA_HUFF
Definition lws-qpack.h:90
@ LQP_DEC_PREFIX_RIC
Definition lws-qpack.h:84
@ LQP_DEC_INSTRUCTION
Definition lws-qpack.h:86
@ LQP_DEC_STR_LEN
Definition lws-qpack.h:88
@ LQP_DEC_WAIT_STR_LEN
Definition lws-qpack.h:91
@ LQP_DEC_INT
Definition lws-qpack.h:87
enum lws_qpack_dec_state state
Definition lws-qpack.h:96
LWS_VISIBLE LWS_EXTERN int lws_qpack_tx_encode_insert_literal(unsigned char *buf, size_t buf_len, const char *name, size_t name_len, const char *val, size_t val_len)
uint32_t virtual_payload_limit
Definition lws-qpack.h:45
LWS_VISIBLE LWS_EXTERN void lws_destroy_h3_dummy_wsi(struct lws *wsi)
LWS_VISIBLE LWS_EXTERN void lws_qpack_destroy_dynamic_header(struct lws_qpack_context *ctx)
struct lws_qpack_dynamic_table dyn_table
Definition lws-qpack.h:79
LWS_VISIBLE LWS_EXTERN int lws_add_http3_header_status(struct lws *wsi, unsigned int code, unsigned char **p, unsigned char *end)
uint32_t virtual_payload_max
Definition lws-qpack.h:44
Definition lws-qpack.h:34
Definition lws-qpack.h:55