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
115 char name_buf[128];
116 size_t name_pos;
117 char val_buf[4096];
118 size_t val_pos;
119};
120
121typedef int (*lws_qpack_header_cb)(void *user, int name_idx, const char *name, size_t name_len, const char *value, size_t value_len);
122
125
128 struct lws_qpack_context *ctx,
129 const unsigned char *in, size_t in_len);
130
133 struct lws_qpack_context *ctx,
134 const unsigned char *in, size_t in_len,
135 lws_qpack_header_cb cb, void *user);
136
138lws_qpack_find_static_index(int lws_hdr_idx, const char *value, int value_len);
139
141lws_qpack_get_static_token(int index, int *lws_hdr_idx, const char **value);
142
144lws_qpack_encode_static(unsigned char *buf, size_t buf_len, int index);
145
147lws_qpack_encode_int(unsigned char *buf, size_t buf_len, uint64_t val,
148 uint8_t prefix_bits, uint8_t prefix_mask);
149
151lws_qpack_encode_string(unsigned char *buf, size_t buf_len, const char *str, size_t len);
152
154lws_qpack_encode_prefix(unsigned char *buf, size_t buf_len, uint64_t ric, uint64_t base, uint64_t max_entries);
155
157lws_qpack_encode_literal_with_name_ref(unsigned char *buf, size_t buf_len, int index, const char *val, size_t val_len);
158
160lws_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);
161
162/* TX Encoder Stream Instructions */
164lws_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);
165
167lws_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);
168
170lws_qpack_tx_encode_set_capacity(unsigned char *buf, size_t buf_len, uint32_t capacity);
171
174
176lws_qpack_tx_encode_dynamic_index(unsigned char *buf, size_t buf_len, uint32_t insert_index, uint32_t base);
177
179lws_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);
180
181LWS_VISIBLE LWS_EXTERN struct lws *
182lws_create_h3_dummy_wsi(struct lws_context *ctx, struct lws_qpack_tx_encoder *tx_enc);
183
186
189
192
195
197lws_add_http3_header_by_name(struct lws *wsi, const unsigned char *name,
198 const unsigned char *value, int length,
199 unsigned char **p, unsigned char *end);
200
203 const unsigned char *value, int length,
204 unsigned char **p, unsigned char *end);
205
207lws_add_http3_header_status(struct lws *wsi, unsigned int code,
208 unsigned char **p, unsigned char *end);
209
210#ifdef __cplusplus
211}
212#endif
213
214#endif
lws_token_indexes
Definition lws-http.h:233
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:121
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
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