mirror of
https://gitea.invidious.io/iv-org/litespeed-quic.git
synced 2024-08-15 00:53:43 +00:00
Release 2.13.0
- [API] Use lsxpack_header structure to process incoming headers. - [BUGFIX] Fix assertion when zero-padding Initial packet. - [BUGFIX] Use idle timeout before we learn of peer's value. - Use ls-hpack 2.0.0 -- has lsxpack_header changes. - Use ls-qpack 0.14.0 -- new, common with ls-hpack, XXH seed (not used yet). - Code cleanup: prefix exported functions with "lsquic_".
This commit is contained in:
parent
5289ebd2fd
commit
a5fa05f958
77 changed files with 1168 additions and 73475 deletions
|
@ -24,7 +24,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define LSQUIC_MAJOR_VERSION 2
|
||||
#define LSQUIC_MINOR_VERSION 12
|
||||
#define LSQUIC_MINOR_VERSION 13
|
||||
#define LSQUIC_PATCH_VERSION 0
|
||||
|
||||
/**
|
||||
|
@ -862,39 +862,6 @@ typedef void (*lsquic_cids_update_f)(void *ctx, void **peer_ctx,
|
|||
|
||||
struct stack_st_X509;
|
||||
|
||||
/**
|
||||
* When headers are processed, various errors may occur. They are listed
|
||||
* in this enum.
|
||||
*/
|
||||
enum lsquic_header_status
|
||||
{
|
||||
LSQUIC_HDR_OK,
|
||||
/** Duplicate pseudo-header */
|
||||
LSQUIC_HDR_ERR_DUPLICATE_PSDO_HDR,
|
||||
/** Not all request pseudo-headers are present */
|
||||
LSQUIC_HDR_ERR_INCOMPL_REQ_PSDO_HDR,
|
||||
/** Unnecessary request pseudo-header present in the response */
|
||||
LSQUIC_HDR_ERR_UNNEC_REQ_PSDO_HDR,
|
||||
/** Prohibited header in request */
|
||||
LSQUIC_HDR_ERR_BAD_REQ_HEADER,
|
||||
/** Not all response pseudo-headers are present */
|
||||
LSQUIC_HDR_ERR_INCOMPL_RESP_PSDO_HDR,
|
||||
/** Unnecessary response pseudo-header present in the response. */
|
||||
LSQUIC_HDR_ERR_UNNEC_RESP_PSDO_HDR,
|
||||
/** Unknown pseudo-header */
|
||||
LSQUIC_HDR_ERR_UNKNOWN_PSDO_HDR,
|
||||
/** Uppercase letter in header */
|
||||
LSQUIC_HDR_ERR_UPPERCASE_HEADER,
|
||||
/** Misplaced pseudo-header */
|
||||
LSQUIC_HDR_ERR_MISPLACED_PSDO_HDR,
|
||||
/** Missing pseudo-header */
|
||||
LSQUIC_HDR_ERR_MISSING_PSDO_HDR,
|
||||
/** Header or headers are too large */
|
||||
LSQUIC_HDR_ERR_HEADERS_TOO_LARGE,
|
||||
/** Cannot allocate any more memory. */
|
||||
LSQUIC_HDR_ERR_NOMEM,
|
||||
};
|
||||
|
||||
struct lsquic_hset_if
|
||||
{
|
||||
/**
|
||||
|
@ -905,27 +872,35 @@ struct lsquic_hset_if
|
|||
void * (*hsi_create_header_set)(void *hsi_ctx,
|
||||
int is_push_promise);
|
||||
/**
|
||||
* Process new header. Return 0 on success, -1 if there is a problem with
|
||||
* the header. -1 is treated as a stream error: the associated stream is
|
||||
* reset.
|
||||
* Return a header set prepared for decoding. If `hdr' is NULL, this
|
||||
* means return a new structure with at least `space' bytes available
|
||||
* in the decoder buffer. If `hdr' is not NULL, it means there was not
|
||||
* enough decoder buffer and it must be increased by `space' bytes.
|
||||
*
|
||||
* If NULL is returned the header set is discarded.
|
||||
*/
|
||||
struct lsxpack_header *
|
||||
(*hsi_prepare_decode)(void *hdr_set,
|
||||
struct lsxpack_header *hdr,
|
||||
size_t space);
|
||||
/**
|
||||
* Process new header. Return 0 on success, a positive value if a header
|
||||
* error occured, or a negative value on any other error.
|
||||
*
|
||||
* A positive return value will result in cancellation of associated
|
||||
* stream.
|
||||
*
|
||||
* A negative return value will result in connection being aborted.
|
||||
*
|
||||
* `hdr_set' is the header set object returned by
|
||||
* @ref hsi_create_header_set().
|
||||
*
|
||||
* `name_idx' is set to the index in either the HPACK or QPACK static table
|
||||
* whose entry's name element matches `name'. The values are as follows:
|
||||
* - if there is no such match, `name_idx' is set to zero;
|
||||
* - if HPACK is used, the value is between 1 and 61; and
|
||||
* - if QPACK is used, the value is 62+ (subtract 62 to get the QPACK
|
||||
* static table index).
|
||||
* `hdr' is the header returned by @ref `hsi_prepare_decode'.
|
||||
*
|
||||
* If `name' is NULL, this means that no more header are going to be
|
||||
* If `hdr' is NULL, this means that no more header are going to be
|
||||
* added to the set.
|
||||
*/
|
||||
enum lsquic_header_status (*hsi_process_header)(void *hdr_set,
|
||||
unsigned name_idx,
|
||||
const char *name, unsigned name_len,
|
||||
const char *value, unsigned value_len);
|
||||
int (*hsi_process_header)(void *hdr_set, struct lsxpack_header *hdr);
|
||||
/**
|
||||
* Discard header set. This is called for unclaimed header sets and
|
||||
* header sets that had an error.
|
||||
|
|
165
include/lsxpack_header.h
Normal file
165
include/lsxpack_header.h
Normal file
|
@ -0,0 +1,165 @@
|
|||
/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */
|
||||
#ifndef LSXPACK_HEADER_H_v203
|
||||
#define LSXPACK_HEADER_H_v203
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef LSXPACK_MAX_STRLEN
|
||||
#define LSXPACK_MAX_STRLEN UINT16_MAX
|
||||
#endif
|
||||
|
||||
#if LSXPACK_MAX_STRLEN == UINT16_MAX
|
||||
typedef uint16_t lsxpack_strlen_t;
|
||||
#elif LSXPACK_MAX_STRLEN == UINT32_MAX
|
||||
typedef uint32_t lsxpack_strlen_t;
|
||||
#else
|
||||
#error unexpected LSXPACK_MAX_STRLEN
|
||||
#endif
|
||||
|
||||
enum lsxpack_flag
|
||||
{
|
||||
LSXPACK_HPACK_IDX = 1,
|
||||
LSXPACK_QPACK_IDX = 2,
|
||||
LSXPACK_APP_IDX = 4,
|
||||
LSXPACK_NAME_HASH = 8,
|
||||
LSXPACK_NAMEVAL_HASH = 16,
|
||||
LSXPACK_VAL_MATCHED = 32,
|
||||
LSXPACK_NEVER_INDEX = 64,
|
||||
};
|
||||
|
||||
/**
|
||||
* When header are decoded, it should be stored to @buf starting from @name_offset,
|
||||
* <name>: <value>\r\n
|
||||
* So, it can be used directly as HTTP/1.1 header. there are 4 extra characters
|
||||
* added.
|
||||
*
|
||||
* limitation: we currently does not support total header size > 64KB.
|
||||
*/
|
||||
|
||||
struct lsxpack_header
|
||||
{
|
||||
char *buf; /* the buffer for headers */
|
||||
const char *name_ptr; /* the name pointer can be optionally set for encoding */
|
||||
uint32_t name_hash; /* hash value for name */
|
||||
uint32_t nameval_hash; /* hash value for name + value */
|
||||
lsxpack_strlen_t name_offset; /* the offset for name in the buffer */
|
||||
lsxpack_strlen_t name_len; /* the length of name */
|
||||
lsxpack_strlen_t val_offset; /* the offset for value in the buffer */
|
||||
lsxpack_strlen_t val_len; /* the length of value */
|
||||
uint8_t hpack_index; /* HPACK static table index */
|
||||
uint8_t qpack_index; /* QPACK static table index */
|
||||
uint8_t app_index; /* APP header index */
|
||||
enum lsxpack_flag flags:8; /* combination of lsxpack_flag */
|
||||
uint8_t indexed_type; /* control to disable index or not */
|
||||
uint8_t dec_overhead; /* num of extra bytes written to decoded buffer */
|
||||
};
|
||||
|
||||
typedef struct lsxpack_header lsxpack_header_t;
|
||||
|
||||
|
||||
static inline void
|
||||
lsxpack_header_set_idx(lsxpack_header_t *hdr, int hpack_idx,
|
||||
const char *val, size_t val_len)
|
||||
{
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->buf = (char *)val;
|
||||
hdr->hpack_index = hpack_idx;
|
||||
assert(hpack_idx != 0);
|
||||
hdr->flags = LSXPACK_HPACK_IDX;
|
||||
assert(val_len <= LSXPACK_MAX_STRLEN);
|
||||
hdr->val_len = val_len;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
lsxpack_header_set_ptr(lsxpack_header_t *hdr,
|
||||
const char *name, size_t name_len,
|
||||
const char *val, size_t val_len)
|
||||
{
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->buf = (char *)val;
|
||||
assert(val_len <= LSXPACK_MAX_STRLEN);
|
||||
hdr->val_len = val_len;
|
||||
hdr->name_ptr = name;
|
||||
assert(name_len <= LSXPACK_MAX_STRLEN);
|
||||
hdr->name_len = name_len;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
lsxpack_header_set_offset(lsxpack_header_t *hdr, const char *buf,
|
||||
size_t name_offset, size_t name_len,
|
||||
size_t val_len)
|
||||
{
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->buf = (char *)buf;
|
||||
hdr->name_offset = name_offset;
|
||||
assert(name_len <= LSXPACK_MAX_STRLEN);
|
||||
hdr->name_len = name_len;
|
||||
assert(name_offset + name_len + 2 <= LSXPACK_MAX_STRLEN);
|
||||
hdr->val_offset = name_offset + name_len + 2;
|
||||
assert(val_len <= LSXPACK_MAX_STRLEN);
|
||||
hdr->val_len = val_len;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
lsxpack_header_set_offset2(lsxpack_header_t *hdr, const char *buf,
|
||||
size_t name_offset, size_t name_len,
|
||||
size_t val_offset, size_t val_len)
|
||||
{
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->buf = (char *)buf;
|
||||
hdr->name_offset = name_offset;
|
||||
assert(name_len <= LSXPACK_MAX_STRLEN);
|
||||
hdr->name_len = name_len;
|
||||
assert(val_offset <= LSXPACK_MAX_STRLEN);
|
||||
hdr->val_offset = val_offset;
|
||||
assert(val_len <= LSXPACK_MAX_STRLEN);
|
||||
hdr->val_len = val_len;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
lsxpack_header_prepare_decode(lsxpack_header_t *hdr,
|
||||
char *out, size_t offset, size_t len)
|
||||
{
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->buf = out;
|
||||
assert(offset <= LSXPACK_MAX_STRLEN);
|
||||
hdr->name_offset = offset;
|
||||
if (len > LSXPACK_MAX_STRLEN)
|
||||
hdr->val_len = LSXPACK_MAX_STRLEN;
|
||||
else
|
||||
hdr->val_len = len;
|
||||
}
|
||||
|
||||
|
||||
static inline const char *
|
||||
lsxpack_header_get_name(const lsxpack_header_t *hdr)
|
||||
{
|
||||
return hdr->name_ptr ? hdr->name_ptr
|
||||
: (hdr->name_len) ? hdr->buf + hdr->name_offset
|
||||
: NULL;
|
||||
}
|
||||
|
||||
|
||||
static inline const char *
|
||||
lsxpack_header_get_value(const lsxpack_header_t *hdr)
|
||||
{ return hdr->buf + hdr->val_offset; }
|
||||
|
||||
static inline size_t
|
||||
lsxpack_header_get_dec_size(const lsxpack_header_t *hdr)
|
||||
{ return hdr->name_len + hdr->val_len + hdr->dec_overhead; }
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //LSXPACK_HEADER_H_v203
|
Loading…
Add table
Add a link
Reference in a new issue