Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,46 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2016 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_VERSION_H
#define NGHTTP3_VERSION_H
/**
* @macro
*
* Version number of the nghttp3 library release.
*/
#define NGHTTP3_VERSION "1.6.0"
/**
* @macro
*
* Numerical representation of the version number of the nghttp3
* library release. This is a 24 bit number with 8 bits for major
* number, 8 bits for minor and 8 bits for patch. Version 1.2.3
* becomes 0x010203.
*/
#define NGHTTP3_VERSION_NUM 0x010600
#endif /* !defined(NGHTTP3_VERSION_H) */

View File

@ -0,0 +1,91 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_balloc.h"
#include <assert.h>
#include "nghttp3_mem.h"
void nghttp3_balloc_init(nghttp3_balloc *balloc, size_t blklen,
const nghttp3_mem *mem) {
assert((blklen & 0xfu) == 0);
balloc->mem = mem;
balloc->blklen = blklen;
balloc->head = NULL;
nghttp3_buf_wrap_init(&balloc->buf, (void *)"", 0);
}
void nghttp3_balloc_free(nghttp3_balloc *balloc) {
if (balloc == NULL) {
return;
}
nghttp3_balloc_clear(balloc);
}
void nghttp3_balloc_clear(nghttp3_balloc *balloc) {
nghttp3_memblock_hd *p, *next;
for (p = balloc->head; p; p = next) {
next = p->next;
nghttp3_mem_free(balloc->mem, p);
}
balloc->head = NULL;
nghttp3_buf_wrap_init(&balloc->buf, (void *)"", 0);
}
int nghttp3_balloc_get(nghttp3_balloc *balloc, void **pbuf, size_t n) {
uint8_t *p;
nghttp3_memblock_hd *hd;
assert(n <= balloc->blklen);
if (nghttp3_buf_left(&balloc->buf) < n) {
p = nghttp3_mem_malloc(balloc->mem,
sizeof(nghttp3_memblock_hd) + 0x8u + balloc->blklen);
if (p == NULL) {
return NGHTTP3_ERR_NOMEM;
}
hd = (nghttp3_memblock_hd *)(void *)p;
hd->next = balloc->head;
balloc->head = hd;
nghttp3_buf_wrap_init(
&balloc->buf,
(uint8_t *)(((uintptr_t)p + sizeof(nghttp3_memblock_hd) + 0xfu) &
~(uintptr_t)0xfu),
balloc->blklen);
}
assert(((uintptr_t)balloc->buf.last & 0xfu) == 0);
*pbuf = balloc->buf.last;
balloc->buf.last += (n + 0xfu) & ~(uintptr_t)0xfu;
return 0;
}

View File

@ -0,0 +1,95 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_BALLOC_H
#define NGHTTP3_BALLOC_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_buf.h"
typedef struct nghttp3_memblock_hd nghttp3_memblock_hd;
/*
* nghttp3_memblock_hd is the header of memory block.
*/
struct nghttp3_memblock_hd {
union {
nghttp3_memblock_hd *next;
uint64_t pad;
};
};
/*
* nghttp3_balloc is a custom memory allocator. It allocates |blklen|
* bytes of memory at once on demand, and returns its slice when the
* allocation is requested.
*/
typedef struct nghttp3_balloc {
/* mem is the underlying memory allocator. */
const nghttp3_mem *mem;
/* blklen is the size of memory block. */
size_t blklen;
/* head points to the list of memory block allocated so far. */
nghttp3_memblock_hd *head;
/* buf wraps the current memory block for allocation requests. */
nghttp3_buf buf;
} nghttp3_balloc;
/*
* nghttp3_balloc_init initializes |balloc| with |blklen| which is the
* size of memory block.
*/
void nghttp3_balloc_init(nghttp3_balloc *balloc, size_t blklen,
const nghttp3_mem *mem);
/*
* nghttp3_balloc_free releases all allocated memory blocks.
*/
void nghttp3_balloc_free(nghttp3_balloc *balloc);
/*
* nghttp3_balloc_get allocates |n| bytes of memory and assigns its
* pointer to |*pbuf|.
*
* It returns 0 if it succeeds, or one of the following negative error
* codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_balloc_get(nghttp3_balloc *balloc, void **pbuf, size_t n);
/*
* nghttp3_balloc_clear releases all allocated memory blocks and
* initializes its state.
*/
void nghttp3_balloc_clear(nghttp3_balloc *balloc);
#endif /* !defined(NGHTTP3_BALLOC_H) */

90
deps/ngtcp2/nghttp3/lib/nghttp3_buf.c vendored Normal file
View File

@ -0,0 +1,90 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_buf.h"
void nghttp3_buf_init(nghttp3_buf *buf) {
buf->begin = buf->end = buf->pos = buf->last = NULL;
}
void nghttp3_buf_wrap_init(nghttp3_buf *buf, uint8_t *src, size_t len) {
buf->begin = buf->pos = buf->last = src;
buf->end = buf->begin + len;
}
void nghttp3_buf_free(nghttp3_buf *buf, const nghttp3_mem *mem) {
nghttp3_mem_free(mem, buf->begin);
}
size_t nghttp3_buf_left(const nghttp3_buf *buf) {
return (size_t)(buf->end - buf->last);
}
size_t nghttp3_buf_len(const nghttp3_buf *buf) {
return (size_t)(buf->last - buf->pos);
}
size_t nghttp3_buf_cap(const nghttp3_buf *buf) {
return (size_t)(buf->end - buf->begin);
}
void nghttp3_buf_reset(nghttp3_buf *buf) { buf->pos = buf->last = buf->begin; }
int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem) {
uint8_t *p;
nghttp3_ssize pos_offset, last_offset;
if ((size_t)(buf->end - buf->begin) >= size) {
return 0;
}
pos_offset = buf->pos - buf->begin;
last_offset = buf->last - buf->begin;
p = nghttp3_mem_realloc(mem, buf->begin, size);
if (p == NULL) {
return NGHTTP3_ERR_NOMEM;
}
buf->begin = p;
buf->end = p + size;
buf->pos = p + pos_offset;
buf->last = p + last_offset;
return 0;
}
void nghttp3_buf_swap(nghttp3_buf *a, nghttp3_buf *b) {
nghttp3_buf c = *a;
*a = *b;
*b = c;
}
void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf,
nghttp3_buf_type type) {
tbuf->buf = *buf;
tbuf->type = type;
}

74
deps/ngtcp2/nghttp3/lib/nghttp3_buf.h vendored Normal file
View File

@ -0,0 +1,74 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_BUF_H
#define NGHTTP3_BUF_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_mem.h"
void nghttp3_buf_wrap_init(nghttp3_buf *buf, uint8_t *src, size_t len);
/*
* nghttp3_buf_cap returns the capacity of the buffer. In other
* words, it returns buf->end - buf->begin.
*/
size_t nghttp3_buf_cap(const nghttp3_buf *buf);
int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem);
/*
* nghttp3_buf_swap swaps |a| and |b|.
*/
void nghttp3_buf_swap(nghttp3_buf *a, nghttp3_buf *b);
typedef enum nghttp3_buf_type {
/* NGHTTP3_BUF_TYPE_PRIVATE indicates that memory is allocated for
this buffer only and should be freed after its use. */
NGHTTP3_BUF_TYPE_PRIVATE,
/* NGHTTP3_BUF_TYPE_SHARED indicates that buffer points to shared
memory. */
NGHTTP3_BUF_TYPE_SHARED,
/* NGHTTP3_BUF_TYPE_ALIEN indicates that the buffer points to a
memory which comes from outside of the library. */
NGHTTP3_BUF_TYPE_ALIEN,
} nghttp3_buf_type;
typedef struct nghttp3_typed_buf {
nghttp3_buf buf;
nghttp3_buf_type type;
} nghttp3_typed_buf;
void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf,
nghttp3_buf_type type);
void nghttp3_typed_buf_free(nghttp3_typed_buf *tbuf);
#endif /* !defined(NGHTTP3_BUF_H) */

2638
deps/ngtcp2/nghttp3/lib/nghttp3_conn.c vendored Normal file

File diff suppressed because it is too large Load Diff

207
deps/ngtcp2/nghttp3/lib/nghttp3_conn.h vendored Normal file
View File

@ -0,0 +1,207 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_CONN_H
#define NGHTTP3_CONN_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_stream.h"
#include "nghttp3_map.h"
#include "nghttp3_qpack.h"
#include "nghttp3_tnode.h"
#include "nghttp3_idtr.h"
#include "nghttp3_gaptr.h"
#define NGHTTP3_VARINT_MAX ((1ull << 62) - 1)
/* NGHTTP3_QPACK_ENCODER_MAX_TABLE_CAPACITY is the maximum dynamic
table size for QPACK encoder. */
#define NGHTTP3_QPACK_ENCODER_MAX_TABLE_CAPACITY 16384
/* NGHTTP3_QPACK_ENCODER_MAX_BLOCK_STREAMS is the maximum number of
blocked streams for QPACK encoder. */
#define NGHTTP3_QPACK_ENCODER_MAX_BLOCK_STREAMS 100
/* NGHTTP3_CONN_FLAG_NONE indicates that no flag is set. */
#define NGHTTP3_CONN_FLAG_NONE 0x0000u
/* NGHTTP3_CONN_FLAG_SETTINGS_RECVED is set when SETTINGS frame has
been received. */
#define NGHTTP3_CONN_FLAG_SETTINGS_RECVED 0x0001u
/* NGHTTP3_CONN_FLAG_CONTROL_OPENED is set when a control stream has
opened. */
#define NGHTTP3_CONN_FLAG_CONTROL_OPENED 0x0002u
/* NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED is set when a QPACK encoder
stream has opened. */
#define NGHTTP3_CONN_FLAG_QPACK_ENCODER_OPENED 0x0004u
/* NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED is set when a QPACK decoder
stream has opened. */
#define NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED 0x0008u
/* NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED is set when graceful shutdown
has started. */
#define NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED 0x0010u
/* NGHTTP3_CONN_FLAG_GOAWAY_RECVED indicates that GOAWAY frame has
received. */
#define NGHTTP3_CONN_FLAG_GOAWAY_RECVED 0x0020u
/* NGHTTP3_CONN_FLAG_GOAWAY_QUEUED indicates that GOAWAY frame has
been submitted for transmission. */
#define NGHTTP3_CONN_FLAG_GOAWAY_QUEUED 0x0040u
typedef struct nghttp3_chunk {
nghttp3_opl_entry oplent;
} nghttp3_chunk;
nghttp3_objalloc_decl(chunk, nghttp3_chunk, oplent);
struct nghttp3_conn {
nghttp3_objalloc out_chunk_objalloc;
nghttp3_objalloc stream_objalloc;
nghttp3_callbacks callbacks;
nghttp3_map streams;
nghttp3_qpack_decoder qdec;
nghttp3_qpack_encoder qenc;
nghttp3_pq qpack_blocked_streams;
struct {
nghttp3_pq spq;
} sched[NGHTTP3_URGENCY_LEVELS];
const nghttp3_mem *mem;
void *user_data;
int server;
uint16_t flags;
struct {
nghttp3_settings settings;
struct {
/* max_pushes is the number of push IDs that local endpoint can
issue. This field is used by server only and used just for
validation */
uint64_t max_pushes;
} uni;
} local;
struct {
struct {
nghttp3_idtr idtr;
/* max_client_streams is the cumulative number of client
initiated bidirectional stream ID the remote endpoint can
issue. This field is used on server side only. */
uint64_t max_client_streams;
/* num_streams is the number of client initiated bidirectional
streams that are currently open. This field is for server
use only. */
size_t num_streams;
} bidi;
nghttp3_settings settings;
} remote;
struct {
/* goaway_id is the latest ID received in GOAWAY frame. */
int64_t goaway_id;
int64_t max_stream_id_bidi;
/* pri_fieldbuf is a buffer to store incoming Priority Field Value
in PRIORITY_UPDATE frame. */
uint8_t pri_fieldbuf[8];
/* pri_fieldlen is the number of bytes written into
pri_fieldbuf. */
size_t pri_fieldbuflen;
} rx;
struct {
struct {
nghttp3_buf rbuf;
nghttp3_buf ebuf;
} qpack;
nghttp3_stream *ctrl;
nghttp3_stream *qenc;
nghttp3_stream *qdec;
/* goaway_id is the latest ID sent in GOAWAY frame. */
int64_t goaway_id;
} tx;
};
nghttp3_stream *nghttp3_conn_find_stream(nghttp3_conn *conn, int64_t stream_id);
int nghttp3_conn_create_stream(nghttp3_conn *conn, nghttp3_stream **pstream,
int64_t stream_id);
nghttp3_ssize nghttp3_conn_read_bidi(nghttp3_conn *conn, size_t *pnproc,
nghttp3_stream *stream, const uint8_t *src,
size_t srclen, int fin);
nghttp3_ssize nghttp3_conn_read_uni(nghttp3_conn *conn, nghttp3_stream *stream,
const uint8_t *src, size_t srclen, int fin);
nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn,
nghttp3_stream *stream,
const uint8_t *src, size_t srclen);
nghttp3_ssize nghttp3_conn_read_qpack_encoder(nghttp3_conn *conn,
const uint8_t *src,
size_t srclen);
nghttp3_ssize nghttp3_conn_read_qpack_decoder(nghttp3_conn *conn,
const uint8_t *src,
size_t srclen);
int nghttp3_conn_on_data(nghttp3_conn *conn, nghttp3_stream *stream,
const uint8_t *data, size_t datalen);
int nghttp3_conn_on_priority_update(nghttp3_conn *conn,
const nghttp3_frame_priority_update *fr);
nghttp3_ssize nghttp3_conn_on_headers(nghttp3_conn *conn,
nghttp3_stream *stream,
const uint8_t *data, size_t datalen,
int fin);
int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn,
const nghttp3_frame_settings *fr);
int nghttp3_conn_qpack_blocked_streams_push(nghttp3_conn *conn,
nghttp3_stream *stream);
void nghttp3_conn_qpack_blocked_streams_pop(nghttp3_conn *conn);
int nghttp3_conn_schedule_stream(nghttp3_conn *conn, nghttp3_stream *stream);
int nghttp3_conn_ensure_stream_scheduled(nghttp3_conn *conn,
nghttp3_stream *stream);
void nghttp3_conn_unschedule_stream(nghttp3_conn *conn, nghttp3_stream *stream);
int nghttp3_conn_reject_stream(nghttp3_conn *conn, nghttp3_stream *stream);
/*
* nghttp3_conn_get_next_tx_stream returns next stream to send. It
* returns NULL if there is no such stream.
*/
nghttp3_stream *nghttp3_conn_get_next_tx_stream(nghttp3_conn *conn);
#endif /* !defined(NGHTTP3_CONN_H) */

128
deps/ngtcp2/nghttp3/lib/nghttp3_conv.c vendored Normal file
View File

@ -0,0 +1,128 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_conv.h"
#include <string.h>
#include <assert.h>
#include "nghttp3_str.h"
#include "nghttp3_unreachable.h"
const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p) {
union {
uint8_t n8;
uint16_t n16;
uint32_t n32;
uint64_t n64;
} n;
switch (*p >> 6) {
case 0:
*dest = *p++;
return p;
case 1:
memcpy(&n, p, 2);
n.n8 &= 0x3f;
*dest = ntohs(n.n16);
return p + 2;
case 2:
memcpy(&n, p, 4);
n.n8 &= 0x3f;
*dest = ntohl(n.n32);
return p + 4;
case 3:
memcpy(&n, p, 8);
n.n8 &= 0x3f;
*dest = (int64_t)nghttp3_ntohl64(n.n64);
return p + 8;
default:
nghttp3_unreachable();
}
}
int64_t nghttp3_get_varint_fb(const uint8_t *p) { return *p & 0x3f; }
size_t nghttp3_get_varintlen(const uint8_t *p) {
return (size_t)(1u << (*p >> 6));
}
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n) {
n = nghttp3_htonl64(n);
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
}
uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n) {
n = htonl(n);
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
}
uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n) {
n = htons(n);
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
}
uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n) {
uint8_t *rv;
if (n < 64) {
*p++ = (uint8_t)n;
return p;
}
if (n < 16384) {
rv = nghttp3_put_uint16be(p, (uint16_t)n);
*p |= 0x40;
return rv;
}
if (n < 1073741824) {
rv = nghttp3_put_uint32be(p, (uint32_t)n);
*p |= 0x80;
return rv;
}
assert(n < 4611686018427387904LL);
rv = nghttp3_put_uint64be(p, (uint64_t)n);
*p |= 0xc0;
return rv;
}
size_t nghttp3_put_varintlen(int64_t n) {
if (n < 64) {
return 1;
}
if (n < 16384) {
return 2;
}
if (n < 1073741824) {
return 4;
}
assert(n < 4611686018427387904LL);
return 8;
}
uint64_t nghttp3_ord_stream_id(int64_t stream_id) {
return (uint64_t)(stream_id >> 2) + 1;
}

194
deps/ngtcp2/nghttp3/lib/nghttp3_conv.h vendored Normal file
View File

@ -0,0 +1,194 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_CONV_H
#define NGHTTP3_CONV_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif /* defined(HAVE_ARPA_INET_H) */
#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif /* defined(HAVE_NETINET_IN_H) */
#ifdef HAVE_BYTESWAP_H
# include <byteswap.h>
#endif /* defined(HAVE_BYTESWAP_H) */
#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif /* defined(HAVE_ENDIAN_H) */
#ifdef HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif /* defined(HAVE_SYS_ENDIAN_H) */
#ifdef __APPLE__
# include <libkern/OSByteOrder.h>
#endif /* defined(__APPLE__) */
#include <nghttp3/nghttp3.h>
#if HAVE_DECL_BE64TOH
# define nghttp3_ntohl64(N) be64toh(N)
# define nghttp3_htonl64(N) htobe64(N)
#else /* !HAVE_DECL_BE64TOH */
# ifdef WORDS_BIGENDIAN
# define nghttp3_ntohl64(N) (N)
# define nghttp3_htonl64(N) (N)
# else /* !defined(WORDS_BIGENDIAN) */
# if HAVE_DECL_BSWAP_64
# define nghttp3_bswap64 bswap_64
# elif defined(WIN32)
# define nghttp3_bswap64 _byteswap_uint64
# elif defined(__APPLE__)
# define nghttp3_bswap64 OSSwapInt64
# else /* !(HAVE_DECL_BSWAP_64 || defined(WIN32) || defined(__APPLE__)) */
# define nghttp3_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
# endif /* !(HAVE_DECL_BSWAP_64 || defined(WIN32) || defined(__APPLE__)) */
# define nghttp3_ntohl64(N) nghttp3_bswap64(N)
# define nghttp3_htonl64(N) nghttp3_bswap64(N)
# endif /* !defined(WORDS_BIGENDIAN) */
#endif /* !HAVE_DECL_BE64TOH */
#ifdef WIN32
/* Windows requires ws2_32 library for ntonl family of functions. We
define inline functions for those functions so that we don't have
dependency on that lib. */
# ifdef _MSC_VER
# define STIN static __inline
# else /* !defined(_MSC_VER) */
# define STIN static inline
# endif /* !defined(_MSC_VER) */
STIN uint32_t htonl(uint32_t hostlong) {
uint32_t res;
unsigned char *p = (unsigned char *)&res;
*p++ = (unsigned char)(hostlong >> 24);
*p++ = (hostlong >> 16) & 0xffu;
*p++ = (hostlong >> 8) & 0xffu;
*p = hostlong & 0xffu;
return res;
}
STIN uint16_t htons(uint16_t hostshort) {
uint16_t res;
unsigned char *p = (unsigned char *)&res;
*p++ = (unsigned char)(hostshort >> 8);
*p = hostshort & 0xffu;
return res;
}
STIN uint32_t ntohl(uint32_t netlong) {
uint32_t res;
unsigned char *p = (unsigned char *)&netlong;
res = (uint32_t)(*p++ << 24);
res += (uint32_t)(*p++ << 16);
res += (uint32_t)(*p++ << 8);
res += *p;
return res;
}
STIN uint16_t ntohs(uint16_t netshort) {
uint16_t res;
unsigned char *p = (unsigned char *)&netshort;
res = (uint16_t)(*p++ << 8);
res += *p;
return res;
}
#endif /* defined(WIN32) */
/*
* nghttp3_get_varint reads variable-length unsigned integer from |p|,
* and stores it in the buffer pointed by |dest| in host byte order.
* It returns |p| plus the number of bytes read from |p|.
*/
const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p);
/*
* nghttp3_get_varint_fb reads first byte of encoded variable-length
* integer from |p|.
*/
int64_t nghttp3_get_varint_fb(const uint8_t *p);
/*
* nghttp3_get_varintlen returns the required number of bytes to read
* variable-length integer starting at |p|.
*/
size_t nghttp3_get_varintlen(const uint8_t *p);
/*
* nghttp3_put_uint64be writes |n| in host byte order in |p| in
* network byte order. It returns the one beyond of the last written
* position.
*/
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n);
/*
* nghttp3_put_uint32be writes |n| in host byte order in |p| in
* network byte order. It returns the one beyond of the last written
* position.
*/
uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n);
/*
* nghttp3_put_uint16be writes |n| in host byte order in |p| in
* network byte order. It returns the one beyond of the last written
* position.
*/
uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n);
/*
* nghttp3_put_varint writes |n| in |p| using variable-length integer
* encoding. It returns the one beyond of the last written position.
*/
uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n);
/*
* nghttp3_put_varintlen returns the required number of bytes to
* encode |n|.
*/
size_t nghttp3_put_varintlen(int64_t n);
/*
* nghttp3_ord_stream_id returns the ordinal number of |stream_id|.
*/
uint64_t nghttp3_ord_stream_id(int64_t stream_id);
/*
* NGHTTP3_PRI_INC_MASK is a bit mask to retrieve incremental bit from
* a value produced by nghttp3_pri_to_uint8.
*/
#define NGHTTP3_PRI_INC_MASK (1 << 7)
#endif /* !defined(NGHTTP3_CONV_H) */

61
deps/ngtcp2/nghttp3/lib/nghttp3_debug.c vendored Normal file
View File

@ -0,0 +1,61 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2016 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_debug.h"
#include <stdio.h>
#ifdef DEBUGBUILD
static void nghttp3_default_debug_vfprintf_callback(const char *fmt,
va_list args) {
vfprintf(stderr, fmt, args);
}
static nghttp3_debug_vprintf_callback static_debug_vprintf_callback =
nghttp3_default_debug_vfprintf_callback;
void nghttp3_debug_vprintf(const char *format, ...) {
if (static_debug_vprintf_callback) {
va_list args;
va_start(args, format);
static_debug_vprintf_callback(format, args);
va_end(args);
}
}
void nghttp3_set_debug_vprintf_callback(
nghttp3_debug_vprintf_callback debug_vprintf_callback) {
static_debug_vprintf_callback = debug_vprintf_callback;
}
#else /* !defined(DEBUGBUILD) */
void nghttp3_set_debug_vprintf_callback(
nghttp3_debug_vprintf_callback debug_vprintf_callback) {
(void)debug_vprintf_callback;
}
#endif /* !defined(DEBUGBUILD) */

44
deps/ngtcp2/nghttp3/lib/nghttp3_debug.h vendored Normal file
View File

