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
52
53/* TX Encoder structures */
55 char *name;
56 char *value;
59 uint16_t hdr_len; /* 32 + name_len + value_len */
60 uint32_t insert_index; /* Absolute insert index */
61};
62
76
81
93
97
98 uint64_t ric;
99 uint64_t base;
100 uint64_t int_val;
102
104 uint8_t is_name; /* 1 if currently parsing name, 0 for value */
107
108 uint64_t str_len;
109 uint64_t str_pos;
110
112 char name_buf[128];
113 size_t name_pos;
114 char val_buf[4096];
115 size_t val_pos;
116};
117
118typedef int (*lws_qpack_header_cb)(void *user, int name_idx, const char *name, size_t name_len, const char *value, size_t value_len);
119
122
125 struct lws_qpack_context *ctx,
126 const unsigned char *in, size_t in_len);
127
130 struct lws_qpack_context *ctx,
131 const unsigned char *in, size_t in_len,
132 lws_qpack_header_cb cb, void *user);
133
135lws_qpack_find_static_index(int lws_hdr_idx, const char *value, int value_len);
136
138lws_qpack_get_static_token(int index, int *lws_hdr_idx, const char **value);
139
141lws_qpack_encode_static(unsigned char *buf, size_t buf_len, int index);
142
144lws_qpack_encode_int(unsigned char *buf, size_t buf_len, uint64_t val,
145 uint8_t prefix_bits, uint8_t prefix_mask);
146
148lws_qpack_encode_string(unsigned char *buf, size_t buf_len, const char *str, size_t len);
149
151lws_qpack_encode_prefix(unsigned char *buf, size_t buf_len, uint64_t ric, uint64_t base, uint64_t max_entries);
152
154lws_qpack_encode_literal_with_name_ref(unsigned char *buf, size_t buf_len, int index, const char *val, size_t val_len);
155
157lws_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);
158
159/* TX Encoder Stream Instructions */
161lws_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);
162
164lws_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);
165
167lws_qpack_tx_encode_set_capacity(unsigned char *buf, size_t buf_len, uint32_t capacity);
168
171
173lws_qpack_tx_encode_dynamic_index(unsigned char *buf, size_t buf_len, uint32_t insert_index, uint32_t base);
174
176lws_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);
177
178LWS_VISIBLE LWS_EXTERN struct lws *
179lws_create_h3_dummy_wsi(struct lws_context *ctx, struct lws_qpack_tx_encoder *tx_enc);
180
183
186
189
192
194lws_add_http3_header_by_name(struct lws *wsi, const unsigned char *name,
195 const unsigned char *value, int length,
196 unsigned char **p, unsigned char *end);
197
200 const unsigned char *value, int length,
201 unsigned char **p, unsigned char *end);
202
204lws_add_http3_header_status(struct lws *wsi, unsigned int code,
205 unsigned char **p, unsigned char *end);
206
207#ifdef __cplusplus
208}
209#endif
210
211#endif
lws_token_indexes
Definition lws-http.h:229
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:73
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:74
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:67
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:66
struct lws_qpack_tx_table_entry * entries
Definition lws-qpack.h:64
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:118
uint32_t known_received_count
Definition lws-qpack.h:47
uint32_t known_received_count
Definition lws-qpack.h:68
uint16_t used_entries
Definition lws-qpack.h:70
uint32_t virtual_payload_usage
Definition lws-qpack.h:65
enum lws_qpack_dec_state next_state
Definition lws-qpack.h:96
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:82
@ LQP_DEC_PREFIX_BASE
Definition lws-qpack.h:84
@ LQP_DEC_EMIT
Definition lws-qpack.h:91
@ LQP_DEC_STR_DATA
Definition lws-qpack.h:88
@ LQP_DEC_STR_DATA_HUFF
Definition lws-qpack.h:89
@ LQP_DEC_PREFIX_RIC
Definition lws-qpack.h:83
@ LQP_DEC_INSTRUCTION
Definition lws-qpack.h:85
@ LQP_DEC_STR_LEN
Definition lws-qpack.h:87
@ LQP_DEC_WAIT_STR_LEN
Definition lws-qpack.h:90
@ LQP_DEC_INT
Definition lws-qpack.h:86
enum lws_qpack_dec_state state
Definition lws-qpack.h:95
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:78
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:54