@ -0,0 +1,44 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2016 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_DEBUG_H
#define NGHTTP3_DEBUG_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#ifdef DEBUGBUILD
# define DEBUGF(...) nghttp3_debug_vprintf(__VA_ARGS__)
void nghttp3_debug_vprintf(const char *format, ...);
#else /* !defined(DEBUGBUILD) */
# define DEBUGF(...) \
do { \
} while (0)
#endif /* !defined(DEBUGBUILD) */
#endif /* !defined(NGHTTP3_DEBUG_H) */

127
deps/ngtcp2/nghttp3/lib/nghttp3_err.c vendored Normal file
View File

@ -0,0 +1,127 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_err.h"
const char *nghttp3_strerror(int liberr) {
switch (liberr) {
case NGHTTP3_ERR_INVALID_ARGUMENT:
return "ERR_INVALID_ARGUMENT";
case NGHTTP3_ERR_INVALID_STATE:
return "ERR_INVALID_STATE";
case NGHTTP3_ERR_WOULDBLOCK:
return "ERR_WOULDBLOCK";
case NGHTTP3_ERR_STREAM_IN_USE:
return "ERR_STREAM_IN_USE";
case NGHTTP3_ERR_MALFORMED_HTTP_HEADER:
return "ERR_MALFORMED_HTTP_HEADER";
case NGHTTP3_ERR_REMOVE_HTTP_HEADER:
return "ERR_REMOVE_HTTP_HEADER";
case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING:
return "ERR_MALFORMED_HTTP_MESSAGING";
case NGHTTP3_ERR_QPACK_FATAL:
return "ERR_QPACK_FATAL";
case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
return "ERR_QPACK_HEADER_TOO_LARGE";
case NGHTTP3_ERR_STREAM_NOT_FOUND:
return "ERR_STREAM_NOT_FOUND";
case NGHTTP3_ERR_CONN_CLOSING:
return "ERR_CONN_CLOSING";
case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
return "ERR_STREAM_DATA_OVERFLOW";
case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED:
return "ERR_QPACK_DECOMPRESSION_FAILED";
case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR:
return "ERR_QPACK_ENCODER_STREAM_ERROR";
case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR:
return "ERR_QPACK_DECODER_STREAM_ERROR";
case NGHTTP3_ERR_H3_FRAME_UNEXPECTED:
return "ERR_H3_FRAME_UNEXPECTED";
case NGHTTP3_ERR_H3_FRAME_ERROR:
return "ERR_H3_FRAME_ERROR";
case NGHTTP3_ERR_H3_MISSING_SETTINGS:
return "ERR_H3_MISSING_SETTINGS";
case NGHTTP3_ERR_H3_INTERNAL_ERROR:
return "ERR_H3_INTERNAL_ERROR";
case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
return "ERR_CLOSED_CRITICAL_STREAM";
case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR:
return "ERR_H3_GENERAL_PROTOCOL_ERROR";
case NGHTTP3_ERR_H3_ID_ERROR:
return "ERR_H3_ID_ERROR";
case NGHTTP3_ERR_H3_SETTINGS_ERROR:
return "ERR_H3_SETTINGS_ERROR";
case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR:
return "ERR_H3_STREAM_CREATION_ERROR";
case NGHTTP3_ERR_NOMEM:
return "ERR_NOMEM";
case NGHTTP3_ERR_CALLBACK_FAILURE:
return "ERR_CALLBACK_FAILURE";
default:
return "(unknown)";
}
}
uint64_t nghttp3_err_infer_quic_app_error_code(int liberr) {
switch (liberr) {
case 0:
return NGHTTP3_H3_NO_ERROR;
case NGHTTP3_ERR_QPACK_DECOMPRESSION_FAILED:
return NGHTTP3_QPACK_DECOMPRESSION_FAILED;
case NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR:
return NGHTTP3_QPACK_ENCODER_STREAM_ERROR;
case NGHTTP3_ERR_QPACK_DECODER_STREAM_ERROR:
return NGHTTP3_QPACK_DECODER_STREAM_ERROR;
case NGHTTP3_ERR_H3_FRAME_UNEXPECTED:
return NGHTTP3_H3_FRAME_UNEXPECTED;
case NGHTTP3_ERR_H3_FRAME_ERROR:
return NGHTTP3_H3_FRAME_ERROR;
case NGHTTP3_ERR_H3_MISSING_SETTINGS:
return NGHTTP3_H3_MISSING_SETTINGS;
case NGHTTP3_ERR_H3_INTERNAL_ERROR:
case NGHTTP3_ERR_NOMEM:
case NGHTTP3_ERR_CALLBACK_FAILURE:
case NGHTTP3_ERR_QPACK_FATAL:
case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
return NGHTTP3_H3_INTERNAL_ERROR;
case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
return NGHTTP3_H3_CLOSED_CRITICAL_STREAM;
case NGHTTP3_ERR_H3_GENERAL_PROTOCOL_ERROR:
return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR;
case NGHTTP3_ERR_H3_ID_ERROR:
return NGHTTP3_H3_ID_ERROR;
case NGHTTP3_ERR_H3_SETTINGS_ERROR:
return NGHTTP3_H3_SETTINGS_ERROR;
case NGHTTP3_ERR_H3_STREAM_CREATION_ERROR:
return NGHTTP3_H3_STREAM_CREATION_ERROR;
case NGHTTP3_ERR_MALFORMED_HTTP_HEADER:
case NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING:
return NGHTTP3_H3_MESSAGE_ERROR;
default:
return NGHTTP3_H3_GENERAL_PROTOCOL_ERROR;
}
}
int nghttp3_err_is_fatal(int liberr) { return liberr < NGHTTP3_ERR_FATAL; }

34
deps/ngtcp2/nghttp3/lib/nghttp3_err.h vendored Normal file
View File

@ -0,0 +1,34 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_ERR_H
#define NGHTTP3_ERR_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#endif /* !defined(NGHTTP3_ERR_H) */

203
deps/ngtcp2/nghttp3/lib/nghttp3_frame.c vendored Normal file
View File

@ -0,0 +1,203 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2013 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_frame.h"
#include <string.h>
#include <assert.h>
#include "nghttp3_conv.h"
#include "nghttp3_str.h"
uint8_t *nghttp3_frame_write_hd(uint8_t *p, const nghttp3_frame_hd *hd) {
p = nghttp3_put_varint(p, hd->type);
p = nghttp3_put_varint(p, hd->length);
return p;
}
size_t nghttp3_frame_write_hd_len(const nghttp3_frame_hd *hd) {
return nghttp3_put_varintlen(hd->type) + nghttp3_put_varintlen(hd->length);
}
uint8_t *nghttp3_frame_write_settings(uint8_t *p,
const nghttp3_frame_settings *fr) {
size_t i;
p = nghttp3_frame_write_hd(p, &fr->hd);
for (i = 0; i < fr->niv; ++i) {
p = nghttp3_put_varint(p, (int64_t)fr->iv[i].id);
p = nghttp3_put_varint(p, (int64_t)fr->iv[i].value);
}
return p;
}
size_t nghttp3_frame_write_settings_len(int64_t *ppayloadlen,
const nghttp3_frame_settings *fr) {
size_t payloadlen = 0;
size_t i;
for (i = 0; i < fr->niv; ++i) {
payloadlen += nghttp3_put_varintlen((int64_t)fr->iv[i].id) +
nghttp3_put_varintlen((int64_t)fr->iv[i].value);
}
*ppayloadlen = (int64_t)payloadlen;
return nghttp3_put_varintlen(NGHTTP3_FRAME_SETTINGS) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
}
uint8_t *nghttp3_frame_write_goaway(uint8_t *p,
const nghttp3_frame_goaway *fr) {
p = nghttp3_frame_write_hd(p, &fr->hd);
p = nghttp3_put_varint(p, fr->id);
return p;
}
size_t nghttp3_frame_write_goaway_len(int64_t *ppayloadlen,
const nghttp3_frame_goaway *fr) {
size_t payloadlen = nghttp3_put_varintlen(fr->id);
*ppayloadlen = (int64_t)payloadlen;
return nghttp3_put_varintlen(NGHTTP3_FRAME_GOAWAY) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
}
uint8_t *
nghttp3_frame_write_priority_update(uint8_t *p,
const nghttp3_frame_priority_update *fr) {
p = nghttp3_frame_write_hd(p, &fr->hd);
p = nghttp3_put_varint(p, fr->pri_elem_id);
if (fr->datalen) {
p = nghttp3_cpymem(p, fr->data, fr->datalen);
}
return p;
}
size_t nghttp3_frame_write_priority_update_len(
int64_t *ppayloadlen, const nghttp3_frame_priority_update *fr) {
size_t payloadlen = nghttp3_put_varintlen(fr->pri_elem_id) + fr->datalen;
*ppayloadlen = (int64_t)payloadlen;
return nghttp3_put_varintlen(fr->hd.type) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
}
int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
const nghttp3_mem *mem) {
size_t i;
uint8_t *data = NULL;
size_t buflen = 0;
nghttp3_nv *p;
if (nvlen == 0) {
*pnva = NULL;
return 0;
}
for (i = 0; i < nvlen; ++i) {
/* + 1 for null-termination */
if ((nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_NAME) == 0) {
buflen += nva[i].namelen + 1;
}
if ((nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_VALUE) == 0) {
buflen += nva[i].valuelen + 1;
}
}
buflen += sizeof(nghttp3_nv) * nvlen;
*pnva = nghttp3_mem_malloc(mem, buflen);
if (*pnva == NULL) {
return NGHTTP3_ERR_NOMEM;
}
p = *pnva;
data = (uint8_t *)(*pnva) + sizeof(nghttp3_nv) * nvlen;
for (i = 0; i < nvlen; ++i) {
p->flags = nva[i].flags;
if (nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_NAME) {
p->name = nva[i].name;
p->namelen = nva[i].namelen;
} else {
if (nva[i].namelen) {
memcpy(data, nva[i].name, nva[i].namelen);
nghttp3_downcase(data, nva[i].namelen);
}
p->name = data;
p->namelen = nva[i].namelen;
data[p->namelen] = '\0';
data += nva[i].namelen + 1;
}
if (nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_VALUE) {
p->value = nva[i].value;
p->valuelen = nva[i].valuelen;
} else {
if (nva[i].valuelen) {
memcpy(data, nva[i].value, nva[i].valuelen);
}
p->value = data;
p->valuelen = nva[i].valuelen;
data[p->valuelen] = '\0';
data += nva[i].valuelen + 1;
}
++p;
}
return 0;
}
void nghttp3_nva_del(nghttp3_nv *nva, const nghttp3_mem *mem) {
nghttp3_mem_free(mem, nva);
}
void nghttp3_frame_headers_free(nghttp3_frame_headers *fr,
const nghttp3_mem *mem) {
if (fr == NULL) {
return;
}
nghttp3_nva_del(fr->nva, mem);
}
void nghttp3_frame_priority_update_free(nghttp3_frame_priority_update *fr,
const nghttp3_mem *mem) {
if (fr == NULL) {
return;
}
nghttp3_mem_free(mem, fr->data);
}

230
deps/ngtcp2/nghttp3/lib/nghttp3_frame.h vendored Normal file
View File

@ -0,0 +1,230 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2013 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_FRAME_H
#define NGHTTP3_FRAME_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_buf.h"
#define NGHTTP3_FRAME_DATA 0x00
#define NGHTTP3_FRAME_HEADERS 0x01
#define NGHTTP3_FRAME_CANCEL_PUSH 0x03
#define NGHTTP3_FRAME_SETTINGS 0x04
#define NGHTTP3_FRAME_PUSH_PROMISE 0x05
#define NGHTTP3_FRAME_GOAWAY 0x07
#define NGHTTP3_FRAME_MAX_PUSH_ID 0x0d
/* PRIORITY_UPDATE: https://datatracker.ietf.org/doc/html/rfc9218 */
#define NGHTTP3_FRAME_PRIORITY_UPDATE 0x0f0700
#define NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID 0x0f0701
/* Frame types that are reserved for HTTP/2, and must not be used in
HTTP/3. */
#define NGHTTP3_H2_FRAME_PRIORITY 0x02
#define NGHTTP3_H2_FRAME_PING 0x06
#define NGHTTP3_H2_FRAME_WINDOW_UPDATE 0x08
#define NGHTTP3_H2_FRAME_CONTINUATION 0x9
typedef struct nghttp3_frame_hd {
int64_t type;
int64_t length;
} nghttp3_frame_hd;
typedef struct nghttp3_frame_data {
nghttp3_frame_hd hd;
} nghttp3_frame_data;
typedef struct nghttp3_frame_headers {
nghttp3_frame_hd hd;
nghttp3_nv *nva;
size_t nvlen;
} nghttp3_frame_headers;
#define NGHTTP3_SETTINGS_ID_MAX_FIELD_SECTION_SIZE 0x06
#define NGHTTP3_SETTINGS_ID_QPACK_MAX_TABLE_CAPACITY 0x01
#define NGHTTP3_SETTINGS_ID_QPACK_BLOCKED_STREAMS 0x07
#define NGHTTP3_SETTINGS_ID_ENABLE_CONNECT_PROTOCOL 0x08
#define NGHTTP3_SETTINGS_ID_H3_DATAGRAM 0x33
#define NGHTTP3_H2_SETTINGS_ID_ENABLE_PUSH 0x2
#define NGHTTP3_H2_SETTINGS_ID_MAX_CONCURRENT_STREAMS 0x3
#define NGHTTP3_H2_SETTINGS_ID_INITIAL_WINDOW_SIZE 0x4
#define NGHTTP3_H2_SETTINGS_ID_MAX_FRAME_SIZE 0x5
typedef struct nghttp3_settings_entry {
uint64_t id;
uint64_t value;
} nghttp3_settings_entry;
typedef struct nghttp3_frame_settings {
nghttp3_frame_hd hd;
size_t niv;
nghttp3_settings_entry iv[1];
} nghttp3_frame_settings;
typedef struct nghttp3_frame_goaway {
nghttp3_frame_hd hd;
int64_t id;
} nghttp3_frame_goaway;
typedef struct nghttp3_frame_priority_update {
nghttp3_frame_hd hd;
/* pri_elem_id is stream ID if hd.type ==
NGHTTP3_FRAME_PRIORITY_UPDATE. It is push ID if hd.type ==
NGHTTP3_FRAME_PRIORITY_UPDATE_PUSH_ID. It is undefined
otherwise. */
int64_t pri_elem_id;
/* When sending this frame, data should point to the buffer
containing a serialized priority field value and its length is
set to datalen. On reception, pri contains the decoded priority
header value. */
union {
nghttp3_pri pri;
struct {
uint8_t *data;
size_t datalen;
};
};
} nghttp3_frame_priority_update;
typedef union nghttp3_frame {
nghttp3_frame_hd hd;
nghttp3_frame_data data;
nghttp3_frame_headers headers;
nghttp3_frame_settings settings;
nghttp3_frame_goaway goaway;
nghttp3_frame_priority_update priority_update;
} nghttp3_frame;
/*
* nghttp3_frame_write_hd writes frame header |hd| to |dest|. This
* function assumes that |dest| has enough space to write |hd|.
*
* This function returns |dest| plus the number of bytes written.
*/
uint8_t *nghttp3_frame_write_hd(uint8_t *dest, const nghttp3_frame_hd *hd);
/*
* nghttp3_frame_write_hd_len returns the number of bytes required to
* write |hd|. hd->length must be set.
*/
size_t nghttp3_frame_write_hd_len(const nghttp3_frame_hd *hd);
/*
* nghttp3_frame_write_settings writes SETTINGS frame |fr| to |dest|.
* This function assumes that |dest| has enough space to write |fr|.
*
* This function returns |dest| plus the number of bytes written.
*/
uint8_t *nghttp3_frame_write_settings(uint8_t *dest,
const nghttp3_frame_settings *fr);
/*
* nghttp3_frame_write_settings_len returns the number of bytes
* required to write |fr|. fr->hd.length is ignored. This function
* stores payload length in |*ppayloadlen|.
*/
size_t nghttp3_frame_write_settings_len(int64_t *pppayloadlen,
const nghttp3_frame_settings *fr);
/*
* nghttp3_frame_write_goaway writes GOAWAY frame |fr| to |dest|.
* This function assumes that |dest| has enough space to write |fr|.
*
* This function returns |dest| plus the number of bytes written.
*/
uint8_t *nghttp3_frame_write_goaway(uint8_t *dest,
const nghttp3_frame_goaway *fr);
/*
* nghttp3_frame_write_goaway_len returns the number of bytes required
* to write |fr|. fr->hd.length is ignored. This function stores
* payload length in |*ppayloadlen|.
*/
size_t nghttp3_frame_write_goaway_len(int64_t *ppayloadlen,
const nghttp3_frame_goaway *fr);
/*
* nghttp3_frame_write_priority_update writes PRIORITY_UPDATE frame
* |fr| to |dest|. This function assumes that |dest| has enough space
* to write |fr|.
*
* This function returns |dest| plus the number of bytes written;
*/
uint8_t *
nghttp3_frame_write_priority_update(uint8_t *dest,
const nghttp3_frame_priority_update *fr);
/*
* nghttp3_frame_write_priority_update_len returns the number of bytes
* required to write |fr|. fr->hd.length is ignored. This function
* stores payload length in |*ppayloadlen|.
*/
size_t nghttp3_frame_write_priority_update_len(
int64_t *ppayloadlen, const nghttp3_frame_priority_update *fr);
/*
* nghttp3_nva_copy copies name/value pairs from |nva|, which contains
* |nvlen| pairs, to |*nva_ptr|, which is dynamically allocated so
* that all items can be stored. The resultant name and value in
* nghttp2_nv are guaranteed to be NULL-terminated even if the input
* is not null-terminated.
*
* The |*pnva| must be freed using nghttp3_nva_del().
*
* This function returns 0 if it succeeds or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
const nghttp3_mem *mem);
/*
* nghttp3_nva_del frees |nva|.
*/
void nghttp3_nva_del(nghttp3_nv *nva, const nghttp3_mem *mem);
/*
* nghttp3_frame_headers_free frees memory allocated for |fr|. It
* assumes that fr->nva is created by nghttp3_nva_copy() or NULL.
*/
void nghttp3_frame_headers_free(nghttp3_frame_headers *fr,
const nghttp3_mem *mem);
/*
* nghttp3_frame_priority_update_free frees memory allocated for |fr|.
* This function should only be called for an outgoing frame.
*/
void nghttp3_frame_priority_update_free(nghttp3_frame_priority_update *fr,
const nghttp3_mem *mem);
#endif /* !defined(NGHTTP3_FRAME_H) */

163
deps/ngtcp2/nghttp3/lib/nghttp3_gaptr.c vendored Normal file
View File

@ -0,0 +1,163 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_gaptr.h"
#include <string.h>
#include <assert.h>
void nghttp3_gaptr_init(nghttp3_gaptr *gaptr, const nghttp3_mem *mem) {
nghttp3_ksl_init(&gaptr->gap, nghttp3_ksl_range_compar, sizeof(nghttp3_range),
mem);
gaptr->mem = mem;
}
static int gaptr_gap_init(nghttp3_gaptr *gaptr) {
nghttp3_range range = {0, UINT64_MAX};
return nghttp3_ksl_insert(&gaptr->gap, NULL, &range, NULL);
}
void nghttp3_gaptr_free(nghttp3_gaptr *gaptr) {
if (gaptr == NULL) {
return;
}
nghttp3_ksl_free(&gaptr->gap);
}
int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset,
uint64_t datalen) {
int rv;
nghttp3_range k, m, l, r, q = {offset, offset + datalen};
nghttp3_ksl_it it;
if (nghttp3_ksl_len(&gaptr->gap) == 0) {
rv = gaptr_gap_init(gaptr);
if (rv != 0) {
return rv;
}
}
it = nghttp3_ksl_lower_bound_compar(&gaptr->gap, &q,
nghttp3_ksl_range_exclusive_compar);
for (; !nghttp3_ksl_it_end(&it);) {
k = *(nghttp3_range *)nghttp3_ksl_it_key(&it);
m = nghttp3_range_intersect(&q, &k);
if (!nghttp3_range_len(&m)) {
break;
}
if (nghttp3_range_eq(&k, &m)) {
nghttp3_ksl_remove_hint(&gaptr->gap, &it, &it, &k);
continue;
}
nghttp3_range_cut(&l, &r, &k, &m);
if (nghttp3_range_len(&l)) {
nghttp3_ksl_update_key(&gaptr->gap, &k, &l);
if (nghttp3_range_len(&r)) {
rv = nghttp3_ksl_insert(&gaptr->gap, &it, &r, NULL);
if (rv != 0) {
return rv;
}
}
} else if (nghttp3_range_len(&r)) {
nghttp3_ksl_update_key(&gaptr->gap, &k, &r);
}
nghttp3_ksl_it_next(&it);
}
return 0;
}
uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr) {
nghttp3_ksl_it it;
if (nghttp3_ksl_len(&gaptr->gap) == 0) {
return 0;
}
it = nghttp3_ksl_begin(&gaptr->gap);
return ((nghttp3_range *)nghttp3_ksl_it_key(&it))->begin;
}
nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,
uint64_t offset) {
nghttp3_range q = {offset, offset + 1};
nghttp3_ksl_it it;
if (nghttp3_ksl_len(&gaptr->gap) == 0) {
nghttp3_range r = {0, UINT64_MAX};
return r;
}
it = nghttp3_ksl_lower_bound_compar(&gaptr->gap, &q,
nghttp3_ksl_range_exclusive_compar);
assert(!nghttp3_ksl_it_end(&it));
return *(nghttp3_range *)nghttp3_ksl_it_key(&it);
}
int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset,
uint64_t datalen) {
nghttp3_range q = {offset, offset + datalen};
nghttp3_ksl_it it;
nghttp3_range m;
if (nghttp3_ksl_len(&gaptr->gap) == 0) {
return 0;
}
it = nghttp3_ksl_lower_bound_compar(&gaptr->gap, &q,
nghttp3_ksl_range_exclusive_compar);
m = nghttp3_range_intersect(&q, (nghttp3_range *)nghttp3_ksl_it_key(&it));
return nghttp3_range_len(&m) == 0;
}
void nghttp3_gaptr_drop_first_gap(nghttp3_gaptr *gaptr) {
nghttp3_ksl_it it;
nghttp3_range r;
if (nghttp3_ksl_len(&gaptr->gap) == 0) {
return;
}
it = nghttp3_ksl_begin(&gaptr->gap);
assert(!nghttp3_ksl_it_end(&it));
r = *(nghttp3_range *)nghttp3_ksl_it_key(&it);
nghttp3_ksl_remove_hint(&gaptr->gap, NULL, &it, &r);
}

99
deps/ngtcp2/nghttp3/lib/nghttp3_gaptr.h vendored Normal file
View File

@ -0,0 +1,99 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_GAPTR_H
#define NGHTTP3_GAPTR_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_mem.h"
#include "nghttp3_ksl.h"
#include "nghttp3_range.h"
/*
* nghttp3_gaptr maintains the gap in the range [0, UINT64_MAX).
*/
typedef struct nghttp3_gaptr {
/* gap maintains the range of offset which is not pushed
yet. Initially, its range is [0, UINT64_MAX). "gap" is the range
that is not pushed yet. */
nghttp3_ksl gap;
/* mem is custom memory allocator */
const nghttp3_mem *mem;
} nghttp3_gaptr;
/*
* nghttp3_gaptr_init initializes |gaptr|.
*/
void nghttp3_gaptr_init(nghttp3_gaptr *gaptr, const nghttp3_mem *mem);
/*
* nghttp3_gaptr_free frees resources allocated for |gaptr|.
*/
void nghttp3_gaptr_free(nghttp3_gaptr *gaptr);
/*
* nghttp3_gaptr_push pushes the range [offset, offset + datalen).
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory
*/
int nghttp3_gaptr_push(nghttp3_gaptr *gaptr, uint64_t offset, uint64_t datalen);
/*
* nghttp3_gaptr_first_gap_offset returns the offset to the first gap.
* If there is no gap, it returns UINT64_MAX.
*/
uint64_t nghttp3_gaptr_first_gap_offset(nghttp3_gaptr *gaptr);
/*
* nghttp3_gaptr_get_first_gap_after returns the first gap which
* includes or comes after |offset|.
*/
nghttp3_range nghttp3_gaptr_get_first_gap_after(nghttp3_gaptr *gaptr,
uint64_t offset);
/*
* nghttp3_gaptr_is_pushed returns nonzero if range [offset, offset +
* datalen) is completely pushed into this object.
*/
int nghttp3_gaptr_is_pushed(nghttp3_gaptr *gaptr, uint64_t offset,
uint64_t datalen);
/*
* nghttp3_gaptr_drop_first_gap deletes the first gap entirely as if
* the range is pushed. This function assumes that at least one gap
* exists.
*/
void nghttp3_gaptr_drop_first_gap(nghttp3_gaptr *gaptr);
#endif /* !defined(NGHTTP3_GAPTR_H) */

1024
deps/ngtcp2/nghttp3/lib/nghttp3_http.c vendored Normal file

File diff suppressed because it is too large Load Diff

173
deps/ngtcp2/nghttp3/lib/nghttp3_http.h vendored Normal file
View File

@ -0,0 +1,173 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2015 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_HTTP_H
#define NGHTTP3_HTTP_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
typedef struct nghttp3_stream nghttp3_stream;
typedef struct nghttp3_http_state nghttp3_http_state;
/* HTTP related flags to enforce HTTP semantics */
/* NGHTTP3_HTTP_FLAG_NONE indicates that no flag is set. */
#define NGHTTP3_HTTP_FLAG_NONE 0x00u
/* header field seen so far */
#define NGHTTP3_HTTP_FLAG__AUTHORITY 0x01u
#define NGHTTP3_HTTP_FLAG__PATH 0x02u
#define NGHTTP3_HTTP_FLAG__METHOD 0x04u
#define NGHTTP3_HTTP_FLAG__SCHEME 0x08u
/* host is not pseudo header, but we require either host or
:authority */
#define NGHTTP3_HTTP_FLAG_HOST 0x10u
#define NGHTTP3_HTTP_FLAG__STATUS 0x20u
/* required header fields for HTTP request except for CONNECT
method. */
#define NGHTTP3_HTTP_FLAG_REQ_HEADERS \
(NGHTTP3_HTTP_FLAG__METHOD | NGHTTP3_HTTP_FLAG__PATH | \
NGHTTP3_HTTP_FLAG__SCHEME)
#define NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED 0x40u
/* HTTP method flags */
#define NGHTTP3_HTTP_FLAG_METH_CONNECT 0x80u
#define NGHTTP3_HTTP_FLAG_METH_HEAD 0x0100u
#define NGHTTP3_HTTP_FLAG_METH_OPTIONS 0x0200u
#define NGHTTP3_HTTP_FLAG_METH_ALL \
(NGHTTP3_HTTP_FLAG_METH_CONNECT | NGHTTP3_HTTP_FLAG_METH_HEAD | \
NGHTTP3_HTTP_FLAG_METH_OPTIONS)
/* :path category */
/* path starts with "/" */
#define NGHTTP3_HTTP_FLAG_PATH_REGULAR 0x0400u
/* path "*" */
#define NGHTTP3_HTTP_FLAG_PATH_ASTERISK 0x0800u
/* scheme */
/* "http" or "https" scheme */
#define NGHTTP3_HTTP_FLAG_SCHEME_HTTP 0x1000u
/* set if final response is expected */
#define NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE 0x2000u
/* NGHTTP3_HTTP_FLAG__PROTOCOL is set when :protocol pseudo header
field is seen. */
#define NGHTTP3_HTTP_FLAG__PROTOCOL 0x4000u
/* NGHTTP3_HTTP_FLAG_PRIORITY is set when priority header field is
processed. */
#define NGHTTP3_HTTP_FLAG_PRIORITY 0x8000u
/* NGHTTP3_HTTP_FLAG_BAD_PRIORITY is set when an error is encountered
while parsing priority header field. */
#define NGHTTP3_HTTP_FLAG_BAD_PRIORITY 0x010000u
/*
* This function is called when HTTP header field |nv| received for
* |http|. This function will validate |nv| against the current state
* of stream. Pass nonzero if this is request headers. Pass nonzero
* to |trailers| if |nv| is included in trailers. |connect_protocol|
* is nonzero if Extended CONNECT Method is enabled.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_MALFORMED_HTTP_HEADER
* Invalid HTTP header field was received.
* NGHTTP3_ERR_REMOVE_HTTP_HEADER
* Invalid HTTP header field was received but it can be treated as
* if it was not received because of compatibility reasons.
*/
int nghttp3_http_on_header(nghttp3_http_state *http, nghttp3_qpack_nv *nv,
int request, int trailers, int connect_protocol);
/*
* This function is called when request header is received. This
* function performs validation and returns 0 if it succeeds, or one
* of the following negative error codes:
*
* NGHTTP3_ERR_MALFORMED_HTTP_HEADER
* Required HTTP header field was not received; or an invalid
* header field was received.
*/
int nghttp3_http_on_request_headers(nghttp3_http_state *http);
/*
* This function is called when response header is received. This
* function performs validation and returns 0 if it succeeds, or one
* of the following negative error codes:
*
* NGHTTP3_ERR_MALFORMED_HTTP_HEADER
* Required HTTP header field was not received; or an invalid
* header field was received.
*/
int nghttp3_http_on_response_headers(nghttp3_http_state *http);
/*
* This function is called when read side stream is closed. This
* function performs validation and returns 0 if it succeeds, or one
* of the following negative error codes:
*
* NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING
* HTTP messaging is violated.
*/
int nghttp3_http_on_remote_end_stream(nghttp3_stream *stream);
/*
* This function is called when chunk of data is received. This
* function performs validation and returns 0 if it succeeds, or one
* of the following negative error codes:
*
* NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING
* HTTP messaging is violated.
*/
int nghttp3_http_on_data_chunk(nghttp3_stream *stream, size_t n);
/*
* This function inspects header fields in |nva| of length |nvlen| and
* records its method in stream->http_flags.
*/
void nghttp3_http_record_request_method(nghttp3_stream *stream,
const nghttp3_nv *nva, size_t nvlen);
/**
* @function
*
* `nghttp3_http_parse_priority` parses priority HTTP header field
* stored in the buffer pointed by |value| of length |len|. If it
* successfully processed header field value, it stores the result
* into |*dest|. This function just overwrites what it sees in the
* header field value and does not initialize any field in |*dest|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* :macro:`NGHTTP3_ERR_INVALID_ARGUMENT`
* The function could not parse the provided value.
*/
int nghttp3_http_parse_priority(nghttp3_pri *dest, const uint8_t *value,
size_t len);
int nghttp3_pri_eq(const nghttp3_pri *a, const nghttp3_pri *b);
#endif /* !defined(NGHTTP3_HTTP_H) */

67
deps/ngtcp2/nghttp3/lib/nghttp3_idtr.c vendored Normal file
View File

@ -0,0 +1,67 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_idtr.h"
#include <assert.h>
void nghttp3_idtr_init(nghttp3_idtr *idtr, const nghttp3_mem *mem) {
nghttp3_gaptr_init(&idtr->gap, mem);
}
void nghttp3_idtr_free(nghttp3_idtr *idtr) {
if (idtr == NULL) {
return;
}
nghttp3_gaptr_free(&idtr->gap);
}
/*
* id_from_stream_id translates |stream_id| to an internal ID.
*/
static uint64_t id_from_stream_id(int64_t stream_id) {
return (uint64_t)(stream_id >> 2);
}
int nghttp3_idtr_open(nghttp3_idtr *idtr, int64_t stream_id) {
uint64_t q;
q = id_from_stream_id(stream_id);
if (nghttp3_gaptr_is_pushed(&idtr->gap, q, 1)) {
return NGHTTP3_ERR_STREAM_IN_USE;
}
return nghttp3_gaptr_push(&idtr->gap, q, 1);
}
int nghttp3_idtr_is_open(nghttp3_idtr *idtr, int64_t stream_id) {
uint64_t q;
q = id_from_stream_id(stream_id);
return nghttp3_gaptr_is_pushed(&idtr->gap, q, 1);
}

77
deps/ngtcp2/nghttp3/lib/nghttp3_idtr.h vendored Normal file
View File

@ -0,0 +1,77 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_IDTR_H
#define NGHTTP3_IDTR_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_mem.h"
#include "nghttp3_gaptr.h"
/*
* nghttp3_idtr tracks the usage of stream ID.
*/
typedef struct nghttp3_idtr {
/* gap maintains the range of an internal ID which is not used yet.
Initially, its range is [0, UINT64_MAX). The internal ID and
stream ID are in the different number spaces. See
id_from_stream_id to convert a stream ID to an internal ID. */
nghttp3_gaptr gap;
} nghttp3_idtr;
/*
* nghttp3_idtr_init initializes |idtr|.
*/
void nghttp3_idtr_init(nghttp3_idtr *idtr, const nghttp3_mem *mem);
/*
* nghttp3_idtr_free frees resources allocated for |idtr|.
*/
void nghttp3_idtr_free(nghttp3_idtr *idtr);
/*
* nghttp3_idtr_open claims that |stream_id| is in use.
*
* It returns 0 if it succeeds, or one of the following negative error
* codes:
*
* NGHTTP3_ERR_STREAM_IN_USE
* |stream_id| has already been used.
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_idtr_open(nghttp3_idtr *idtr, int64_t stream_id);
/*
* nghttp3_idtr_open returns nonzero if |stream_id| is in use.
*/
int nghttp3_idtr_is_open(nghttp3_idtr *idtr, int64_t stream_id);
#endif /* !defined(NGHTTP3_IDTR_H) */

833
deps/ngtcp2/nghttp3/lib/nghttp3_ksl.c vendored Normal file
View File

@ -0,0 +1,833 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2018 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_ksl.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "nghttp3_macro.h"
#include "nghttp3_mem.h"
#include "nghttp3_range.h"
static nghttp3_ksl_blk null_blk = {{{NULL, NULL, 0, 0, {0}}}};
nghttp3_objalloc_def(ksl_blk, nghttp3_ksl_blk, oplent);
static size_t ksl_nodelen(size_t keylen) {
assert(keylen >= sizeof(uint64_t));
return (sizeof(nghttp3_ksl_node) + keylen - sizeof(uint64_t) + 0x7u) &
~(uintptr_t)0x7u;
}
static size_t ksl_blklen(size_t nodelen) {
return sizeof(nghttp3_ksl_blk) + nodelen * NGHTTP3_KSL_MAX_NBLK -
sizeof(uint64_t);
}
/*
* ksl_node_set_key sets |key| to |node|.
*/
static void ksl_node_set_key(nghttp3_ksl *ksl, nghttp3_ksl_node *node,
const void *key) {
memcpy(node->key, key, ksl->keylen);
}
void nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar,
size_t keylen, const nghttp3_mem *mem) {
size_t nodelen = ksl_nodelen(keylen);
nghttp3_objalloc_init(&ksl->blkalloc,
(ksl_blklen(nodelen) + 0xfu) & ~(uintptr_t)0xfu, mem);
ksl->head = NULL;
ksl->front = ksl->back = NULL;
ksl->compar = compar;
ksl->n = 0;
ksl->keylen = keylen;
ksl->nodelen = nodelen;
}
static nghttp3_ksl_blk *ksl_blk_objalloc_new(nghttp3_ksl *ksl) {
return nghttp3_objalloc_ksl_blk_len_get(&ksl->blkalloc,
ksl_blklen(ksl->nodelen));
}
static void ksl_blk_objalloc_del(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk) {
nghttp3_objalloc_ksl_blk_release(&ksl->blkalloc, blk);
}
static int ksl_head_init(nghttp3_ksl *ksl) {
nghttp3_ksl_blk *head = ksl_blk_objalloc_new(ksl);
if (!head) {
return NGHTTP3_ERR_NOMEM;
}
head->next = head->prev = NULL;
head->n = 0;
head->leaf = 1;
ksl->head = head;
ksl->front = ksl->back = head;
return 0;
}
#ifdef NOMEMPOOL
/*
* ksl_free_blk frees |blk| recursively.
*/
static void ksl_free_blk(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk) {
size_t i;
if (!blk->leaf) {
for (i = 0; i < blk->n; ++i) {
ksl_free_blk(ksl, nghttp3_ksl_nth_node(ksl, blk, i)->blk);
}
}
ksl_blk_objalloc_del(ksl, blk);
}
#endif /* defined(NOMEMPOOL) */
void nghttp3_ksl_free(nghttp3_ksl *ksl) {
if (!ksl || !ksl->head) {
return;
}
#ifdef NOMEMPOOL
ksl_free_blk(ksl, ksl->head);
#endif /* defined(NOMEMPOOL) */
nghttp3_objalloc_free(&ksl->blkalloc);
}
/*
* ksl_split_blk splits |blk| into 2 nghttp3_ksl_blk objects. The new
* nghttp3_ksl_blk is always the "right" block.
*
* It returns the pointer to the nghttp3_ksl_blk created which is the
* located at the right of |blk|, or NULL which indicates out of
* memory error.
*/
static nghttp3_ksl_blk *ksl_split_blk(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk) {
nghttp3_ksl_blk *rblk;
rblk = ksl_blk_objalloc_new(ksl);
if (rblk == NULL) {
return NULL;
}
rblk->next = blk->next;
blk->next = rblk;
if (rblk->next) {
rblk->next->prev = rblk;
} else if (ksl->back == blk) {
ksl->back = rblk;
}
rblk->prev = blk;
rblk->leaf = blk->leaf;
rblk->n = blk->n / 2;
blk->n -= rblk->n;
memcpy(rblk->nodes, blk->nodes + ksl->nodelen * blk->n,
ksl->nodelen * rblk->n);
assert(blk->n >= NGHTTP3_KSL_MIN_NBLK);
assert(rblk->n >= NGHTTP3_KSL_MIN_NBLK);
return rblk;
}
/*
* ksl_split_node splits a node included in |blk| at the position |i|
* into 2 adjacent nodes. The new node is always inserted at the
* position |i+1|.
*
* It returns 0 if it succeeds, or one of the following negative error
* codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
static int ksl_split_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) {
nghttp3_ksl_node *node;
nghttp3_ksl_blk *lblk = nghttp3_ksl_nth_node(ksl, blk, i)->blk, *rblk;
rblk = ksl_split_blk(ksl, lblk);
if (rblk == NULL) {
return NGHTTP3_ERR_NOMEM;
}
memmove(blk->nodes + (i + 2) * ksl->nodelen,
blk->nodes + (i + 1) * ksl->nodelen,
ksl->nodelen * (blk->n - (i + 1)));
node = nghttp3_ksl_nth_node(ksl, blk, i + 1);
node->blk = rblk;
++blk->n;
ksl_node_set_key(ksl, node,
nghttp3_ksl_nth_node(ksl, rblk, rblk->n - 1)->key);
node = nghttp3_ksl_nth_node(ksl, blk, i);
ksl_node_set_key(ksl, node,
nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key);
return 0;
}
/*
* ksl_split_head splits a head (root) block. It increases the height
* of skip list by 1.
*
* It returns 0 if it succeeds, or one of the following negative error
* codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
static int ksl_split_head(nghttp3_ksl *ksl) {
nghttp3_ksl_blk *rblk = NULL, *lblk, *nhead = NULL;
nghttp3_ksl_node *node;
rblk = ksl_split_blk(ksl, ksl->head);
if (rblk == NULL) {
return NGHTTP3_ERR_NOMEM;
}
lblk = ksl->head;
nhead = ksl_blk_objalloc_new(ksl);
if (nhead == NULL) {
ksl_blk_objalloc_del(ksl, rblk);
return NGHTTP3_ERR_NOMEM;
}
nhead->next = nhead->prev = NULL;
nhead->n = 2;
nhead->leaf = 0;
node = nghttp3_ksl_nth_node(ksl, nhead, 0);
ksl_node_set_key(ksl, node,
nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key);
node->blk = lblk;
node = nghttp3_ksl_nth_node(ksl, nhead, 1);
ksl_node_set_key(ksl, node,
nghttp3_ksl_nth_node(ksl, rblk, rblk->n - 1)->key);
node->blk = rblk;
ksl->head = nhead;
return 0;
}
/*
* ksl_insert_node inserts a node whose key is |key| with the
* associated |data| at the index of |i|. This function assumes that
* the number of nodes contained by |blk| is strictly less than
* NGHTTP3_KSL_MAX_NBLK.
*/
static void ksl_insert_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i,
const nghttp3_ksl_key *key, void *data) {
nghttp3_ksl_node *node;
assert(blk->n < NGHTTP3_KSL_MAX_NBLK);
memmove(blk->nodes + (i + 1) * ksl->nodelen, blk->nodes + i * ksl->nodelen,
ksl->nodelen * (blk->n - i));
node = nghttp3_ksl_nth_node(ksl, blk, i);
ksl_node_set_key(ksl, node, key);
node->data = data;
++blk->n;
}
static size_t ksl_search(const nghttp3_ksl *ksl, nghttp3_ksl_blk *blk,
const nghttp3_ksl_key *key,
nghttp3_ksl_compar compar) {
size_t i;
nghttp3_ksl_node *node;
for (i = 0, node = (nghttp3_ksl_node *)(void *)blk->nodes;
i < blk->n && compar((nghttp3_ksl_key *)node->key, key);
++i, node = (nghttp3_ksl_node *)(void *)((uint8_t *)node + ksl->nodelen))
;
return i;
}
int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
const nghttp3_ksl_key *key, void *data) {
nghttp3_ksl_blk *blk;
nghttp3_ksl_node *node;
size_t i;
int rv;
if (!ksl->head) {
rv = ksl_head_init(ksl);
if (rv != 0) {
return rv;
}
}
if (ksl->head->n == NGHTTP3_KSL_MAX_NBLK) {
rv = ksl_split_head(ksl);
if (rv != 0) {
return rv;
}
}
blk = ksl->head;
for (;;) {
i = ksl_search(ksl, blk, key, ksl->compar);
if (blk->leaf) {
if (i < blk->n &&
!ksl->compar(key, nghttp3_ksl_nth_node(ksl, blk, i)->key)) {
if (it) {
*it = nghttp3_ksl_end(ksl);
}
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
ksl_insert_node(ksl, blk, i, key, data);
++ksl->n;
if (it) {
nghttp3_ksl_it_init(it, ksl, blk, i);
}
return 0;
}
if (i == blk->n) {
/* This insertion extends the largest key in this subtree. */
for (; !blk->leaf;) {
node = nghttp3_ksl_nth_node(ksl, blk, blk->n - 1);
if (node->blk->n == NGHTTP3_KSL_MAX_NBLK) {
rv = ksl_split_node(ksl, blk, blk->n - 1);
if (rv != 0) {
return rv;
}
node = nghttp3_ksl_nth_node(ksl, blk, blk->n - 1);
}
ksl_node_set_key(ksl, node, key);
blk = node->blk;
}
ksl_insert_node(ksl, blk, blk->n, key, data);
++ksl->n;
if (it) {
nghttp3_ksl_it_init(it, ksl, blk, blk->n - 1);
}
return 0;
}
node = nghttp3_ksl_nth_node(ksl, blk, i);
if (node->blk->n == NGHTTP3_KSL_MAX_NBLK) {
rv = ksl_split_node(ksl, blk, i);
if (rv != 0) {
return rv;
}
if (ksl->compar((nghttp3_ksl_key *)node->key, key)) {
node = nghttp3_ksl_nth_node(ksl, blk, i + 1);
if (ksl->compar((nghttp3_ksl_key *)node->key, key)) {
ksl_node_set_key(ksl, node, key);
}
}
}
blk = node->blk;
}
}
/*
* ksl_remove_node removes the node included in |blk| at the index of
* |i|.
*/
static void ksl_remove_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) {
memmove(blk->nodes + i * ksl->nodelen, blk->nodes + (i + 1) * ksl->nodelen,
ksl->nodelen * (blk->n - (i + 1)));
--blk->n;
}
/*
* ksl_merge_node merges 2 nodes which are the nodes at the index of
* |i| and |i + 1|.
*
* If |blk| is the head (root) block and it contains just 2 nodes
* before merging nodes, the merged block becomes head block, which
* decreases the height of |ksl| by 1.
*
* This function returns the pointer to the merged block.
*/
static nghttp3_ksl_blk *ksl_merge_node(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk,
size_t i) {
nghttp3_ksl_node *lnode;
nghttp3_ksl_blk *lblk, *rblk;
assert(i + 1 < blk->n);
lnode = nghttp3_ksl_nth_node(ksl, blk, i);
lblk = lnode->blk;
rblk = nghttp3_ksl_nth_node(ksl, blk, i + 1)->blk;
assert(lblk->n + rblk->n < NGHTTP3_KSL_MAX_NBLK);
memcpy(lblk->nodes + ksl->nodelen * lblk->n, rblk->nodes,
ksl->nodelen * rblk->n);
lblk->n += rblk->n;
lblk->next = rblk->next;
if (lblk->next) {
lblk->next->prev = lblk;
} else if (ksl->back == rblk) {
ksl->back = lblk;
}
ksl_blk_objalloc_del(ksl, rblk);
if (ksl->head == blk && blk->n == 2) {
ksl_blk_objalloc_del(ksl, ksl->head);
ksl->head = lblk;
} else {
ksl_remove_node(ksl, blk, i + 1);
ksl_node_set_key(ksl, lnode,
nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key);
}
return lblk;
}
/*
* ksl_shift_left moves the first nodes in blk->nodes[i]->blk->nodes
* to blk->nodes[i - 1]->blk->nodes in a manner that they have the
* same amount of nodes as much as possible.
*/
static void ksl_shift_left(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) {
nghttp3_ksl_node *lnode, *rnode;
nghttp3_ksl_blk *lblk, *rblk;
size_t n;
assert(i > 0);
lnode = nghttp3_ksl_nth_node(ksl, blk, i - 1);
rnode = nghttp3_ksl_nth_node(ksl, blk, i);
lblk = lnode->blk;
rblk = rnode->blk;
assert(lblk->n < NGHTTP3_KSL_MAX_NBLK);
assert(rblk->n > NGHTTP3_KSL_MIN_NBLK);
n = (lblk->n + rblk->n + 1) / 2 - lblk->n;
assert(n > 0);
assert(lblk->n <= NGHTTP3_KSL_MAX_NBLK - n);
assert(rblk->n >= NGHTTP3_KSL_MIN_NBLK + n);
memcpy(lblk->nodes + ksl->nodelen * lblk->n, rblk->nodes, ksl->nodelen * n);
lblk->n += (uint32_t)n;
rblk->n -= (uint32_t)n;
ksl_node_set_key(ksl, lnode,
nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key);
memmove(rblk->nodes, rblk->nodes + ksl->nodelen * n, ksl->nodelen * rblk->n);
}
/*
* ksl_shift_right moves the last nodes in blk->nodes[i]->blk->nodes
* to blk->nodes[i + 1]->blk->nodes in a manner that they have the
* same amount of nodes as much as possible.
*/
static void ksl_shift_right(nghttp3_ksl *ksl, nghttp3_ksl_blk *blk, size_t i) {
nghttp3_ksl_node *lnode, *rnode;
nghttp3_ksl_blk *lblk, *rblk;
size_t n;
assert(i < blk->n - 1);
lnode = nghttp3_ksl_nth_node(ksl, blk, i);
rnode = nghttp3_ksl_nth_node(ksl, blk, i + 1);
lblk = lnode->blk;
rblk = rnode->blk;
assert(lblk->n > NGHTTP3_KSL_MIN_NBLK);
assert(rblk->n < NGHTTP3_KSL_MAX_NBLK);
n = (lblk->n + rblk->n + 1) / 2 - rblk->n;
assert(n > 0);
assert(lblk->n >= NGHTTP3_KSL_MIN_NBLK + n);
assert(rblk->n <= NGHTTP3_KSL_MAX_NBLK - n);
memmove(rblk->nodes + ksl->nodelen * n, rblk->nodes, ksl->nodelen * rblk->n);
rblk->n += (uint32_t)n;
lblk->n -= (uint32_t)n;
memcpy(rblk->nodes, lblk->nodes + ksl->nodelen * lblk->n, ksl->nodelen * n);
ksl_node_set_key(ksl, lnode,
nghttp3_ksl_nth_node(ksl, lblk, lblk->n - 1)->key);
}
/*
* key_equal returns nonzero if |lhs| and |rhs| are equal using the
* function |compar|.
*/
static int key_equal(nghttp3_ksl_compar compar, const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
return !compar(lhs, rhs) && !compar(rhs, lhs);
}
int nghttp3_ksl_remove_hint(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
const nghttp3_ksl_it *hint,
const nghttp3_ksl_key *key) {
nghttp3_ksl_blk *blk = hint->blk;
assert(ksl->head);
if (blk->n <= NGHTTP3_KSL_MIN_NBLK) {
return nghttp3_ksl_remove(ksl, it, key);
}
ksl_remove_node(ksl, blk, hint->i);
--ksl->n;
if (it) {
if (hint->i == blk->n && blk->next) {
nghttp3_ksl_it_init(it, ksl, blk->next, 0);
} else {
nghttp3_ksl_it_init(it, ksl, blk, hint->i);
}
}
return 0;
}
int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
const nghttp3_ksl_key *key) {
nghttp3_ksl_blk *blk = ksl->head;
nghttp3_ksl_node *node;
size_t i;
if (!blk) {
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
if (!blk->leaf && blk->n == 2 &&
nghttp3_ksl_nth_node(ksl, blk, 0)->blk->n == NGHTTP3_KSL_MIN_NBLK &&
nghttp3_ksl_nth_node(ksl, blk, 1)->blk->n == NGHTTP3_KSL_MIN_NBLK) {
blk = ksl_merge_node(ksl, blk, 0);
}
for (;;) {
i = ksl_search(ksl, blk, key, ksl->compar);
if (i == blk->n) {
if (it) {
*it = nghttp3_ksl_end(ksl);
}
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
if (blk->leaf) {
if (ksl->compar(key, nghttp3_ksl_nth_node(ksl, blk, i)->key)) {
if (it) {
*it = nghttp3_ksl_end(ksl);
}
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
ksl_remove_node(ksl, blk, i);
--ksl->n;
if (it) {
if (blk->n == i && blk->next) {
nghttp3_ksl_it_init(it, ksl, blk->next, 0);
} else {
nghttp3_ksl_it_init(it, ksl, blk, i);
}
}
return 0;
}
node = nghttp3_ksl_nth_node(ksl, blk, i);
if (node->blk->n > NGHTTP3_KSL_MIN_NBLK) {
blk = node->blk;
continue;
}
assert(node->blk->n == NGHTTP3_KSL_MIN_NBLK);
if (i + 1 < blk->n &&
nghttp3_ksl_nth_node(ksl, blk, i + 1)->blk->n > NGHTTP3_KSL_MIN_NBLK) {
ksl_shift_left(ksl, blk, i + 1);
blk = node->blk;
continue;
}
if (i > 0 &&
nghttp3_ksl_nth_node(ksl, blk, i - 1)->blk->n > NGHTTP3_KSL_MIN_NBLK) {
ksl_shift_right(ksl, blk, i - 1);
blk = node->blk;
continue;
}
if (i + 1 < blk->n) {
blk = ksl_merge_node(ksl, blk, i);
continue;
}
assert(i > 0);
blk = ksl_merge_node(ksl, blk, i - 1);
}
}
nghttp3_ksl_it nghttp3_ksl_lower_bound(const nghttp3_ksl *ksl,
const nghttp3_ksl_key *key) {
return nghttp3_ksl_lower_bound_compar(ksl, key, ksl->compar);
}
nghttp3_ksl_it nghttp3_ksl_lower_bound_compar(const nghttp3_ksl *ksl,
const nghttp3_ksl_key *key,
nghttp3_ksl_compar compar) {
nghttp3_ksl_blk *blk = ksl->head;
nghttp3_ksl_it it;
size_t i;
if (!blk) {
nghttp3_ksl_it_init(&it, ksl, &null_blk, 0);
return it;
}
for (;;) {
i = ksl_search(ksl, blk, key, compar);
if (blk->leaf) {
if (i == blk->n && blk->next) {
blk = blk->next;
i = 0;
}
nghttp3_ksl_it_init(&it, ksl, blk, i);
return it;
}
if (i == blk->n) {
/* This happens if descendant has smaller key. Fast forward to
find last node in this subtree. */
for (; !blk->leaf; blk = nghttp3_ksl_nth_node(ksl, blk, blk->n - 1)->blk)
;
if (blk->next) {
blk = blk->next;
i = 0;
} else {
i = blk->n;
}
nghttp3_ksl_it_init(&it, ksl, blk, i);
return it;
}
blk = nghttp3_ksl_nth_node(ksl, blk, i)->blk;
}
}
void nghttp3_ksl_update_key(nghttp3_ksl *ksl, const nghttp3_ksl_key *old_key,
const nghttp3_ksl_key *new_key) {
nghttp3_ksl_blk *blk = ksl->head;
nghttp3_ksl_node *node;
size_t i;
assert(ksl->head);
for (;;) {
i = ksl_search(ksl, blk, old_key, ksl->compar);
assert(i < blk->n);
node = nghttp3_ksl_nth_node(ksl, blk, i);
if (blk->leaf) {
assert(key_equal(ksl->compar, (nghttp3_ksl_key *)node->key, old_key));
ksl_node_set_key(ksl, node, new_key);
return;
}
if (key_equal(ksl->compar, (nghttp3_ksl_key *)node->key, old_key) ||
ksl->compar((nghttp3_ksl_key *)node->key, new_key)) {
ksl_node_set_key(ksl, node, new_key);
}
blk = node->blk;
}
}
size_t nghttp3_ksl_len(const nghttp3_ksl *ksl) { return ksl->n; }
void nghttp3_ksl_clear(nghttp3_ksl *ksl) {
if (!ksl->head) {
return;
}
#ifdef NOMEMPOOL
ksl_free_blk(ksl, ksl->head);
#endif /* defined(NOMEMPOOL) */
ksl->front = ksl->back = ksl->head = NULL;
ksl->n = 0;
nghttp3_objalloc_clear(&ksl->blkalloc);
}
#ifndef WIN32
static void ksl_print(const nghttp3_ksl *ksl, nghttp3_ksl_blk *blk,
size_t level) {
size_t i;
nghttp3_ksl_node *node;
fprintf(stderr, "LV=%zu n=%u\n", level, blk->n);
if (blk->leaf) {
for (i = 0; i < blk->n; ++i) {
node = nghttp3_ksl_nth_node(ksl, blk, i);
fprintf(stderr, " %" PRId64, *(int64_t *)(void *)node->key);
}
fprintf(stderr, "\n");
return;
}
for (i = 0; i < blk->n; ++i) {
ksl_print(ksl, nghttp3_ksl_nth_node(ksl, blk, i)->blk, level + 1);
}
}
void nghttp3_ksl_print(const nghttp3_ksl *ksl) {
if (!ksl->head) {
return;
}
ksl_print(ksl, ksl->head, 0);
}
#endif /* !defined(WIN32) */
nghttp3_ksl_it nghttp3_ksl_begin(const nghttp3_ksl *ksl) {
nghttp3_ksl_it it;
if (ksl->head) {
nghttp3_ksl_it_init(&it, ksl, ksl->front, 0);
} else {
nghttp3_ksl_it_init(&it, ksl, &null_blk, 0);
}
return it;
}
nghttp3_ksl_it nghttp3_ksl_end(const nghttp3_ksl *ksl) {
nghttp3_ksl_it it;
if (ksl->head) {
nghttp3_ksl_it_init(&it, ksl, ksl->back, ksl->back->n);
} else {
nghttp3_ksl_it_init(&it, ksl, &null_blk, 0);
}
return it;
}
void nghttp3_ksl_it_init(nghttp3_ksl_it *it, const nghttp3_ksl *ksl,
nghttp3_ksl_blk *blk, size_t i) {
it->ksl = ksl;
it->blk = blk;
it->i = i;
}
void nghttp3_ksl_it_prev(nghttp3_ksl_it *it) {
assert(!nghttp3_ksl_it_begin(it));
if (it->i == 0) {
it->blk = it->blk->prev;
it->i = it->blk->n - 1;
} else {
--it->i;
}
}
int nghttp3_ksl_it_begin(const nghttp3_ksl_it *it) {
return it->i == 0 && it->blk->prev == NULL;
}
int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
const nghttp3_range *a = lhs, *b = rhs;
return a->begin < b->begin;
}
int nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs) {
const nghttp3_range *a = lhs, *b = rhs;
return a->begin < b->begin && !(nghttp3_max_uint64(a->begin, b->begin) <
nghttp3_min_uint64(a->end, b->end));
}

351
deps/ngtcp2/nghttp3/lib/nghttp3_ksl.h vendored Normal file
View File

@ -0,0 +1,351 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2018 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_KSL_H
#define NGHTTP3_KSL_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <stdlib.h>
#include <nghttp3/nghttp3.h>
#include "nghttp3_objalloc.h"
#define NGHTTP3_KSL_DEGR 16
/* NGHTTP3_KSL_MAX_NBLK is the maximum number of nodes which a single
block can contain. */
#define NGHTTP3_KSL_MAX_NBLK (2 * NGHTTP3_KSL_DEGR - 1)
/* NGHTTP3_KSL_MIN_NBLK is the minimum number of nodes which a single
block other than root must contain. */
#define NGHTTP3_KSL_MIN_NBLK (NGHTTP3_KSL_DEGR - 1)
/*
* nghttp3_ksl_key represents key in nghttp3_ksl.
*/
typedef void nghttp3_ksl_key;
typedef struct nghttp3_ksl_node nghttp3_ksl_node;
typedef struct nghttp3_ksl_blk nghttp3_ksl_blk;
/*
* nghttp3_ksl_node is a node which contains either nghttp3_ksl_blk or
* opaque data. If a node is an internal node, it contains
* nghttp3_ksl_blk. Otherwise, it has data. The key is stored at the
* location starting at key.
*/
struct nghttp3_ksl_node {
union {
nghttp3_ksl_blk *blk;
void *data;
};
union {
uint64_t align;
/* key is a buffer to include key associated to this node.
Because the length of key is unknown until nghttp3_ksl_init is
called, the actual buffer will be allocated after this
field. */
uint8_t key[1];
};
};
/*
* nghttp3_ksl_blk contains nghttp3_ksl_node objects.
*/
struct nghttp3_ksl_blk {
union {
struct {
/* next points to the next block if leaf field is nonzero. */
nghttp3_ksl_blk *next;
/* prev points to the previous block if leaf field is
nonzero. */
nghttp3_ksl_blk *prev;
/* n is the number of nodes this object contains in nodes. */
uint32_t n;
/* leaf is nonzero if this block contains leaf nodes. */
uint32_t leaf;
union {
uint64_t align;
/* nodes is a buffer to contain NGHTTP3_KSL_MAX_NBLK
nghttp3_ksl_node objects. Because nghttp3_ksl_node object
is allocated along with the additional variable length key
storage, the size of buffer is unknown until
nghttp3_ksl_init is called. */
uint8_t nodes[1];
};
};
nghttp3_opl_entry oplent;
};
};
nghttp3_objalloc_decl(ksl_blk, nghttp3_ksl_blk, oplent);
/*
* nghttp3_ksl_compar is a function type which returns nonzero if key
* |lhs| should be placed before |rhs|. It returns 0 otherwise.
*/
typedef int (*nghttp3_ksl_compar)(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs);
typedef struct nghttp3_ksl nghttp3_ksl;
typedef struct nghttp3_ksl_it nghttp3_ksl_it;
/*
* nghttp3_ksl_it is a bidirectional iterator to iterate nodes.
*/
struct nghttp3_ksl_it {
const nghttp3_ksl *ksl;
nghttp3_ksl_blk *blk;
size_t i;
};
/*
* nghttp3_ksl is a deterministic paged skip list.
*/
struct nghttp3_ksl {
nghttp3_objalloc blkalloc;
/* head points to the root block. */
nghttp3_ksl_blk *head;
/* front points to the first leaf block. */
nghttp3_ksl_blk *front;
/* back points to the last leaf block. */
nghttp3_ksl_blk *back;
nghttp3_ksl_compar compar;
/* n is the number of elements stored. */
size_t n;
/* keylen is the size of key */
size_t keylen;
/* nodelen is the actual size of nghttp3_ksl_node including key
storage. */
size_t nodelen;
};
/*
* nghttp3_ksl_init initializes |ksl|. |compar| specifies compare
* function. |keylen| is the length of key and must be at least
* sizeof(uint64_t).
*/
void nghttp3_ksl_init(nghttp3_ksl *ksl, nghttp3_ksl_compar compar,
size_t keylen, const nghttp3_mem *mem);
/*
* nghttp3_ksl_free frees resources allocated for |ksl|. If |ksl| is
* NULL, this function does nothing. It does not free the memory
* region pointed by |ksl| itself.
*/
void nghttp3_ksl_free(nghttp3_ksl *ksl);
/*
* nghttp3_ksl_insert inserts |key| with its associated |data|. On
* successful insertion, the iterator points to the inserted node is
* stored in |*it| if |it| is not NULL.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
* NGHTTP3_ERR_INVALID_ARGUMENT
* |key| already exists.
*/
int nghttp3_ksl_insert(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
const nghttp3_ksl_key *key, void *data);
/*
* nghttp3_ksl_remove removes the |key| from |ksl|.
*
* This function assigns the iterator to |*it|, which points to the
* node which is located at the right next of the removed node if |it|
* is not NULL. If |key| is not found, no deletion takes place and
* the return value of nghttp3_ksl_end(ksl) is assigned to |*it| if
* |it| is not NULL.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_INVALID_ARGUMENT
* |key| does not exist.
*/
int nghttp3_ksl_remove(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
const nghttp3_ksl_key *key);
/*
* nghttp3_ksl_remove_hint removes the |key| from |ksl|. |hint| must
* point to the same node denoted by |key|. |hint| is used to remove
* a node efficiently in some cases. Other than that, it behaves
* exactly like nghttp3_ksl_remove. |it| and |hint| can point to the
* same object.
*/
int nghttp3_ksl_remove_hint(nghttp3_ksl *ksl, nghttp3_ksl_it *it,
const nghttp3_ksl_it *hint,
const nghttp3_ksl_key *key);
/*
* nghttp3_ksl_lower_bound returns the iterator which points to the
* first node which has the key which is equal to |key| or the last
* node which satisfies !compar(&node->key, key). If there is no such
* node, it returns the iterator which satisfies
* nghttp3_ksl_it_end(it) != 0.
*/
nghttp3_ksl_it nghttp3_ksl_lower_bound(const nghttp3_ksl *ksl,
const nghttp3_ksl_key *key);
/*
* nghttp3_ksl_lower_bound_compar works like nghttp3_ksl_lower_bound,
* but it takes custom function |compar| to do lower bound search.
*/
nghttp3_ksl_it nghttp3_ksl_lower_bound_compar(const nghttp3_ksl *ksl,
const nghttp3_ksl_key *key,
nghttp3_ksl_compar compar);
/*
* nghttp3_ksl_update_key replaces the key of nodes which has
* |old_key| with |new_key|. |new_key| must be strictly greater than
* the previous node and strictly smaller than the next node.
*/
void nghttp3_ksl_update_key(nghttp3_ksl *ksl, const nghttp3_ksl_key *old_key,
const nghttp3_ksl_key *new_key);
/*
* nghttp3_ksl_begin returns the iterator which points to the first
* node. If there is no node in |ksl|, it returns the iterator which
* satisfies both nghttp3_ksl_it_begin(it) != 0 and
* nghttp3_ksl_it_end(it) != 0.
*/
nghttp3_ksl_it nghttp3_ksl_begin(const nghttp3_ksl *ksl);
/*
* nghttp3_ksl_end returns the iterator which points to the node
* following the last node. The returned object satisfies
* nghttp3_ksl_it_end(). If there is no node in |ksl|, it returns the
* iterator which satisfies nghttp3_ksl_it_begin(it) != 0 and
* nghttp3_ksl_it_end(it) != 0.
*/
nghttp3_ksl_it nghttp3_ksl_end(const nghttp3_ksl *ksl);
/*
* nghttp3_ksl_len returns the number of elements stored in |ksl|.
*/
size_t nghttp3_ksl_len(const nghttp3_ksl *ksl);
/*
* nghttp3_ksl_clear removes all elements stored in |ksl|.
*/
void nghttp3_ksl_clear(nghttp3_ksl *ksl);
/*
* nghttp3_ksl_nth_node returns the |n|th node under |blk|.
*/
#define nghttp3_ksl_nth_node(KSL, BLK, N) \
((nghttp3_ksl_node *)(void *)((BLK)->nodes + (KSL)->nodelen * (N)))
#ifndef WIN32
/*
* nghttp3_ksl_print prints its internal state in stderr. It assumes
* that the key is of type int64_t. This function should be used for
* the debugging purpose only.
*/
void nghttp3_ksl_print(const nghttp3_ksl *ksl);
#endif /* !defined(WIN32) */
/*
* nghttp3_ksl_it_init initializes |it|.
*/
void nghttp3_ksl_it_init(nghttp3_ksl_it *it, const nghttp3_ksl *ksl,
nghttp3_ksl_blk *blk, size_t i);
/*
* nghttp3_ksl_it_get returns the data associated to the node which
* |it| points to. It is undefined to call this function when
* nghttp3_ksl_it_end(it) returns nonzero.
*/
#define nghttp3_ksl_it_get(IT) \
nghttp3_ksl_nth_node((IT)->ksl, (IT)->blk, (IT)->i)->data
/*
* nghttp3_ksl_it_next advances the iterator by one. It is undefined
* if this function is called when nghttp3_ksl_it_end(it) returns
* nonzero.
*/
#define nghttp3_ksl_it_next(IT) \
(++(IT)->i == (IT)->blk->n && (IT)->blk->next \
? ((IT)->blk = (IT)->blk->next, (IT)->i = 0) \
: 0)
/*
* nghttp3_ksl_it_prev moves backward the iterator by one. It is
* undefined if this function is called when nghttp3_ksl_it_begin(it)
* returns nonzero.
*/
void nghttp3_ksl_it_prev(nghttp3_ksl_it *it);
/*
* nghttp3_ksl_it_end returns nonzero if |it| points to the one beyond
* the last node.
*/
#define nghttp3_ksl_it_end(IT) \
((IT)->blk->n == (IT)->i && (IT)->blk->next == NULL)
/*
* nghttp3_ksl_it_begin returns nonzero if |it| points to the first
* node. |it| might satisfy both nghttp3_ksl_it_begin(it) != 0 and
* nghttp3_ksl_it_end(it) != 0 if the skip list has no node.
*/
int nghttp3_ksl_it_begin(const nghttp3_ksl_it *it);
/*
* nghttp3_ksl_key returns the key of the node which |it| points to.
* It is undefined to call this function when nghttp3_ksl_it_end(it)
* returns nonzero.
*/
#define nghttp3_ksl_it_key(IT) \
((nghttp3_ksl_key *)nghttp3_ksl_nth_node((IT)->ksl, (IT)->blk, (IT)->i)->key)
/*
* nghttp3_ksl_range_compar is an implementation of
* nghttp3_ksl_compar. lhs->ptr and rhs->ptr must point to
* nghttp3_range object and the function returns nonzero if (const
* nghttp3_range *)(lhs->ptr)->begin < (const nghttp3_range
* *)(rhs->ptr)->begin.
*/
int nghttp3_ksl_range_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs);
/*
* nghttp3_ksl_range_exclusive_compar is an implementation of
* nghttp3_ksl_compar. lhs->ptr and rhs->ptr must point to
* nghttp3_range object and the function returns nonzero if (const
* nghttp3_range *)(lhs->ptr)->begin < (const nghttp3_range
* *)(rhs->ptr)->begin and the 2 ranges do not intersect.
*/
int nghttp3_ksl_range_exclusive_compar(const nghttp3_ksl_key *lhs,
const nghttp3_ksl_key *rhs);
#endif /* !defined(NGHTTP3_KSL_H) */

74
deps/ngtcp2/nghttp3/lib/nghttp3_macro.h vendored Normal file
View File

@ -0,0 +1,74 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_MACRO_H
#define NGHTTP3_MACRO_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <stddef.h>
#include <nghttp3/nghttp3.h>
#define nghttp3_struct_of(ptr, type, member) \
((type *)(void *)((char *)(ptr) - offsetof(type, member)))
#define nghttp3_arraylen(A) (sizeof(A) / sizeof(*(A)))
#define lstreq(A, B, N) ((sizeof((A)) - 1) == (N) && memcmp((A), (B), (N)) == 0)
/* NGHTTP3_MAX_VARINT` is the maximum value which can be encoded in
variable-length integer encoding. */
#define NGHTTP3_MAX_VARINT ((1ULL << 62) - 1)
#define nghttp3_max_def(SUFFIX, T) \
static inline T nghttp3_max_##SUFFIX(T a, T b) { return a < b ? b : a; }
nghttp3_max_def(int8, int8_t);
nghttp3_max_def(int16, int16_t);
nghttp3_max_def(int32, int32_t);
nghttp3_max_def(int64, int64_t);
nghttp3_max_def(uint8, uint8_t);
nghttp3_max_def(uint16, uint16_t);
nghttp3_max_def(uint32, uint32_t);
nghttp3_max_def(uint64, uint64_t);
nghttp3_max_def(size, size_t);
#define nghttp3_min_def(SUFFIX, T) \
static inline T nghttp3_min_##SUFFIX(T a, T b) { return a < b ? a : b; }
nghttp3_min_def(int8, int8_t);
nghttp3_min_def(int16, int16_t);
nghttp3_min_def(int32, int32_t);
nghttp3_min_def(int64, int64_t);
nghttp3_min_def(uint8, uint8_t);
nghttp3_min_def(uint16, uint16_t);
nghttp3_min_def(uint32, uint32_t);
nghttp3_min_def(uint64, uint64_t);
nghttp3_min_def(size, size_t);
#endif /* !defined(NGHTTP3_MACRO_H) */

303
deps/ngtcp2/nghttp3/lib/nghttp3_map.c vendored Normal file
View File

@ -0,0 +1,303 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2012 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_map.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "nghttp3_conv.h"
#define NGHTTP3_INITIAL_TABLE_LENBITS 4
void nghttp3_map_init(nghttp3_map *map, const nghttp3_mem *mem) {
map->mem = mem;
map->hashbits = 0;
map->table = NULL;
map->size = 0;
}
void nghttp3_map_free(nghttp3_map *map) {
if (!map) {
return;
}
nghttp3_mem_free(map->mem, map->table);
}
int nghttp3_map_each(const nghttp3_map *map, int (*func)(void *data, void *ptr),
void *ptr) {
int rv;
size_t i;
nghttp3_map_bucket *bkt;
size_t tablelen;
if (map->size == 0) {
return 0;
}
tablelen = 1u << map->hashbits;
for (i = 0; i < tablelen; ++i) {
bkt = &map->table[i];
if (bkt->data == NULL) {
continue;
}
rv = func(bkt->data, ptr);
if (rv != 0) {
return rv;
}
}
return 0;
}
static size_t hash(nghttp3_map_key_type key, size_t bits) {
return (size_t)((key * 11400714819323198485llu) >> (64 - bits));
}
static void map_bucket_swap(nghttp3_map_bucket *a, nghttp3_map_bucket *b) {
nghttp3_map_bucket c = *a;
*a = *b;
*b = c;
}
#ifndef WIN32
void nghttp3_map_print_distance(const nghttp3_map *map) {
size_t i;
size_t idx;
nghttp3_map_bucket *bkt;
size_t tablelen;
if (map->size == 0) {
return;
}
tablelen = 1u << map->hashbits;
for (i = 0; i < tablelen; ++i) {
bkt = &map->table[i];
if (bkt->data == NULL) {
fprintf(stderr, "@%zu <EMPTY>\n", i);
continue;
}
idx = hash(bkt->key, map->hashbits);
fprintf(stderr, "@%zu hash=%zu key=%" PRIu64 " base=%zu distance=%u\n", i,
hash(bkt->key, map->hashbits), bkt->key, idx, bkt->psl);
}
}
#endif /* !defined(WIN32) */
static int insert(nghttp3_map_bucket *table, size_t hashbits,
nghttp3_map_key_type key, void *data) {
size_t idx = hash(key, hashbits);
nghttp3_map_bucket b = {0, key, data}, *bkt;
size_t mask = (1u << hashbits) - 1;
for (;;) {
bkt = &table[idx];
if (bkt->data == NULL) {
*bkt = b;
return 0;
}
if (b.psl > bkt->psl) {
map_bucket_swap(bkt, &b);
} else if (bkt->key == key) {
/* TODO This check is just a waste after first swap or if this
function is called from map_resize. That said, there is no
difference with or without this conditional in performance
wise. */
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
++b.psl;
idx = (idx + 1) & mask;
}
}
static int map_resize(nghttp3_map *map, size_t new_hashbits) {
size_t i;
nghttp3_map_bucket *new_table;
nghttp3_map_bucket *bkt;
size_t tablelen;
int rv;
(void)rv;
new_table = nghttp3_mem_calloc(map->mem, 1u << new_hashbits,
sizeof(nghttp3_map_bucket));
if (new_table == NULL) {
return NGHTTP3_ERR_NOMEM;
}
if (map->size) {
tablelen = 1u << map->hashbits;
for (i = 0; i < tablelen; ++i) {
bkt = &map->table[i];
if (bkt->data == NULL) {
continue;
}
rv = insert(new_table, new_hashbits, bkt->key, bkt->data);
assert(0 == rv);
}
}
nghttp3_mem_free(map->mem, map->table);
map->hashbits = new_hashbits;
map->table = new_table;
return 0;
}
int nghttp3_map_insert(nghttp3_map *map, nghttp3_map_key_type key, void *data) {
int rv;
assert(data);
/* Load factor is 0.75 */
/* Under the very initial condition, that is map->size == 0 and
map->hashbits == 0, 4 > 3 still holds nicely. */
if ((map->size + 1) * 4 > (1u << map->hashbits) * 3) {
if (map->hashbits) {
rv = map_resize(map, map->hashbits + 1);
if (rv != 0) {
return rv;
}
} else {
rv = map_resize(map, NGHTTP3_INITIAL_TABLE_LENBITS);
if (rv != 0) {
return rv;
}
}
}
rv = insert(map->table, map->hashbits, key, data);
if (rv != 0) {
return rv;
}
++map->size;
return 0;
}
void *nghttp3_map_find(const nghttp3_map *map, nghttp3_map_key_type key) {
size_t idx;
nghttp3_map_bucket *bkt;
size_t psl = 0;
size_t mask;
if (map->size == 0) {
return NULL;
}
idx = hash(key, map->hashbits);
mask = (1u << map->hashbits) - 1;
for (;;) {
bkt = &map->table[idx];
if (bkt->data == NULL || psl > bkt->psl) {
return NULL;
}
if (bkt->key == key) {
return bkt->data;
}
++psl;
idx = (idx + 1) & mask;
}
}
int nghttp3_map_remove(nghttp3_map *map, nghttp3_map_key_type key) {
size_t idx;
nghttp3_map_bucket *b, *bkt;
size_t psl = 0;
size_t mask;
if (map->size == 0) {
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
idx = hash(key, map->hashbits);
mask = (1u << map->hashbits) - 1;
for (;;) {
bkt = &map->table[idx];
if (bkt->data == NULL || psl > bkt->psl) {
return NGHTTP3_ERR_INVALID_ARGUMENT;
}
if (bkt->key == key) {
b = bkt;
idx = (idx + 1) & mask;
for (;;) {
bkt = &map->table[idx];
if (bkt->data == NULL || bkt->psl == 0) {
b->data = NULL;
break;
}
--bkt->psl;
*b = *bkt;
b = bkt;
idx = (idx + 1) & mask;
}
--map->size;
return 0;
}
++psl;
idx = (idx + 1) & mask;
}
}
void nghttp3_map_clear(nghttp3_map *map) {
if (map->size == 0) {
return;
}
memset(map->table, 0, sizeof(*map->table) * (1u << map->hashbits));
map->size = 0;
}
size_t nghttp3_map_size(const nghttp3_map *map) { return map->size; }

129
deps/ngtcp2/nghttp3/lib/nghttp3_map.h vendored Normal file
View File

@ -0,0 +1,129 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2012 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_MAP_H
#define NGHTTP3_MAP_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_mem.h"
/* Implementation of unordered map */
typedef uint64_t nghttp3_map_key_type;
typedef struct nghttp3_map_bucket {
uint32_t psl;
nghttp3_map_key_type key;
void *data;
} nghttp3_map_bucket;
typedef struct nghttp3_map {
nghttp3_map_bucket *table;
const nghttp3_mem *mem;
size_t size;
size_t hashbits;
} nghttp3_map;
/*
* nghttp3_map_init initializes the map |map|.
*/
void nghttp3_map_init(nghttp3_map *map, const nghttp3_mem *mem);
/*
* nghttp3_map_free deallocates any resources allocated for |map|.
* The stored entries are not freed by this function. Use
* nghttp3_map_each() to free each entry.
*/
void nghttp3_map_free(nghttp3_map *map);
/*
* nghttp3_map_insert inserts the new |data| with the |key| to the map
* |map|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_INVALID_ARGUMENT
* The item associated by |key| already exists.
* NGHTTP3_ERR_NOMEM
* Out of memory
*/
int nghttp3_map_insert(nghttp3_map *map, nghttp3_map_key_type key, void *data);
/*
* nghttp3_map_find returns the entry associated by the key |key|. If
* there is no such entry, this function returns NULL.
*/
void *nghttp3_map_find(const nghttp3_map *map, nghttp3_map_key_type key);
/*
* nghttp3_map_remove removes the entry associated by the key |key|
* from the |map|. The removed entry is not freed by this function.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_INVALID_ARGUMENT
* The entry associated by |key| does not exist.
*/
int nghttp3_map_remove(nghttp3_map *map, nghttp3_map_key_type key);
/*
* nghttp3_map_clear removes all entries from |map|. The removed
* entry is not freed by this function.
*/
void nghttp3_map_clear(nghttp3_map *map);
/*
* nghttp3_map_size returns the number of items stored in the map
* |map|.
*/
size_t nghttp3_map_size(const nghttp3_map *map);
/*
* nghttp3_map_each applies the function |func| to each entry in the
* |map| with the optional user supplied pointer |ptr|.
*
* If the |func| returns 0, this function calls the |func| with the
* next entry. If the |func| returns nonzero, it will not call the
* |func| for further entries and return the return value of the
* |func| immediately. Thus, this function returns 0 if all the
* invocations of the |func| return 0, or nonzero value which the last
* invocation of |func| returns.
*/
int nghttp3_map_each(const nghttp3_map *map, int (*func)(void *data, void *ptr),
void *ptr);
#ifndef WIN32
void nghttp3_map_print_distance(const nghttp3_map *map);
#endif /* !defined(WIN32) */
#endif /* !defined(NGHTTP3_MAP_H) */

124
deps/ngtcp2/nghttp3/lib/nghttp3_mem.c vendored Normal file
View File

@ -0,0 +1,124 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2014 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_mem.h"
#include <stdio.h>
static void *default_malloc(size_t size, void *user_data) {
(void)user_data;
return malloc(size);
}
static void default_free(void *ptr, void *user_data) {
(void)user_data;
free(ptr);
}
static void *default_calloc(size_t nmemb, size_t size, void *user_data) {
(void)user_data;
return calloc(nmemb, size);
}
static void *default_realloc(void *ptr, size_t size, void *user_data) {
(void)user_data;
return realloc(ptr, size);
}
static nghttp3_mem mem_default = {NULL, default_malloc, default_free,
default_calloc, default_realloc};
const nghttp3_mem *nghttp3_mem_default(void) { return &mem_default; }
#ifndef MEMDEBUG
void *nghttp3_mem_malloc(const nghttp3_mem *mem, size_t size) {
return mem->malloc(size, mem->user_data);
}
void nghttp3_mem_free(const nghttp3_mem *mem, void *ptr) {
mem->free(ptr, mem->user_data);
}
void *nghttp3_mem_calloc(const nghttp3_mem *mem, size_t nmemb, size_t size) {
return mem->calloc(nmemb, size, mem->user_data);
}
void *nghttp3_mem_realloc(const nghttp3_mem *mem, void *ptr, size_t size) {
return mem->realloc(ptr, size, mem->user_data);
}
#else /* defined(MEMDEBUG) */
void *nghttp3_mem_malloc_debug(const nghttp3_mem *mem, size_t size,
const char *func, const char *file,
size_t line) {
void *nptr = mem->malloc(size, mem->user_data);
fprintf(stderr, "malloc %p size=%zu in %s at %s:%zu\n", nptr, size, func,
file, line);
return nptr;
}
void nghttp3_mem_free_debug(const nghttp3_mem *mem, void *ptr, const char *func,
const char *file, size_t line) {
fprintf(stderr, "free ptr=%p in %s at %s:%zu\n", ptr, func, file, line);
mem->free(ptr, mem->user_data);
}
void nghttp3_mem_free2_debug(const nghttp3_free free_func, void *ptr,
void *user_data, const char *func,
const char *file, size_t line) {
fprintf(stderr, "free ptr=%p in %s at %s:%zu\n", ptr, func, file, line);
free_func(ptr, user_data);
}
void *nghttp3_mem_calloc_debug(const nghttp3_mem *mem, size_t nmemb,
size_t size, const char *func, const char *file,
size_t line) {
void *nptr = mem->calloc(nmemb, size, mem->user_data);
fprintf(stderr, "calloc %p nmemb=%zu size=%zu in %s at %s:%zu\n", nptr, nmemb,
size, func, file, line);
return nptr;
}
void *nghttp3_mem_realloc_debug(const nghttp3_mem *mem, void *ptr, size_t size,
const char *func, const char *file,
size_t line) {
void *nptr = mem->realloc(ptr, size, mem->user_data);
fprintf(stderr, "realloc %p ptr=%p size=%zu in %s at %s:%zu\n", nptr, ptr,
size, func, file, line);
return nptr;
}
#endif /* defined(MEMDEBUG) */

80
deps/ngtcp2/nghttp3/lib/nghttp3_mem.h vendored Normal file
View File

@ -0,0 +1,80 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2014 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_MEM_H
#define NGHTTP3_MEM_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
/* Convenient wrapper functions to call allocator function in
|mem|. */
#ifndef MEMDEBUG
void *nghttp3_mem_malloc(const nghttp3_mem *mem, size_t size);
void nghttp3_mem_free(const nghttp3_mem *mem, void *ptr);
void *nghttp3_mem_calloc(const nghttp3_mem *mem, size_t nmemb, size_t size);
void *nghttp3_mem_realloc(const nghttp3_mem *mem, void *ptr, size_t size);
#else /* defined(MEMDEBUG) */
void *nghttp3_mem_malloc_debug(const nghttp3_mem *mem, size_t size,
const char *func, const char *file, size_t line);
# define nghttp3_mem_malloc(MEM, SIZE) \
nghttp3_mem_malloc_debug((MEM), (SIZE), __func__, __FILE__, __LINE__)
void nghttp3_mem_free_debug(const nghttp3_mem *mem, void *ptr, const char *func,
const char *file, size_t line);
# define nghttp3_mem_free(MEM, PTR) \
nghttp3_mem_free_debug((MEM), (PTR), __func__, __FILE__, __LINE__)
void nghttp3_mem_free2_debug(nghttp3_free free_func, void *ptr, void *user_data,
const char *func, const char *file, size_t line);
# define nghttp3_mem_free2(FREE_FUNC, PTR, USER_DATA) \
nghttp3_mem_free2_debug((FREE_FUNC), (PTR), (USER_DATA), __func__, \
__FILE__, __LINE__)
void *nghttp3_mem_calloc_debug(const nghttp3_mem *mem, size_t nmemb,
size_t size, const char *func, const char *file,
size_t line);
# define nghttp3_mem_calloc(MEM, NMEMB, SIZE) \
nghttp3_mem_calloc_debug((MEM), (NMEMB), (SIZE), __func__, __FILE__, \
__LINE__)
void *nghttp3_mem_realloc_debug(const nghttp3_mem *mem, void *ptr, size_t size,
const char *func, const char *file,
size_t line);
# define nghttp3_mem_realloc(MEM, PTR, SIZE) \
nghttp3_mem_realloc_debug((MEM), (PTR), (SIZE), __func__, __FILE__, \
__LINE__)
#endif /* defined(MEMDEBUG) */
#endif /* !defined(NGHTTP3_MEM_H) */

View File

@ -0,0 +1,41 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_objalloc.h"
void nghttp3_objalloc_init(nghttp3_objalloc *objalloc, size_t blklen,
const nghttp3_mem *mem) {
nghttp3_balloc_init(&objalloc->balloc, blklen, mem);
nghttp3_opl_init(&objalloc->opl);
}
void nghttp3_objalloc_free(nghttp3_objalloc *objalloc) {
nghttp3_balloc_free(&objalloc->balloc);
}
void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc) {
nghttp3_opl_clear(&objalloc->opl);
nghttp3_balloc_clear(&objalloc->balloc);
}

View File

@ -0,0 +1,148 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_OBJALLOC_H
#define NGHTTP3_OBJALLOC_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_balloc.h"
#include "nghttp3_opl.h"
#include "nghttp3_macro.h"
#include "nghttp3_mem.h"
/*
* nghttp3_objalloc combines nghttp3_balloc and nghttp3_opl, and
* provides an object pool with the custom allocator to reduce the
* allocation and deallocation overheads for small objects.
*/
typedef struct nghttp3_objalloc {
nghttp3_balloc balloc;
nghttp3_opl opl;
} nghttp3_objalloc;
/*
* nghttp3_objalloc_init initializes |objalloc|. |blklen| is directly
* passed to nghttp3_balloc_init.
*/
void nghttp3_objalloc_init(nghttp3_objalloc *objalloc, size_t blklen,
const nghttp3_mem *mem);
/*
* nghttp3_objalloc_free releases all allocated resources.
*/
void nghttp3_objalloc_free(nghttp3_objalloc *objalloc);
/*
* nghttp3_objalloc_clear releases all allocated resources and
* initializes its state.
*/
void nghttp3_objalloc_clear(nghttp3_objalloc *objalloc);
#ifndef NOMEMPOOL
# define nghttp3_objalloc_decl(NAME, TYPE, OPLENTFIELD) \
inline static void nghttp3_objalloc_##NAME##_init( \
nghttp3_objalloc *objalloc, size_t nmemb, const nghttp3_mem *mem) { \
nghttp3_objalloc_init( \
objalloc, ((sizeof(TYPE) + 0xfu) & ~(uintptr_t)0xfu) * nmemb, mem); \
} \
\
TYPE *nghttp3_objalloc_##NAME##_get(nghttp3_objalloc *objalloc); \
\
TYPE *nghttp3_objalloc_##NAME##_len_get(nghttp3_objalloc *objalloc, \
size_t len); \
\
inline static void nghttp3_objalloc_##NAME##_release( \
nghttp3_objalloc *objalloc, TYPE *obj) { \
nghttp3_opl_push(&objalloc->opl, &obj->OPLENTFIELD); \
}
# define nghttp3_objalloc_def(NAME, TYPE, OPLENTFIELD) \
TYPE *nghttp3_objalloc_##NAME##_get(nghttp3_objalloc *objalloc) { \
nghttp3_opl_entry *oplent = nghttp3_opl_pop(&objalloc->opl); \
TYPE *obj; \
int rv; \
\
if (!oplent) { \
rv = \
nghttp3_balloc_get(&objalloc->balloc, (void **)&obj, sizeof(TYPE)); \
if (rv != 0) { \
return NULL; \
} \
\
return obj; \
} \
\
return nghttp3_struct_of(oplent, TYPE, OPLENTFIELD); \
} \
\
TYPE *nghttp3_objalloc_##NAME##_len_get(nghttp3_objalloc *objalloc, \
size_t len) { \
nghttp3_opl_entry *oplent = nghttp3_opl_pop(&objalloc->opl); \
TYPE *obj; \
int rv; \
\
if (!oplent) { \
rv = nghttp3_balloc_get(&objalloc->balloc, (void **)&obj, len); \
if (rv != 0) { \
return NULL; \
} \
\
return obj; \
} \
\
return nghttp3_struct_of(oplent, TYPE, OPLENTFIELD); \
}
#else /* defined(NOMEMPOOL) */
# define nghttp3_objalloc_decl(NAME, TYPE, OPLENTFIELD) \
inline static void nghttp3_objalloc_##NAME##_init( \
nghttp3_objalloc *objalloc, size_t nmemb, const nghttp3_mem *mem) { \
nghttp3_objalloc_init( \
objalloc, ((sizeof(TYPE) + 0xfu) & ~(uintptr_t)0xfu) * nmemb, mem); \
} \
\
inline static TYPE *nghttp3_objalloc_##NAME##_get( \
nghttp3_objalloc *objalloc) { \
return nghttp3_mem_malloc(objalloc->balloc.mem, sizeof(TYPE)); \
} \
\
inline static TYPE *nghttp3_objalloc_##NAME##_len_get( \
nghttp3_objalloc *objalloc, size_t len) { \
return nghttp3_mem_malloc(objalloc->balloc.mem, len); \
} \
\
inline static void nghttp3_objalloc_##NAME##_release( \
nghttp3_objalloc *objalloc, TYPE *obj) { \
nghttp3_mem_free(objalloc->balloc.mem, obj); \
}
# define nghttp3_objalloc_def(NAME, TYPE, OPLENTFIELD)
#endif /* defined(NOMEMPOOL) */
#endif /* !defined(NGHTTP3_OBJALLOC_H) */

47
deps/ngtcp2/nghttp3/lib/nghttp3_opl.c vendored Normal file
View File

@ -0,0 +1,47 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_opl.h"
void nghttp3_opl_init(nghttp3_opl *opl) { opl->head = NULL; }
void nghttp3_opl_push(nghttp3_opl *opl, nghttp3_opl_entry *ent) {
ent->next = opl->head;
opl->head = ent;
}
nghttp3_opl_entry *nghttp3_opl_pop(nghttp3_opl *opl) {
nghttp3_opl_entry *ent = opl->head;
if (!ent) {
return NULL;
}
opl->head = ent->next;
return ent;
}
void nghttp3_opl_clear(nghttp3_opl *opl) { opl->head = NULL; }

66
deps/ngtcp2/nghttp3/lib/nghttp3_opl.h vendored Normal file
View File

@ -0,0 +1,66 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_OPL_H
#define NGHTTP3_OPL_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
typedef struct nghttp3_opl_entry nghttp3_opl_entry;
struct nghttp3_opl_entry {
nghttp3_opl_entry *next;
};
/*
* nghttp3_opl is an object memory pool.
*/
typedef struct nghttp3_opl {
nghttp3_opl_entry *head;
} nghttp3_opl;
/*
* nghttp3_opl_init initializes |opl|.
*/
void nghttp3_opl_init(nghttp3_opl *opl);
/*
* nghttp3_opl_push inserts |ent| to |opl| head.
*/
void nghttp3_opl_push(nghttp3_opl *opl, nghttp3_opl_entry *ent);
/*
* nghttp3_opl_pop removes the first nghttp3_opl_entry from |opl| and
* returns it. If |opl| does not have any entry, it returns NULL.
*/
nghttp3_opl_entry *nghttp3_opl_pop(nghttp3_opl *opl);
void nghttp3_opl_clear(nghttp3_opl *opl);
#endif /* !defined(NGHTTP3_OPL_H) */

183
deps/ngtcp2/nghttp3/lib/nghttp3_pq.c vendored Normal file
View File

@ -0,0 +1,183 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2012 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_pq.h"
#include <assert.h>
#include "nghttp3_macro.h"
void nghttp3_pq_init(nghttp3_pq *pq, nghttp3_pq_less less,
const nghttp3_mem *mem) {
pq->q = NULL;
pq->mem = mem;
pq->length = 0;
pq->capacity = 0;
pq->less = less;
}
void nghttp3_pq_free(nghttp3_pq *pq) {
if (!pq) {
return;
}
nghttp3_mem_free(pq->mem, pq->q);
}
static void swap(nghttp3_pq *pq, size_t i, size_t j) {
nghttp3_pq_entry *a = pq->q[i];
nghttp3_pq_entry *b = pq->q[j];
pq->q[i] = b;
b->index = i;
pq->q[j] = a;
a->index = j;
}
static void bubble_up(nghttp3_pq *pq, size_t index) {
size_t parent;
while (index) {
parent = (index - 1) / 2;
if (!pq->less(pq->q[index], pq->q[parent])) {
return;
}
swap(pq, parent, index);
index = parent;
}
}
int nghttp3_pq_push(nghttp3_pq *pq, nghttp3_pq_entry *item) {
if (pq->capacity <= pq->length) {
void *nq;
size_t ncapacity;
ncapacity = nghttp3_max_size(4, pq->capacity * 2);
nq = nghttp3_mem_realloc(pq->mem, pq->q,
ncapacity * sizeof(nghttp3_pq_entry *));
if (nq == NULL) {
return NGHTTP3_ERR_NOMEM;
}
pq->capacity = ncapacity;
pq->q = nq;
}
pq->q[pq->length] = item;
item->index = pq->length;
++pq->length;
bubble_up(pq, item->index);
return 0;
}
nghttp3_pq_entry *nghttp3_pq_top(const nghttp3_pq *pq) {
assert(pq->length);
return pq->q[0];
}
static void bubble_down(nghttp3_pq *pq, size_t index) {
size_t i, j, minindex;
for (;;) {
j = index * 2 + 1;
minindex = index;
for (i = 0; i < 2; ++i, ++j) {
if (j >= pq->length) {
break;
}
if (pq->less(pq->q[j], pq->q[minindex])) {
minindex = j;
}
}
if (minindex == index) {
return;
}
swap(pq, index, minindex);
index = minindex;
}
}
void nghttp3_pq_pop(nghttp3_pq *pq) {
assert(pq->length);
pq->q[0] = pq->q[pq->length - 1];
pq->q[0]->index = 0;
--pq->length;
bubble_down(pq, 0);
}
void nghttp3_pq_remove(nghttp3_pq *pq, nghttp3_pq_entry *item) {
assert(pq->q[item->index] == item);
if (item->index == 0) {
nghttp3_pq_pop(pq);
return;
}
if (item->index == pq->length - 1) {
--pq->length;
return;
}
pq->q[item->index] = pq->q[pq->length - 1];
pq->q[item->index]->index = item->index;
--pq->length;
if (pq->less(item, pq->q[item->index])) {
bubble_down(pq, item->index);
} else {
bubble_up(pq, item->index);
}
}
int nghttp3_pq_empty(const nghttp3_pq *pq) { return pq->length == 0; }
size_t nghttp3_pq_size(const nghttp3_pq *pq) { return pq->length; }
int nghttp3_pq_each(const nghttp3_pq *pq, nghttp3_pq_item_cb fun, void *arg) {
size_t i;
if (pq->length == 0) {
return 0;
}
for (i = 0; i < pq->length; ++i) {
if ((*fun)(pq->q[i], arg)) {
return 1;
}
}
return 0;
}
void nghttp3_pq_clear(nghttp3_pq *pq) { pq->length = 0; }

137
deps/ngtcp2/nghttp3/lib/nghttp3_pq.h vendored Normal file
View File

@ -0,0 +1,137 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2012 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_PQ_H
#define NGHTTP3_PQ_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_mem.h"
/* Implementation of priority queue */
/* NGHTTP3_PQ_BAD_INDEX is the priority queue index which indicates
that an entry is not queued. Assigning this value to
nghttp3_pq_entry.index can check that the entry is queued or
not. */
#define NGHTTP3_PQ_BAD_INDEX SIZE_MAX
typedef struct nghttp3_pq_entry {
size_t index;
} nghttp3_pq_entry;
/* nghttp3_pq_less is a "less" function, that returns nonzero if |lhs|
is considered to be less than |rhs|. */
typedef int (*nghttp3_pq_less)(const nghttp3_pq_entry *lhs,
const nghttp3_pq_entry *rhs);
typedef struct nghttp3_pq {
/* q is a pointer to an array that stores the items. */
nghttp3_pq_entry **q;
/* mem is a memory allocator. */
const nghttp3_mem *mem;
/* length is the number of items stored. */
size_t length;
/* capacity is the maximum number of items this queue can store.
This is automatically extended when length is reached to this
limit. */
size_t capacity;
/* less is the less function to compare items. */
nghttp3_pq_less less;
} nghttp3_pq;
/*
* nghttp3_pq_init initializes |pq| with compare function |cmp|.
*/
void nghttp3_pq_init(nghttp3_pq *pq, nghttp3_pq_less less,
const nghttp3_mem *mem);
/*
* nghttp3_pq_free deallocates any resources allocated for |pq|. The
* stored items are not freed by this function.
*/
void nghttp3_pq_free(nghttp3_pq *pq);
/*
* nghttp3_pq_push adds |item| to |pq|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_pq_push(nghttp3_pq *pq, nghttp3_pq_entry *item);
/*
* nghttp3_pq_top returns item at the top of |pq|. It is undefined if
* |pq| is empty.
*/
nghttp3_pq_entry *nghttp3_pq_top(const nghttp3_pq *pq);
/*
* nghttp3_pq_pop pops item at the top of |pq|. The popped item is
* not freed by this function. It is undefined if |pq| is empty.
*/
void nghttp3_pq_pop(nghttp3_pq *pq);
/*
* nghttp3_pq_empty returns nonzero if |pq| is empty.
*/
int nghttp3_pq_empty(const nghttp3_pq *pq);
/*
* nghttp3_pq_size returns the number of items |pq| contains.
*/
size_t nghttp3_pq_size(const nghttp3_pq *pq);
typedef int (*nghttp3_pq_item_cb)(nghttp3_pq_entry *item, void *arg);
/*
* nghttp3_pq_each applies |fun| to each item in |pq|. The |arg| is
* passed as arg parameter to callback function. This function must
* not change the ordering key. If the return value from callback is
* nonzero, this function returns 1 immediately without iterating
* remaining items. Otherwise this function returns 0.
*/
int nghttp3_pq_each(const nghttp3_pq *pq, nghttp3_pq_item_cb fun, void *arg);
/*
* nghttp3_pq_remove removes |item| from |pq|. |pq| must contain
* |item| otherwise the behavior is undefined.
*/
void nghttp3_pq_remove(nghttp3_pq *pq, nghttp3_pq_entry *item);
/*
* nghttp3_pq_clear removes all items from |pq|.
*/
void nghttp3_pq_clear(nghttp3_pq *pq);
#endif /* !defined(NGHTTP3_PQ_H) */

4164
deps/ngtcp2/nghttp3/lib/nghttp3_qpack.c vendored Normal file

File diff suppressed because it is too large Load Diff

1010
deps/ngtcp2/nghttp3/lib/nghttp3_qpack.h vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,124 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2013 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_qpack_huffman.h"
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include "nghttp3_conv.h"
size_t nghttp3_qpack_huffman_encode_count(const uint8_t *src, size_t len) {
size_t i;
size_t nbits = 0;
for (i = 0; i < len; ++i) {
nbits += huffman_sym_table[src[i]].nbits;
}
/* pad the prefix of EOS (256) */
return (nbits + 7) / 8;
}
uint8_t *nghttp3_qpack_huffman_encode(uint8_t *dest, const uint8_t *src,
size_t srclen) {
const nghttp3_qpack_huffman_sym *sym;
const uint8_t *end = src + srclen;
uint64_t code = 0;
size_t nbits = 0;
uint32_t x;
for (; src != end;) {
sym = &huffman_sym_table[*src++];
code |= (uint64_t)sym->code << (32 - nbits);
nbits += sym->nbits;
if (nbits < 32) {
continue;
}
x = htonl((uint32_t)(code >> 32));
memcpy(dest, &x, 4);
dest += 4;
code <<= 32;
nbits -= 32;
}
for (; nbits >= 8;) {
*dest++ = (uint8_t)(code >> 56);
code <<= 8;
nbits -= 8;
}
if (nbits) {
*dest++ = (uint8_t)((uint8_t)(code >> 56) | ((1 << (8 - nbits)) - 1));
}
return dest;
}
void nghttp3_qpack_huffman_decode_context_init(
nghttp3_qpack_huffman_decode_context *ctx) {
ctx->fstate = NGHTTP3_QPACK_HUFFMAN_ACCEPTED;
}
nghttp3_ssize
nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx,
uint8_t *dest, const uint8_t *src, size_t srclen,
int fin) {
uint8_t *p = dest;
const uint8_t *end = src + srclen;
nghttp3_qpack_huffman_decode_node node = {ctx->fstate, 0};
const nghttp3_qpack_huffman_decode_node *t = &node;
uint8_t c;
/* We use the decoding algorithm described in
- http://graphics.ics.uci.edu/pub/Prefix.pdf [!!! NO LONGER VALID !!!]
- https://ics.uci.edu/~dan/pubs/Prefix.pdf
- https://github.com/nghttp2/nghttp2/files/15141264/Prefix.pdf */
for (; src != end;) {
c = *src++;
t = &qpack_huffman_decode_table[t->fstate & 0x1ff][c >> 4];
if (t->fstate & NGHTTP3_QPACK_HUFFMAN_SYM) {
*p++ = t->sym;
}
t = &qpack_huffman_decode_table[t->fstate & 0x1ff][c & 0xf];
if (t->fstate & NGHTTP3_QPACK_HUFFMAN_SYM) {
*p++ = t->sym;
}
}
ctx->fstate = t->fstate;
if (fin && !(ctx->fstate & NGHTTP3_QPACK_HUFFMAN_ACCEPTED)) {
return NGHTTP3_ERR_QPACK_FATAL;
}
return p - dest;
}
int nghttp3_qpack_huffman_decode_failure_state(
nghttp3_qpack_huffman_decode_context *ctx) {
return ctx->fstate == 0x100;
}

View File

@ -0,0 +1,108 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2013 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_QPACK_HUFFMAN_H
#define NGHTTP3_QPACK_HUFFMAN_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
typedef struct nghttp3_qpack_huffman_sym {
/* The number of bits in this code */
uint32_t nbits;
/* Huffman code aligned to LSB */
uint32_t code;
} nghttp3_qpack_huffman_sym;
extern const nghttp3_qpack_huffman_sym huffman_sym_table[];
size_t nghttp3_qpack_huffman_encode_count(const uint8_t *src, size_t len);
uint8_t *nghttp3_qpack_huffman_encode(uint8_t *dest, const uint8_t *src,
size_t srclen);
typedef enum nghttp3_qpack_huffman_decode_flag {
/* FSA accepts this state as the end of huffman encoding
sequence. */
NGHTTP3_QPACK_HUFFMAN_ACCEPTED = 1 << 14,
/* This state emits symbol */
NGHTTP3_QPACK_HUFFMAN_SYM = 1 << 15,
} nghttp3_qpack_huffman_decode_flag;
typedef struct nghttp3_qpack_huffman_decode_node {
/* fstate is the current huffman decoding state, which is actually
the node ID of internal huffman tree with
nghttp3_qpack_huffman_decode_flag OR-ed. We have 257 leaf nodes,
but they are identical to root node other than emitting a symbol,
so we have 256 internal nodes [1..256], inclusive. The node ID
256 is a special node and it is a terminal state that means
decoding failed. */
uint16_t fstate;
/* symbol if NGHTTP3_QPACK_HUFFMAN_SYM flag set */
uint8_t sym;
} nghttp3_qpack_huffman_decode_node;
typedef struct nghttp3_qpack_huffman_decode_context {
/* fstate is the current huffman decoding state. */
uint16_t fstate;
} nghttp3_qpack_huffman_decode_context;
extern const nghttp3_qpack_huffman_decode_node qpack_huffman_decode_table[][16];
void nghttp3_qpack_huffman_decode_context_init(
nghttp3_qpack_huffman_decode_context *ctx);
/*
* nghttp3_qpack_huffman_decode decodes huffman encoded byte string
* stored in |src| of length |srclen|. |ctx| is a decoding context.
* |ctx| remembers the decoding state, and caller can call this
* function multiple times to feed each chunk of huffman encoded
* substring. |fin| must be nonzero if |src| contains the last chunk
* of huffman string. The decoded string is written to the buffer
* pointed by |dest|. This function assumes that the buffer pointed
* by |dest| contains enough memory to store decoded byte string.
*
* This function returns the number of bytes written to |dest|, or one
* of the following negative error codes:
*
* NGHTTP3_ERR_QPACK_FATAL
* Could not decode huffman string.
*/
nghttp3_ssize
nghttp3_qpack_huffman_decode(nghttp3_qpack_huffman_decode_context *ctx,
uint8_t *dest, const uint8_t *src, size_t srclen,
int fin);
/*
* nghttp3_qpack_huffman_decode_failure_state returns nonzero if |ctx|
* indicates that huffman decoding context is in failure state.
*/
int nghttp3_qpack_huffman_decode_failure_state(
nghttp3_qpack_huffman_decode_context *ctx);
#endif /* !defined(NGHTTP3_QPACK_HUFFMAN_H) */

File diff suppressed because it is too large Load Diff

64
deps/ngtcp2/nghttp3/lib/nghttp3_range.c vendored Normal file
View File

@ -0,0 +1,64 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_range.h"
#include "nghttp3_macro.h"
void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end) {
r->begin = begin;
r->end = end;
}
nghttp3_range nghttp3_range_intersect(const nghttp3_range *a,
const nghttp3_range *b) {
nghttp3_range r = {0, 0};
uint64_t begin = nghttp3_max_uint64(a->begin, b->begin);
uint64_t end = nghttp3_min_uint64(a->end, b->end);
if (begin < end) {
nghttp3_range_init(&r, begin, end);
}
return r;
}
uint64_t nghttp3_range_len(const nghttp3_range *r) { return r->end - r->begin; }
int nghttp3_range_eq(const nghttp3_range *a, const nghttp3_range *b) {
return a->begin == b->begin && a->end == b->end;
}
void nghttp3_range_cut(nghttp3_range *left, nghttp3_range *right,
const nghttp3_range *a, const nghttp3_range *b) {
/* Assume that b is included in a */
left->begin = a->begin;
left->end = b->begin;
right->begin = b->end;
right->end = a->end;
}
int nghttp3_range_not_after(const nghttp3_range *a, const nghttp3_range *b) {
return a->end <= b->end;
}

81
deps/ngtcp2/nghttp3/lib/nghttp3_range.h vendored Normal file
View File

@ -0,0 +1,81 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_RANGE_H
#define NGHTTP3_RANGE_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
/*
* nghttp3_range represents half-closed range [begin, end).
*/
typedef struct nghttp3_range {
uint64_t begin;
uint64_t end;
} nghttp3_range;
/*
* nghttp3_range_init initializes |r| with the range [|begin|, |end|).
*/
void nghttp3_range_init(nghttp3_range *r, uint64_t begin, uint64_t end);
/*
* nghttp3_range_intersect returns the intersection of |a| and |b|.
* If they do not overlap, it returns empty range.
*/
nghttp3_range nghttp3_range_intersect(const nghttp3_range *a,
const nghttp3_range *b);
/*
* nghttp3_range_len returns the length of |r|.
*/
uint64_t nghttp3_range_len(const nghttp3_range *r);
/*
* nghttp3_range_eq returns nonzero if |a| equals |b|, such that
* a->begin == b->begin and a->end == b->end hold.
*/
int nghttp3_range_eq(const nghttp3_range *a, const nghttp3_range *b);
/*
* nghttp3_range_cut returns the left and right range after removing
* |b| from |a|. This function assumes that |a| completely includes
* |b|. In other words, a->begin <= b->begin and b->end <= a->end
* hold.
*/
void nghttp3_range_cut(nghttp3_range *left, nghttp3_range *right,
const nghttp3_range *a, const nghttp3_range *b);
/*
* nghttp3_range_not_after returns nonzero if the right edge of |a|
* does not go beyond of the right edge of |b|.
*/
int nghttp3_range_not_after(const nghttp3_range *a, const nghttp3_range *b);
#endif /* !defined(NGHTTP3_RANGE_H) */

108
deps/ngtcp2/nghttp3/lib/nghttp3_rcbuf.c vendored Normal file
View File

@ -0,0 +1,108 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2016 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_rcbuf.h"
#include <assert.h>
#include "nghttp3_mem.h"
#include "nghttp3_str.h"
int nghttp3_rcbuf_new(nghttp3_rcbuf **rcbuf_ptr, size_t size,
const nghttp3_mem *mem) {
uint8_t *p;
p = nghttp3_mem_malloc(mem, sizeof(nghttp3_rcbuf) + size);
if (p == NULL) {
return NGHTTP3_ERR_NOMEM;
}
*rcbuf_ptr = (void *)p;
(*rcbuf_ptr)->mem = mem;
(*rcbuf_ptr)->base = p + sizeof(nghttp3_rcbuf);
(*rcbuf_ptr)->len = size;
(*rcbuf_ptr)->ref = 1;
return 0;
}
int nghttp3_rcbuf_new2(nghttp3_rcbuf **rcbuf_ptr, const uint8_t *src,
size_t srclen, const nghttp3_mem *mem) {
int rv;
uint8_t *p;
rv = nghttp3_rcbuf_new(rcbuf_ptr, srclen + 1, mem);
if (rv != 0) {
return rv;
}
(*rcbuf_ptr)->len = srclen;
p = (*rcbuf_ptr)->base;
if (srclen) {
p = nghttp3_cpymem(p, src, srclen);
}
*p = '\0';
return 0;
}
/*
* Frees |rcbuf| itself, regardless of its reference cout.
*/
void nghttp3_rcbuf_del(nghttp3_rcbuf *rcbuf) {
nghttp3_mem_free(rcbuf->mem, rcbuf);
}
void nghttp3_rcbuf_incref(nghttp3_rcbuf *rcbuf) {
if (rcbuf->ref == -1) {
return;
}
++rcbuf->ref;
}
void nghttp3_rcbuf_decref(nghttp3_rcbuf *rcbuf) {
if (rcbuf == NULL || rcbuf->ref == -1) {
return;
}
assert(rcbuf->ref > 0);
if (--rcbuf->ref == 0) {
nghttp3_rcbuf_del(rcbuf);
}
}
nghttp3_vec nghttp3_rcbuf_get_buf(const nghttp3_rcbuf *rcbuf) {
nghttp3_vec res = {rcbuf->base, rcbuf->len};
return res;
}
int nghttp3_rcbuf_is_static(const nghttp3_rcbuf *rcbuf) {
return rcbuf->ref == -1;
}

81
deps/ngtcp2/nghttp3/lib/nghttp3_rcbuf.h vendored Normal file
View File

@ -0,0 +1,81 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2016 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_RCBUF_H
#define NGHTTP3_RCBUF_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
struct nghttp3_rcbuf {
/* mem is the memory allocator that allocates memory for this
object. */
const nghttp3_mem *mem;
/* The pointer to the underlying buffer */
uint8_t *base;
/* Size of buffer pointed by |base|. */
size_t len;
/* Reference count */
int32_t ref;
};
/*
* Allocates nghttp3_rcbuf object with |size| as initial buffer size.
* When the function succeeds, the reference count becomes 1.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM:
* Out of memory.
*/
int nghttp3_rcbuf_new(nghttp3_rcbuf **rcbuf_ptr, size_t size,
const nghttp3_mem *mem);
/*
* Like nghttp3_rcbuf_new(), but initializes the buffer with |src| of
* length |srclen|. This function allocates additional byte at the
* end and puts '\0' into it, so that the resulting buffer could be
* used as NULL-terminated string. Still (*rcbuf_ptr)->len equals to
* |srclen|.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM:
* Out of memory.
*/
int nghttp3_rcbuf_new2(nghttp3_rcbuf **rcbuf_ptr, const uint8_t *src,
size_t srclen, const nghttp3_mem *mem);
/*
* Frees |rcbuf| itself, regardless of its reference cout.
*/
void nghttp3_rcbuf_del(nghttp3_rcbuf *rcbuf);
#endif /* !defined(NGHTTP3_RCBUF_H) */

View File

@ -0,0 +1,154 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_ringbuf.h"
#include <assert.h>
#include <string.h>
#ifdef WIN32
# include <intrin.h>
#endif /* defined(WIN32) */
#include "nghttp3_macro.h"
static int ispow2(size_t n) {
#if defined(_MSC_VER) && !defined(__clang__) && \
(defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941))
return n && !(n & (n - 1));
#elif defined(WIN32)
return 1 == __popcnt((unsigned int)n);
#else /* !((defined(_MSC_VER) && !defined(__clang__) && (defined(_M_ARM) || \
(defined(_M_ARM64) && _MSC_VER < 1941))) || defined(WIN32)) */
return 1 == __builtin_popcount((unsigned int)n);
#endif /* !((defined(_MSC_VER) && !defined(__clang__) && (defined(_M_ARM) || \
(defined(_M_ARM64) && _MSC_VER < 1941))) || defined(WIN32)) */
}
int nghttp3_ringbuf_init(nghttp3_ringbuf *rb, size_t nmemb, size_t size,
const nghttp3_mem *mem) {
if (nmemb) {
assert(ispow2(nmemb));
rb->buf = nghttp3_mem_malloc(mem, nmemb * size);
if (rb->buf == NULL) {
return NGHTTP3_ERR_NOMEM;
}
} else {
rb->buf = NULL;
}
rb->mem = mem;
rb->nmemb = nmemb;
rb->size = size;
rb->first = 0;
rb->len = 0;
return 0;
}
void nghttp3_ringbuf_free(nghttp3_ringbuf *rb) {
if (rb == NULL) {
return;
}
nghttp3_mem_free(rb->mem, rb->buf);
}
void *nghttp3_ringbuf_push_front(nghttp3_ringbuf *rb) {
rb->first = (rb->first - 1) & (rb->nmemb - 1);
rb->len = nghttp3_min_size(rb->nmemb, rb->len + 1);
return (void *)&rb->buf[rb->first * rb->size];
}
void *nghttp3_ringbuf_push_back(nghttp3_ringbuf *rb) {
size_t offset = (rb->first + rb->len) & (rb->nmemb - 1);
if (rb->len == rb->nmemb) {
rb->first = (rb->first + 1) & (rb->nmemb - 1);
} else {
++rb->len;
}
return (void *)&rb->buf[offset * rb->size];
}
void nghttp3_ringbuf_pop_front(nghttp3_ringbuf *rb) {
rb->first = (rb->first + 1) & (rb->nmemb - 1);
--rb->len;
}
void nghttp3_ringbuf_pop_back(nghttp3_ringbuf *rb) {
assert(rb->len);
--rb->len;
}
void nghttp3_ringbuf_resize(nghttp3_ringbuf *rb, size_t len) {
assert(len <= rb->nmemb);
rb->len = len;
}
void *nghttp3_ringbuf_get(nghttp3_ringbuf *rb, size_t offset) {
assert(offset < rb->len);
offset = (rb->first + offset) & (rb->nmemb - 1);
return &rb->buf[offset * rb->size];
}
int nghttp3_ringbuf_full(nghttp3_ringbuf *rb) { return rb->len == rb->nmemb; }
int nghttp3_ringbuf_reserve(nghttp3_ringbuf *rb, size_t nmemb) {
uint8_t *buf;
if (rb->nmemb >= nmemb) {
return 0;
}
assert(ispow2(nmemb));
buf = nghttp3_mem_malloc(rb->mem, nmemb * rb->size);
if (buf == NULL) {
return NGHTTP3_ERR_NOMEM;
}
if (rb->buf != NULL) {
if (rb->first + rb->len <= rb->nmemb) {
memcpy(buf, rb->buf + rb->first * rb->size, rb->len * rb->size);
rb->first = 0;
} else {
memcpy(buf, rb->buf + rb->first * rb->size,
(rb->nmemb - rb->first) * rb->size);
memcpy(buf + (rb->nmemb - rb->first) * rb->size, rb->buf,
(rb->len - (rb->nmemb - rb->first)) * rb->size);
rb->first = 0;
}
nghttp3_mem_free(rb->mem, rb->buf);
}
rb->buf = buf;
rb->nmemb = nmemb;
return 0;
}

View File

@ -0,0 +1,113 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_RINGBUF_H
#define NGHTTP3_RINGBUF_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_mem.h"
typedef struct nghttp3_ringbuf {
/* buf points to the underlying buffer. */
uint8_t *buf;
const nghttp3_mem *mem;
/* nmemb is the number of elements that can be stored in this ring
buffer. */
size_t nmemb;
/* size is the size of each element. */
size_t size;
/* first is the offset to the first element. */
size_t first;
/* len is the number of elements actually stored. */
size_t len;
} nghttp3_ringbuf;
/*
* nghttp3_ringbuf_init initializes |rb|. |nmemb| is the number of
* elements that can be stored in this buffer. |size| is the size of
* each element. |size| must be power of 2.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* NGHTTP3_ERR_NOMEM
* Out of memory.
*/
int nghttp3_ringbuf_init(nghttp3_ringbuf *rb, size_t nmemb, size_t size,
const nghttp3_mem *mem);
/*
* nghttp3_ringbuf_free frees resources allocated for |rb|. This
* function does not free the memory pointed by |rb|.
*/
void nghttp3_ringbuf_free(nghttp3_ringbuf *rb);
/* nghttp3_ringbuf_push_front moves the offset to the first element in
the buffer backward, and returns the pointer to the element.
Caller can store data to the buffer pointed by the returned
pointer. If this action exceeds the capacity of the ring buffer,
the last element is silently overwritten, and rb->len remains
unchanged. */
void *nghttp3_ringbuf_push_front(nghttp3_ringbuf *rb);
/* nghttp3_ringbuf_push_back moves the offset to the last element in
the buffer forward, and returns the pointer to the element. Caller
can store data to the buffer pointed by the returned pointer. If
this action exceeds the capacity of the ring buffer, the first
element is silently overwritten, and rb->len remains unchanged. */
void *nghttp3_ringbuf_push_back(nghttp3_ringbuf *rb);
/*
* nghttp3_ringbuf_pop_front removes first element in |rb|.
*/
void nghttp3_ringbuf_pop_front(nghttp3_ringbuf *rb);
/*
* nghttp3_ringbuf_pop_back removes the last element in |rb|.
*/
void nghttp3_ringbuf_pop_back(nghttp3_ringbuf *rb);
/* nghttp3_ringbuf_resize changes the number of elements stored. This
does not change the capacity of the underlying buffer. */
void nghttp3_ringbuf_resize(nghttp3_ringbuf *rb, size_t len);
/* nghttp3_ringbuf_get returns the pointer to the element at
|offset|. */
void *nghttp3_ringbuf_get(nghttp3_ringbuf *rb, size_t offset);
/* nghttp3_ringbuf_len returns the number of elements stored. */
#define nghttp3_ringbuf_len(RB) ((RB)->len)
/* nghttp3_ringbuf_full returns nonzero if |rb| is full. */
int nghttp3_ringbuf_full(nghttp3_ringbuf *rb);
int nghttp3_ringbuf_reserve(nghttp3_ringbuf *rb, size_t nmemb);
#endif /* !defined(NGHTTP3_RINGBUF_H) */

110
deps/ngtcp2/nghttp3/lib/nghttp3_str.c vendored Normal file
View File

@ -0,0 +1,110 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2012 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_str.h"
#include <string.h>
#include <assert.h>
uint8_t *nghttp3_cpymem(uint8_t *dest, const uint8_t *src, size_t n) {
memcpy(dest, src, n);
return dest + n;
}
/* Generated by gendowncasetbl.py */
static const uint8_t DOWNCASE_TBL[] = {
0 /* NUL */, 1 /* SOH */, 2 /* STX */, 3 /* ETX */,
4 /* EOT */, 5 /* ENQ */, 6 /* ACK */, 7 /* BEL */,
8 /* BS */, 9 /* HT */, 10 /* LF */, 11 /* VT */,
12 /* FF */, 13 /* CR */, 14 /* SO */, 15 /* SI */,
16 /* DLE */, 17 /* DC1 */, 18 /* DC2 */, 19 /* DC3 */,
20 /* DC4 */, 21 /* NAK */, 22 /* SYN */, 23 /* ETB */,
24 /* CAN */, 25 /* EM */, 26 /* SUB */, 27 /* ESC */,
28 /* FS */, 29 /* GS */, 30 /* RS */, 31 /* US */,
32 /* SPC */, 33 /* ! */, 34 /* " */, 35 /* # */,
36 /* $ */, 37 /* % */, 38 /* & */, 39 /* ' */,
40 /* ( */, 41 /* ) */, 42 /* * */, 43 /* + */,
44 /* , */, 45 /* - */, 46 /* . */, 47 /* / */,
48 /* 0 */, 49 /* 1 */, 50 /* 2 */, 51 /* 3 */,
52 /* 4 */, 53 /* 5 */, 54 /* 6 */, 55 /* 7 */,
56 /* 8 */, 57 /* 9 */, 58 /* : */, 59 /* ; */,
60 /* < */, 61 /* = */, 62 /* > */, 63 /* ? */,
64 /* @ */, 97 /* A */, 98 /* B */, 99 /* C */,
100 /* D */, 101 /* E */, 102 /* F */, 103 /* G */,
104 /* H */, 105 /* I */, 106 /* J */, 107 /* K */,
108 /* L */, 109 /* M */, 110 /* N */, 111 /* O */,
112 /* P */, 113 /* Q */, 114 /* R */, 115 /* S */,
116 /* T */, 117 /* U */, 118 /* V */, 119 /* W */,
120 /* X */, 121 /* Y */, 122 /* Z */, 91 /* [ */,
92 /* \ */, 93 /* ] */, 94 /* ^ */, 95 /* _ */,
96 /* ` */, 97 /* a */, 98 /* b */, 99 /* c */,
100 /* d */, 101 /* e */, 102 /* f */, 103 /* g */,
104 /* h */, 105 /* i */, 106 /* j */, 107 /* k */,
108 /* l */, 109 /* m */, 110 /* n */, 111 /* o */,
112 /* p */, 113 /* q */, 114 /* r */, 115 /* s */,
116 /* t */, 117 /* u */, 118 /* v */, 119 /* w */,
120 /* x */, 121 /* y */, 122 /* z */, 123 /* { */,
124 /* | */, 125 /* } */, 126 /* ~ */, 127 /* DEL */,
128 /* 0x80 */, 129 /* 0x81 */, 130 /* 0x82 */, 131 /* 0x83 */,
132 /* 0x84 */, 133 /* 0x85 */, 134 /* 0x86 */, 135 /* 0x87 */,
136 /* 0x88 */, 137 /* 0x89 */, 138 /* 0x8a */, 139 /* 0x8b */,
140 /* 0x8c */, 141 /* 0x8d */, 142 /* 0x8e */, 143 /* 0x8f */,
144 /* 0x90 */, 145 /* 0x91 */, 146 /* 0x92 */, 147 /* 0x93 */,
148 /* 0x94 */, 149 /* 0x95 */, 150 /* 0x96 */, 151 /* 0x97 */,
152 /* 0x98 */, 153 /* 0x99 */, 154 /* 0x9a */, 155 /* 0x9b */,
156 /* 0x9c */, 157 /* 0x9d */, 158 /* 0x9e */, 159 /* 0x9f */,
160 /* 0xa0 */, 161 /* 0xa1 */, 162 /* 0xa2 */, 163 /* 0xa3 */,
164 /* 0xa4 */, 165 /* 0xa5 */, 166 /* 0xa6 */, 167 /* 0xa7 */,
168 /* 0xa8 */, 169 /* 0xa9 */, 170 /* 0xaa */, 171 /* 0xab */,
172 /* 0xac */, 173 /* 0xad */, 174 /* 0xae */, 175 /* 0xaf */,
176 /* 0xb0 */, 177 /* 0xb1 */, 178 /* 0xb2 */, 179 /* 0xb3 */,
180 /* 0xb4 */, 181 /* 0xb5 */, 182 /* 0xb6 */, 183 /* 0xb7 */,
184 /* 0xb8 */, 185 /* 0xb9 */, 186 /* 0xba */, 187 /* 0xbb */,
188 /* 0xbc */, 189 /* 0xbd */, 190 /* 0xbe */, 191 /* 0xbf */,
192 /* 0xc0 */, 193 /* 0xc1 */, 194 /* 0xc2 */, 195 /* 0xc3 */,
196 /* 0xc4 */, 197 /* 0xc5 */, 198 /* 0xc6 */, 199 /* 0xc7 */,
200 /* 0xc8 */, 201 /* 0xc9 */, 202 /* 0xca */, 203 /* 0xcb */,
204 /* 0xcc */, 205 /* 0xcd */, 206 /* 0xce */, 207 /* 0xcf */,
208 /* 0xd0 */, 209 /* 0xd1 */, 210 /* 0xd2 */, 211 /* 0xd3 */,
212 /* 0xd4 */, 213 /* 0xd5 */, 214 /* 0xd6 */, 215 /* 0xd7 */,
216 /* 0xd8 */, 217 /* 0xd9 */, 218 /* 0xda */, 219 /* 0xdb */,
220 /* 0xdc */, 221 /* 0xdd */, 222 /* 0xde */, 223 /* 0xdf */,
224 /* 0xe0 */, 225 /* 0xe1 */, 226 /* 0xe2 */, 227 /* 0xe3 */,
228 /* 0xe4 */, 229 /* 0xe5 */, 230 /* 0xe6 */, 231 /* 0xe7 */,
232 /* 0xe8 */, 233 /* 0xe9 */, 234 /* 0xea */, 235 /* 0xeb */,
236 /* 0xec */, 237 /* 0xed */, 238 /* 0xee */, 239 /* 0xef */,
240 /* 0xf0 */, 241 /* 0xf1 */, 242 /* 0xf2 */, 243 /* 0xf3 */,
244 /* 0xf4 */, 245 /* 0xf5 */, 246 /* 0xf6 */, 247 /* 0xf7 */,
248 /* 0xf8 */, 249 /* 0xf9 */, 250 /* 0xfa */, 251 /* 0xfb */,
252 /* 0xfc */, 253 /* 0xfd */, 254 /* 0xfe */, 255 /* 0xff */,
};
void nghttp3_downcase(uint8_t *s, size_t len) {
size_t i;
for (i = 0; i < len; ++i) {
s[i] = DOWNCASE_TBL[s[i]];
}
}

40
deps/ngtcp2/nghttp3/lib/nghttp3_str.h vendored Normal file
View File

@ -0,0 +1,40 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2017 ngtcp2 contributors
* Copyright (c) 2012 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_STR_H
#define NGHTTP3_STR_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
uint8_t *nghttp3_cpymem(uint8_t *dest, const uint8_t *src, size_t n);
void nghttp3_downcase(uint8_t *s, size_t len);
#endif /* !defined(NGHTTP3_STR_H) */

1247
deps/ngtcp2/nghttp3/lib/nghttp3_stream.c vendored Normal file

File diff suppressed because it is too large Load Diff

397
deps/ngtcp2/nghttp3/lib/nghttp3_stream.h vendored Normal file
View File

@ -0,0 +1,397 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_STREAM_H
#define NGHTTP3_STREAM_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_map.h"
#include "nghttp3_tnode.h"
#include "nghttp3_ringbuf.h"
#include "nghttp3_buf.h"
#include "nghttp3_frame.h"
#include "nghttp3_qpack.h"
#include "nghttp3_objalloc.h"
#define NGHTTP3_STREAM_MIN_CHUNK_SIZE 256
/* NGHTTP3_MIN_UNSENT_BYTES is the minimum unsent bytes which is large
enough to fill outgoing single QUIC packet. */
#define NGHTTP3_MIN_UNSENT_BYTES 4096
/* NGHTTP3_STREAM_MIN_WRITELEN is the minimum length of write to cause
the stream to reschedule. */
#define NGHTTP3_STREAM_MIN_WRITELEN 800
/* nghttp3_stream_type is unidirectional stream type. */
typedef uint64_t nghttp3_stream_type;
#define NGHTTP3_STREAM_TYPE_CONTROL 0x00
#define NGHTTP3_STREAM_TYPE_PUSH 0x01
#define NGHTTP3_STREAM_TYPE_QPACK_ENCODER 0x02
#define NGHTTP3_STREAM_TYPE_QPACK_DECODER 0x03
#define NGHTTP3_STREAM_TYPE_UNKNOWN UINT64_MAX
typedef enum nghttp3_ctrl_stream_state {
NGHTTP3_CTRL_STREAM_STATE_FRAME_TYPE,
NGHTTP3_CTRL_STREAM_STATE_FRAME_LENGTH,
NGHTTP3_CTRL_STREAM_STATE_SETTINGS,
NGHTTP3_CTRL_STREAM_STATE_GOAWAY,
NGHTTP3_CTRL_STREAM_STATE_MAX_PUSH_ID,
NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME,
NGHTTP3_CTRL_STREAM_STATE_SETTINGS_ID,
NGHTTP3_CTRL_STREAM_STATE_SETTINGS_VALUE,
NGHTTP3_CTRL_STREAM_STATE_PRIORITY_UPDATE_PRI_ELEM_ID,
NGHTTP3_CTRL_STREAM_STATE_PRIORITY_UPDATE,
} nghttp3_ctrl_stream_state;
typedef enum nghttp3_req_stream_state {
NGHTTP3_REQ_STREAM_STATE_FRAME_TYPE,
NGHTTP3_REQ_STREAM_STATE_FRAME_LENGTH,
NGHTTP3_REQ_STREAM_STATE_DATA,
NGHTTP3_REQ_STREAM_STATE_HEADERS,
NGHTTP3_REQ_STREAM_STATE_IGN_FRAME,
NGHTTP3_REQ_STREAM_STATE_IGN_REST,
} nghttp3_req_stream_state;
typedef struct nghttp3_varint_read_state {
int64_t acc;
size_t left;
} nghttp3_varint_read_state;
typedef struct nghttp3_stream_read_state {
nghttp3_varint_read_state rvint;
nghttp3_frame fr;
int64_t left;
int state;
} nghttp3_stream_read_state;
/* NGHTTP3_STREAM_FLAG_NONE indicates that no flag is set. */
#define NGHTTP3_STREAM_FLAG_NONE 0x0000u
/* NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED is set when a unidirectional
stream type is identified. */
#define NGHTTP3_STREAM_FLAG_TYPE_IDENTIFIED 0x0001u
/* NGHTTP3_STREAM_FLAG_FC_BLOCKED indicates that stream is blocked by
QUIC flow control. */
#define NGHTTP3_STREAM_FLAG_FC_BLOCKED 0x0002u
/* NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED indicates that application is
temporarily unable to provide data. */
#define NGHTTP3_STREAM_FLAG_READ_DATA_BLOCKED 0x0004u
/* NGHTTP3_STREAM_FLAG_WRITE_END_STREAM indicates that application
finished to feed outgoing data. */
#define NGHTTP3_STREAM_FLAG_WRITE_END_STREAM 0x0008u
/* NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED indicates that stream is
blocked due to QPACK decoding. */
#define NGHTTP3_STREAM_FLAG_QPACK_DECODE_BLOCKED 0x0010u
/* NGHTTP3_STREAM_FLAG_READ_EOF indicates that remote endpoint sent
fin. */
#define NGHTTP3_STREAM_FLAG_READ_EOF 0x0020u
/* NGHTTP3_STREAM_FLAG_CLOSED indicates that QUIC stream was closed.
nghttp3_stream object can still alive because it might be blocked
by QPACK decoder. */
#define NGHTTP3_STREAM_FLAG_CLOSED 0x0040u
/* NGHTTP3_STREAM_FLAG_SHUT_WR indicates that any further write
operation to a stream is prohibited. */
#define NGHTTP3_STREAM_FLAG_SHUT_WR 0x0100u
/* NGHTTP3_STREAM_FLAG_SHUT_RD indicates that a read-side stream is
closed abruptly and any incoming and pending stream data is just
discarded for a stream. */
#define NGHTTP3_STREAM_FLAG_SHUT_RD 0x0200u
/* NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET indicates that server
overrides stream priority. */
#define NGHTTP3_STREAM_FLAG_SERVER_PRIORITY_SET 0x0400u
/* NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED indicates that server
received PRIORITY_UPDATE frame for this stream. */
#define NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED 0x0800u
/* NGHTTP3_STREAM_FLAG_HTTP_ERROR indicates that
NGHTTP3_ERR_MALFORMED_HTTP_HEADER error is encountered while
processing incoming HTTP fields. */
#define NGHTTP3_STREAM_FLAG_HTTP_ERROR 0x1000u
typedef enum nghttp3_stream_http_state {
NGHTTP3_HTTP_STATE_NONE,
NGHTTP3_HTTP_STATE_REQ_INITIAL,
NGHTTP3_HTTP_STATE_REQ_BEGIN,
NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN,
NGHTTP3_HTTP_STATE_REQ_HEADERS_END,
NGHTTP3_HTTP_STATE_REQ_DATA_BEGIN,
NGHTTP3_HTTP_STATE_REQ_DATA_END,
NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN,
NGHTTP3_HTTP_STATE_REQ_TRAILERS_END,
NGHTTP3_HTTP_STATE_REQ_END,
NGHTTP3_HTTP_STATE_RESP_INITIAL,
NGHTTP3_HTTP_STATE_RESP_BEGIN,
NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN,
NGHTTP3_HTTP_STATE_RESP_HEADERS_END,
NGHTTP3_HTTP_STATE_RESP_DATA_BEGIN,
NGHTTP3_HTTP_STATE_RESP_DATA_END,
NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN,
NGHTTP3_HTTP_STATE_RESP_TRAILERS_END,
NGHTTP3_HTTP_STATE_RESP_END,
} nghttp3_stream_http_state;
typedef enum nghttp3_stream_http_event {
NGHTTP3_HTTP_EVENT_DATA_BEGIN,
NGHTTP3_HTTP_EVENT_DATA_END,
NGHTTP3_HTTP_EVENT_HEADERS_BEGIN,
NGHTTP3_HTTP_EVENT_HEADERS_END,
NGHTTP3_HTTP_EVENT_MSG_END,
} nghttp3_stream_http_event;
typedef struct nghttp3_stream nghttp3_stream;
/*
* nghttp3_stream_acked_data is a callback function which is invoked
* when data sent on stream denoted by |stream_id| supplied from
* application is acknowledged by remote endpoint. The number of
* bytes acknowledged is given in |datalen|.
*
* The implementation of this callback must return 0 if it succeeds.
* Returning NGHTTP3_ERR_CALLBACK_FAILURE will return to the caller
* immediately. Any values other than 0 is treated as
* NGHTTP3_ERR_CALLBACK_FAILURE.
*/
typedef int (*nghttp3_stream_acked_data)(nghttp3_stream *stream,
int64_t stream_id, uint64_t datalen,
void *user_data);
typedef struct nghttp3_stream_callbacks {
nghttp3_stream_acked_data acked_data;
} nghttp3_stream_callbacks;
typedef struct nghttp3_http_state {
/* content_length is the value of received content-length header
field. */
int64_t content_length;
/* recv_content_length is the number of body bytes received so
far. */
int64_t recv_content_length;
nghttp3_pri pri;
/* status_code is HTTP status code received. This field is used
if connection is initialized as client. */
int32_t status_code;
uint32_t flags;
} nghttp3_http_state;
struct nghttp3_stream {
union {
struct {
const nghttp3_mem *mem;
nghttp3_objalloc *out_chunk_objalloc;
nghttp3_objalloc *stream_objalloc;
nghttp3_tnode node;
nghttp3_pq_entry qpack_blocked_pe;
nghttp3_stream_callbacks callbacks;
nghttp3_ringbuf frq;
nghttp3_ringbuf chunks;
nghttp3_ringbuf outq;
/* inq stores the stream raw data which cannot be read because
stream is blocked by QPACK decoder. */
nghttp3_ringbuf inq;
nghttp3_qpack_stream_context qpack_sctx;
/* conn is a reference to underlying connection. It could be NULL
if stream is not a request stream. */
nghttp3_conn *conn;
void *user_data;
/* unsent_bytes is the number of bytes in outq not written yet */
uint64_t unsent_bytes;
/* outq_idx is an index into outq where next write is made. */
size_t outq_idx;
/* outq_offset is write offset relative to the element at outq_idx
in outq. */
uint64_t outq_offset;
/* ack_base is the number of bytes acknowledged by a remote
endpoint where the first element in outq is positioned at. */
uint64_t ack_base;
/* ack_offset is the number of bytes acknowledged by a remote
endpoint so far. */
uint64_t ack_offset;
uint64_t unscheduled_nwrite;
nghttp3_stream_type type;
nghttp3_stream_read_state rstate;
/* error_code indicates the reason of closure of this stream. */
uint64_t error_code;
struct {
uint64_t offset;
nghttp3_stream_http_state hstate;
} tx;
struct {
nghttp3_stream_http_state hstate;
nghttp3_http_state http;
} rx;
uint16_t flags;
};
nghttp3_opl_entry oplent;
};
};
nghttp3_objalloc_decl(stream, nghttp3_stream, oplent);
typedef struct nghttp3_frame_entry {
nghttp3_frame fr;
union {
struct {
nghttp3_settings *local_settings;
} settings;
struct {
nghttp3_data_reader dr;
} data;
} aux;
} nghttp3_frame_entry;
int nghttp3_stream_new(nghttp3_stream **pstream, int64_t stream_id,
const nghttp3_stream_callbacks *callbacks,
nghttp3_objalloc *out_chunk_objalloc,
nghttp3_objalloc *stream_objalloc,
const nghttp3_mem *mem);
void nghttp3_stream_del(nghttp3_stream *stream);
void nghttp3_varint_read_state_reset(nghttp3_varint_read_state *rvint);
void nghttp3_stream_read_state_reset(nghttp3_stream_read_state *rstate);
nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint,
const uint8_t *begin, const uint8_t *end,
int fin);
int nghttp3_stream_frq_add(nghttp3_stream *stream,
const nghttp3_frame_entry *frent);
int nghttp3_stream_fill_outq(nghttp3_stream *stream);
int nghttp3_stream_write_stream_type(nghttp3_stream *stream);
size_t nghttp3_stream_writev(nghttp3_stream *stream, int *pfin,
nghttp3_vec *vec, size_t veccnt);
int nghttp3_stream_write_qpack_decoder_stream(nghttp3_stream *stream);
int nghttp3_stream_outq_add(nghttp3_stream *stream,
const nghttp3_typed_buf *tbuf);
int nghttp3_stream_write_headers(nghttp3_stream *stream,
nghttp3_frame_entry *frent);
int nghttp3_stream_write_header_block(nghttp3_stream *stream,
nghttp3_qpack_encoder *qenc,
nghttp3_stream *qenc_stream,
nghttp3_buf *rbuf, nghttp3_buf *ebuf,
int64_t frame_type, const nghttp3_nv *nva,
size_t nvlen);
int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof,
nghttp3_frame_entry *frent);
int nghttp3_stream_write_settings(nghttp3_stream *stream,
nghttp3_frame_entry *frent);
int nghttp3_stream_write_goaway(nghttp3_stream *stream,
nghttp3_frame_entry *frent);
int nghttp3_stream_write_priority_update(nghttp3_stream *stream,
nghttp3_frame_entry *frent);
int nghttp3_stream_ensure_chunk(nghttp3_stream *stream, size_t need);
nghttp3_buf *nghttp3_stream_get_chunk(nghttp3_stream *stream);
int nghttp3_stream_is_blocked(nghttp3_stream *stream);
void nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n);
/*
* nghttp3_stream_outq_write_done returns nonzero if all contents in
* outq have been written.
*/
int nghttp3_stream_outq_write_done(nghttp3_stream *stream);
/*
* nghttp2_stream_update_ack_offset updates the last acknowledged
* offset to |offset|.
*/
int nghttp3_stream_update_ack_offset(nghttp3_stream *stream, uint64_t offset);
/*
* nghttp3_stream_is_active returns nonzero if |stream| is active. In
* other words, it has something to send. This function does not take
* into account its descendants.
*/
int nghttp3_stream_is_active(nghttp3_stream *stream);
/*
* nghttp3_stream_require_schedule returns nonzero if |stream| should
* be scheduled. In other words, |stream| or its descendants have
* something to send.
*/
int nghttp3_stream_require_schedule(nghttp3_stream *stream);
int nghttp3_stream_buffer_data(nghttp3_stream *stream, const uint8_t *src,
size_t srclen);
size_t nghttp3_stream_get_buffered_datalen(nghttp3_stream *stream);
int nghttp3_stream_ensure_qpack_stream_context(nghttp3_stream *stream);
void nghttp3_stream_delete_qpack_stream_context(nghttp3_stream *stream);
int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream,
nghttp3_stream_http_event event);
int nghttp3_stream_empty_headers_allowed(nghttp3_stream *stream);
/*
* nghttp3_stream_uni returns nonzero if stream identified by
* |stream_id| is unidirectional.
*/
int nghttp3_stream_uni(int64_t stream_id);
/*
* nghttp3_client_stream_bidi returns nonzero if stream identified by
* |stream_id| is client initiated bidirectional stream.
*/
int nghttp3_client_stream_bidi(int64_t stream_id);
/*
* nghttp3_client_stream_uni returns nonzero if stream identified by
* |stream_id| is client initiated unidirectional stream.
*/
int nghttp3_client_stream_uni(int64_t stream_id);
/*
* nghttp3_server_stream_uni returns nonzero if stream identified by
* |stream_id| is server initiated unidirectional stream.
*/
int nghttp3_server_stream_uni(int64_t stream_id);
#endif /* !defined(NGHTTP3_STREAM_H) */

95
deps/ngtcp2/nghttp3/lib/nghttp3_tnode.c vendored Normal file
View File

@ -0,0 +1,95 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_tnode.h"
#include <assert.h>
#include "nghttp3_macro.h"
#include "nghttp3_stream.h"
#include "nghttp3_conn.h"
#include "nghttp3_conv.h"
void nghttp3_tnode_init(nghttp3_tnode *tnode, int64_t id) {
tnode->pe.index = NGHTTP3_PQ_BAD_INDEX;
tnode->id = id;
tnode->cycle = 0;
tnode->pri.urgency = NGHTTP3_DEFAULT_URGENCY;
tnode->pri.inc = 0;
}
void nghttp3_tnode_free(nghttp3_tnode *tnode) { (void)tnode; }
static void tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq) {
assert(tnode->pe.index != NGHTTP3_PQ_BAD_INDEX);
nghttp3_pq_remove(pq, &tnode->pe);
tnode->pe.index = NGHTTP3_PQ_BAD_INDEX;
}
void nghttp3_tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq) {
if (tnode->pe.index == NGHTTP3_PQ_BAD_INDEX) {
return;
}
tnode_unschedule(tnode, pq);
}
static uint64_t pq_get_first_cycle(nghttp3_pq *pq) {
nghttp3_tnode *top;
if (nghttp3_pq_empty(pq)) {
return 0;
}
top = nghttp3_struct_of(nghttp3_pq_top(pq), nghttp3_tnode, pe);
return top->cycle;
}
int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
uint64_t nwrite) {
uint64_t penalty = nwrite / NGHTTP3_STREAM_MIN_WRITELEN;
if (tnode->pe.index == NGHTTP3_PQ_BAD_INDEX) {
tnode->cycle =
pq_get_first_cycle(pq) +
((nwrite == 0 || !tnode->pri.inc) ? 0 : nghttp3_max_uint64(1, penalty));
} else if (nwrite > 0) {
if (!tnode->pri.inc || nghttp3_pq_size(pq) == 1) {
return 0;
}
nghttp3_pq_remove(pq, &tnode->pe);
tnode->pe.index = NGHTTP3_PQ_BAD_INDEX;
tnode->cycle += nghttp3_max_uint64(1, penalty);
} else {
return 0;
}
return nghttp3_pq_push(pq, &tnode->pe);
}
int nghttp3_tnode_is_scheduled(nghttp3_tnode *tnode) {
return tnode->pe.index != NGHTTP3_PQ_BAD_INDEX;
}

66
deps/ngtcp2/nghttp3/lib/nghttp3_tnode.h vendored Normal file
View File

@ -0,0 +1,66 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_TNODE_H
#define NGHTTP3_TNODE_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#include "nghttp3_pq.h"
#define NGHTTP3_TNODE_MAX_CYCLE_GAP (1llu << 24)
typedef struct nghttp3_tnode {
nghttp3_pq_entry pe;
size_t num_children;
int64_t id;
uint64_t cycle;
/* pri is a stream priority produced by nghttp3_pri_to_uint8. */
nghttp3_pri pri;
} nghttp3_tnode;
void nghttp3_tnode_init(nghttp3_tnode *tnode, int64_t id);
void nghttp3_tnode_free(nghttp3_tnode *tnode);
void nghttp3_tnode_unschedule(nghttp3_tnode *tnode, nghttp3_pq *pq);
/*
* nghttp3_tnode_schedule schedules |tnode| using |nwrite| as penalty.
* If |tnode| has already been scheduled, it is rescheduled by the
* amount of |nwrite|.
*/
int nghttp3_tnode_schedule(nghttp3_tnode *tnode, nghttp3_pq *pq,
uint64_t nwrite);
/*
* nghttp3_tnode_is_scheduled returns nonzero if |tnode| is scheduled.
*/
int nghttp3_tnode_is_scheduled(nghttp3_tnode *tnode);
#endif /* !defined(NGHTTP3_TNODE_H) */

View File

@ -0,0 +1,72 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_unreachable.h"
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif /* defined(HAVE_UNISTD_H) */
#include <stdlib.h>
#ifdef WIN32
# include <io.h>
#endif /* defined(WIN32) */
void nghttp3_unreachable_fail(const char *file, int line, const char *func) {
char *buf;
size_t buflen;
int rv;
#define NGHTTP3_UNREACHABLE_TEMPLATE "%s:%d %s: Unreachable.\n"
rv = snprintf(NULL, 0, NGHTTP3_UNREACHABLE_TEMPLATE, file, line, func);
if (rv < 0) {
abort();
}
/* here we explicitly use system malloc */
buflen = (size_t)rv + 1;
buf = malloc(buflen);
if (buf == NULL) {
abort();
}
rv = snprintf(buf, buflen, NGHTTP3_UNREACHABLE_TEMPLATE, file, line, func);
if (rv < 0) {
abort();
}
#ifndef WIN32
while (write(STDERR_FILENO, buf, (size_t)rv) == -1 && errno == EINTR)
;
#else /* defined(WIN32) */
_write(_fileno(stderr), buf, (unsigned int)rv);
#endif /* defined(WIN32) */
free(buf);
abort();
}

View File

@ -0,0 +1,53 @@
/*
* nghttp3
*
* Copyright (c) 2022 nghttp3 contributors
* Copyright (c) 2022 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_UNREACHABLE_H
#define NGHTTP3_UNREACHABLE_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
#ifdef __FILE_NAME__
# define NGHTTP3_FILE_NAME __FILE_NAME__
#else /* !defined(__FILE_NAME__) */
# define NGHTTP3_FILE_NAME "(file)"
#endif /* !defined(__FILE_NAME__) */
#define nghttp3_unreachable() \
nghttp3_unreachable_fail(NGHTTP3_FILE_NAME, __LINE__, __func__)
#ifdef _MSC_VER
__declspec(noreturn)
#endif /* defined(_MSC_VER) */
void nghttp3_unreachable_fail(const char *file, int line, const char *func)
#ifndef _MSC_VER
__attribute__((noreturn))
#endif /* !defined(_MSC_VER) */
;
#endif /* !defined(NGHTTP3_UNREACHABLE_H) */

55
deps/ngtcp2/nghttp3/lib/nghttp3_vec.c vendored Normal file
View File

@ -0,0 +1,55 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2018 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "nghttp3_vec.h"
#include "nghttp3_macro.h"
uint64_t nghttp3_vec_len(const nghttp3_vec *vec, size_t n) {
size_t i;
uint64_t res = 0;
for (i = 0; i < n; ++i) {
res += vec[i].len;
}
return res;
}
int64_t nghttp3_vec_len_varint(const nghttp3_vec *vec, size_t n) {
uint64_t res = 0;
size_t len;
size_t i;
for (i = 0; i < n; ++i) {
len = vec[i].len;
if (len > NGHTTP3_MAX_VARINT - res) {
return -1;
}
res += len;
}
return (int64_t)res;
}

41
deps/ngtcp2/nghttp3/lib/nghttp3_vec.h vendored Normal file
View File

@ -0,0 +1,41 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2018 ngtcp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef NGHTTP3_VEC_H
#define NGHTTP3_VEC_H
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
/*
* nghttp3_vec_len_varint is similar to nghttp3_vec_len, but it
* returns -1 if the sum of the length exceeds NGHTTP3_MAX_VARINT.
*/
int64_t nghttp3_vec_len_varint(const nghttp3_vec *vec, size_t n);
#endif /* !defined(NGHTTP3_VEC_H) */

View File

@ -0,0 +1,39 @@
/*
* nghttp3
*
* Copyright (c) 2019 nghttp3 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* defined(HAVE_CONFIG_H) */
#include <nghttp3/nghttp3.h>
static nghttp3_info version = {NGHTTP3_VERSION_AGE, NGHTTP3_VERSION_NUM,
NGHTTP3_VERSION};
const nghttp3_info *nghttp3_version(int least_version) {
if (least_version > NGHTTP3_VERSION_NUM) {
return NULL;
}
return &version;
}

22
deps/ngtcp2/nghttp3/lib/sfparse/COPYING vendored Normal file
View File

@ -0,0 +1,22 @@
The MIT License
Copyright (c) 2023 sfparse contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1517
deps/ngtcp2/nghttp3/lib/sfparse/sfparse.c vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,428 @@
/*
* sfparse
*
* Copyright (c) 2023 sfparse contributors
* Copyright (c) 2019 nghttp3 contributors
* Copyright (c) 2015 nghttp2 contributors
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SFPARSE_H
#define SFPARSE_H
/* Define WIN32 when build target is Win32 API (borrowed from
libcurl) */
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_MSC_VER) && (_MSC_VER < 1800)
/* MSVC < 2013 does not have inttypes.h because it is not C99
compliant. See compiler macros and version number in
https://sourceforge.net/p/predef/wiki/Compilers/ */
# include <stdint.h>
#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
# include <inttypes.h>
#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
#include <sys/types.h>
#include <stddef.h>
/**
* @enum
*
* :type:`sf_type` defines value type.
*/
typedef enum sf_type {
/**
* :enum:`SF_TYPE_BOOLEAN` indicates boolean type.
*/
SF_TYPE_BOOLEAN,
/**
* :enum:`SF_TYPE_INTEGER` indicates integer type.
*/
SF_TYPE_INTEGER,
/**
* :enum:`SF_TYPE_DECIMAL` indicates decimal type.
*/
SF_TYPE_DECIMAL,
/**
* :enum:`SF_TYPE_STRING` indicates string type.
*/
SF_TYPE_STRING,
/**
* :enum:`SF_TYPE_TOKEN` indicates token type.
*/
SF_TYPE_TOKEN,
/**
* :enum:`SF_TYPE_BYTESEQ` indicates byte sequence type.
*/
SF_TYPE_BYTESEQ,
/**
* :enum:`SF_TYPE_INNER_LIST` indicates inner list type.
*/
SF_TYPE_INNER_LIST,
/**
* :enum:`SF_TYPE_DATE` indicates date type.
*/
SF_TYPE_DATE,
/**
* :enum:`SF_TYPE_DISPSTRING` indicates display string type.
*/
SF_TYPE_DISPSTRING
} sf_type;
/**
* @macro
*
* :macro:`SF_ERR_PARSE_ERROR` indicates fatal parse error has
* occurred, and it is not possible to continue the processing.
*/
#define SF_ERR_PARSE_ERROR -1
/**
* @macro
*
* :macro:`SF_ERR_EOF` indicates that there is nothing left to read.
* The context of this error varies depending on the function that
* returns this error code.
*/
#define SF_ERR_EOF -2
/**
* @struct
*
* :type:`sf_vec` stores sequence of bytes.
*/
typedef struct sf_vec {
/**
* :member:`base` points to the beginning of the sequence of bytes.
*/
uint8_t *base;
/**
* :member:`len` is the number of bytes contained in this sequence.
*/
size_t len;
} sf_vec;
/**
* @macro
*
* :macro:`SF_VALUE_FLAG_NONE` indicates no flag set.
*/
#define SF_VALUE_FLAG_NONE 0x0u
/**
* @macro
*
* :macro:`SF_VALUE_FLAG_ESCAPED_STRING` indicates that a string
* contains escaped character(s).
*/
#define SF_VALUE_FLAG_ESCAPED_STRING 0x1u
/**
* @struct
*
* :type:`sf_decimal` contains decimal value.
*/
typedef struct sf_decimal {
/**
* :member:`numer` contains numerator of the decimal value.
*/
int64_t numer;
/**
* :member:`denom` contains denominator of the decimal value.
*/
int64_t denom;
} sf_decimal;
/**
* @struct
*
* :type:`sf_value` stores a Structured Field item. For Inner List,
* only type is set to :enum:`sf_type.SF_TYPE_INNER_LIST`. In order
* to read the items contained in an inner list, call
* `sf_parser_inner_list`.
*/
typedef struct sf_value {
/**
* :member:`type` is the type of the value contained in this
* particular object.
*/
sf_type type;
/**
* :member:`flags` is bitwise OR of one or more of
* :macro:`SF_VALUE_FLAG_* <SF_VALUE_FLAG_NONE>`.
*/
uint32_t flags;
/**
* @anonunion_start
*
* @sf_value_value
*/
union {
/**
* :member:`boolean` contains boolean value if :member:`type` ==
* :enum:`sf_type.SF_TYPE_BOOLEAN`. 1 indicates true, and 0
* indicates false.
*/
int boolean;
/**
* :member:`integer` contains integer value if :member:`type` is
* either :enum:`sf_type.SF_TYPE_INTEGER` or
* :enum:`sf_type.SF_TYPE_DATE`.
*/
int64_t integer;
/**
* :member:`decimal` contains decimal value if :member:`type` ==
* :enum:`sf_type.SF_TYPE_DECIMAL`.
*/
sf_decimal decimal;
/**
* :member:`vec` contains sequence of bytes if :member:`type` is
* either :enum:`sf_type.SF_TYPE_STRING`,
* :enum:`sf_type.SF_TYPE_TOKEN`, :enum:`sf_type.SF_TYPE_BYTESEQ`,
* or :enum:`sf_type.SF_TYPE_DISPSTRING`.
*
* For :enum:`sf_type.SF_TYPE_STRING`, this field contains one or
* more escaped characters if :member:`flags` has
* :macro:`SF_VALUE_FLAG_ESCAPED_STRING` set. To unescape the
* string, use `sf_unescape`.
*
* For :enum:`sf_type.SF_TYPE_BYTESEQ`, this field contains base64
* encoded string. To decode this byte string, use
* `sf_base64decode`.
*
* For :enum:`sf_type.SF_TYPE_DISPSTRING`, this field may contain
* percent-encoded UTF-8 byte sequences. To decode it, use
* `sf_pctdecode`.
*
* If :member:`vec.len <sf_vec.len>` == 0, :member:`vec.base
* <sf_vec.base>` is guaranteed to be NULL.
*/
sf_vec vec;
/**
* @anonunion_end
*/
};
} sf_value;
/**
* @struct
*
* :type:`sf_parser` is the Structured Field Values parser. Use
* `sf_parser_init` to initialize it.
*/
typedef struct sf_parser {
/* all fields are private */
const uint8_t *pos;
const uint8_t *end;
uint32_t state;
} sf_parser;
/**
* @function
*
* `sf_parser_init` initializes |sfp| with the given buffer pointed by
* |data| of length |datalen|.
*/
void sf_parser_init(sf_parser *sfp, const uint8_t *data, size_t datalen);
/**
* @function
*
* `sf_parser_param` reads a parameter. If this function returns 0,
* it stores parameter key and value in |dest_key| and |dest_value|
* respectively, if they are not NULL.
*
* This function does no effort to find duplicated keys. Same key may
* be reported more than once.
*
* Caller should keep calling this function until it returns negative
* error code. If it returns :macro:`SF_ERR_EOF`, all parameters have
* read, and caller can continue to read rest of the values. If it
* returns :macro:`SF_ERR_PARSE_ERROR`, it encountered fatal error
* while parsing field value.
*/
int sf_parser_param(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value);
/**
* @function
*
* `sf_parser_dict` reads the next dictionary key and value pair. If
* this function returns 0, it stores the key and value in |dest_key|
* and |dest_value| respectively, if they are not NULL.
*
* Caller can optionally read parameters attached to the pair by
* calling `sf_parser_param`.
*
* This function does no effort to find duplicated keys. Same key may
* be reported more than once.
*
* Caller should keep calling this function until it returns negative
* error code. If it returns :macro:`SF_ERR_EOF`, all key and value
* pairs have been read, and there is nothing left to read.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* :macro:`SF_ERR_EOF`
* All values in the dictionary have read.
* :macro:`SF_ERR_PARSE_ERROR`
* It encountered fatal error while parsing field value.
*/
int sf_parser_dict(sf_parser *sfp, sf_vec *dest_key, sf_value *dest_value);
/**
* @function
*
* `sf_parser_list` reads the next list item. If this function
* returns 0, it stores the item in |dest| if it is not NULL.
*
* Caller can optionally read parameters attached to the item by
* calling `sf_parser_param`.
*
* Caller should keep calling this function until it returns negative
* error code. If it returns :macro:`SF_ERR_EOF`, all values in the
* list have been read, and there is nothing left to read.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* :macro:`SF_ERR_EOF`
* All values in the list have read.
* :macro:`SF_ERR_PARSE_ERROR`
* It encountered fatal error while parsing field value.
*/
int sf_parser_list(sf_parser *sfp, sf_value *dest);
/**
* @function
*
* `sf_parser_item` reads a single item. If this function returns 0,
* it stores the item in |dest| if it is not NULL.
*
* This function is only used for the field value that consists of a
* single item.
*
* Caller can optionally read parameters attached to the item by
* calling `sf_parser_param`.
*
* Caller should call this function again to make sure that there is
* nothing left to read. If this 2nd function call returns
* :macro:`SF_ERR_EOF`, all data have been processed successfully.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* :macro:`SF_ERR_EOF`
* There is nothing left to read.
* :macro:`SF_ERR_PARSE_ERROR`
* It encountered fatal error while parsing field value.
*/
int sf_parser_item(sf_parser *sfp, sf_value *dest);
/**
* @function
*
* `sf_parser_inner_list` reads the next inner list item. If this
* function returns 0, it stores the item in |dest| if it is not NULL.
*
* Caller can optionally read parameters attached to the item by
* calling `sf_parser_param`.
*
* Caller should keep calling this function until it returns negative
* error code. If it returns :macro:`SF_ERR_EOF`, all values in this
* inner list have been read, and caller can optionally read
* parameters attached to this inner list by calling
* `sf_parser_param`. Then caller can continue to read rest of the
* values.
*
* This function returns 0 if it succeeds, or one of the following
* negative error codes:
*
* :macro:`SF_ERR_EOF`
* All values in the inner list have read.
* :macro:`SF_ERR_PARSE_ERROR`
* It encountered fatal error while parsing field value.
*/
int sf_parser_inner_list(sf_parser *sfp, sf_value *dest);
/**
* @function
*
* `sf_unescape` copies |src| to |dest| by removing escapes (``\``).
* |src| should be the pointer to :member:`sf_value.vec` of type
* :enum:`sf_type.SF_TYPE_STRING` produced by either `sf_parser_dict`,
* `sf_parser_list`, `sf_parser_inner_list`, `sf_parser_item`, or
* `sf_parser_param`, otherwise the behavior is undefined.
*
* :member:`dest->base <sf_vec.base>` must point to the buffer that
* has sufficient space to store the unescaped string.
*
* This function sets the length of unescaped string to
* :member:`dest->len <sf_vec.len>`.
*/
void sf_unescape(sf_vec *dest, const sf_vec *src);
/**
* @function
*
* `sf_base64decode` decodes Base64 encoded string |src| and writes
* the result into |dest|. |src| should be the pointer to
* :member:`sf_value.vec` of type :enum:`sf_type.SF_TYPE_BYTESEQ`
* produced by either `sf_parser_dict`, `sf_parser_list`,
* `sf_parser_inner_list`, `sf_parser_item`, or `sf_parser_param`,
* otherwise the behavior is undefined.
*
* :member:`dest->base <sf_vec.base>` must point to the buffer that
* has sufficient space to store the decoded byte string.
*
* This function sets the length of decoded byte string to
* :member:`dest->len <sf_vec.len>`.
*/
void sf_base64decode(sf_vec *dest, const sf_vec *src);
/**
* @function
*
* `sf_pctdecode` decodes percent-encoded string |src| and writes the
* result into |dest|. |src| should be the pointer to
* :member:`sf_value.vec` of type :enum:`sf_type.SF_TYPE_DISPSTRING`
* produced by either `sf_parser_dict`, `sf_parser_list`,
* `sf_parser_inner_list`, `sf_parser_item`, or `sf_parser_param`,
* otherwise the behavior is undefined.
*
* :member:`dest->base <sf_vec.base>` must point to the buffer that
* has sufficient space to store the decoded byte string.
*
* This function sets the length of decoded byte string to
* :member:`dest->len <sf_vec.len>`.
*/
void sf_pctdecode(sf_vec *dest, const sf_vec *src);
#ifdef __cplusplus
}
#endif
#endif /* SFPARSE_H */