Generic utilities. More...
#include <arpa/inet.h>
#include "internal/utils.h"
#include "imquic/debug.h"
#include <openssl/rand.h>
Functions | |
size_t | imquic_strlcat (char *dest, const char *src, size_t dest_size) |
Helper method to concatenate strings and log an error if truncation occurred. | |
int | imquic_strlcat_fast (char *dest, const char *src, size_t dest_size, size_t *offset) |
Alternative helper method to concatenate strings and log an error if truncation occurred, which uses memccpy instead of g_strlcat and so is supposed to be faster. | |
uint64_t | imquic_random_uint64 (void) |
Helper to generate random 64 bit unsigned integers. | |
uint64_t * | imquic_dup_uint64 (uint64_t num) |
Helper to generate an allocated copy of a uint64_t number. | |
uint64_t | imquic_read_varint (uint8_t *bytes, size_t blen, uint8_t *length) |
Read a variable size integer from a buffer. | |
uint8_t | imquic_write_varint (uint64_t number, uint8_t *bytes, size_t blen) |
Write a variable size integer to a buffer. | |
uint64_t | imquic_read_pfxint (uint8_t n, uint8_t *bytes, size_t blen, uint8_t *length) |
Read a prefixed integer from a buffer (QPACK only) | |
uint8_t | imquic_write_pfxint (uint64_t number, uint8_t n, uint8_t *bytes, size_t blen) |
Write a prefixed integer to a buffer (QPACK only) | |
uint64_t | imquic_full_packet_number (uint64_t largest, uint64_t pn_pkt, uint8_t p_len) |
Helper method to reconstruct a full QUIC packet number. | |
void | imquic_print_hex (int level, uint8_t *buf, size_t buflen) |
Helper method mostly used for debugging: prints the content of a hex buffer. | |
imquic_data * | imquic_data_create (uint8_t *buffer, size_t length) |
Helper method to create a data buffer out of existing data. | |
gboolean | imquic_data_equal (const void *a, const void *b) |
Helper comparator function, to check if two buffers contain the same data. | |
void | imquic_data_destroy (imquic_data *data) |
Helper method to free an existing data buffer. | |
uint8_t | imquic_bitstream_peek (imquic_bitstream *bs, uint8_t *len) |
Helper method to peek 8 bit in the bitstream. | |
size_t | imquic_bitstream_write (imquic_bitstream *bs, uint32_t value, uint8_t bits) |
Helper method to add bits to a bitstream buffer. | |
Generic utilities.
Implementation of a few more generic functionality that is useful in the QUIC stack internals (e.g., varint support).
uint8_t imquic_bitstream_peek | ( | imquic_bitstream * | bs, |
uint8_t * | len ) |
Helper method to peek 8 bit in the bitstream.
[in] | bs | The bitstream instance to peek |
[out] | len | How many bits were actually put in the byte |
size_t imquic_bitstream_write | ( | imquic_bitstream * | bs, |
uint32_t | value, | ||
uint8_t | bits ) |
Helper method to add bits to a bitstream buffer.
bs | The bitstream instance to update |
value | Integer containing the data to write |
bits | Number of bits from the integer to actually write |
imquic_data * imquic_data_create | ( | uint8_t * | buffer, |
size_t | length ) |
Helper method to create a data buffer out of existing data.
buffer | The data to copy in the new buffer |
length | How many bytes to copy from the original data |
void imquic_data_destroy | ( | imquic_data * | data | ) |
Helper method to free an existing data buffer.
data | The data buffer to free |
gboolean imquic_data_equal | ( | const void * | a, |
const void * | b ) |
Helper comparator function, to check if two buffers contain the same data.
a | Opaque pointer to the first data buffer to compare |
b | Opaque pointer to the second data buffer to compare |
uint64_t * imquic_dup_uint64 | ( | uint64_t | num | ) |
Helper to generate an allocated copy of a uint64_t number.
num | The uint64_t number to duplicate |
uint64_t imquic_full_packet_number | ( | uint64_t | largest, |
uint64_t | pn_pkt, | ||
uint8_t | p_len ) |
Helper method to reconstruct a full QUIC packet number.
largest | The largest packet number received so far at this encryption level |
pn_pkt | The received packet number |
p_len | How many bytes the received packet number used as a variable size integer |
void imquic_print_hex | ( | int | level, |
uint8_t * | buf, | ||
size_t | buflen ) |
Helper method mostly used for debugging: prints the content of a hex buffer.
level | Log level at which this should be printed |
buf | Buffer whose content need to be printed |
buflen | How many bytes in the buffer should be printed |
uint64_t imquic_random_uint64 | ( | void | ) |
Helper to generate random 64 bit unsigned integers.
uint64_t imquic_read_pfxint | ( | uint8_t | n, |
uint8_t * | bytes, | ||
size_t | blen, | ||
uint8_t * | length ) |
Read a prefixed integer from a buffer (QPACK only)
[in] | n | The N prefix |
[in] | bytes | The buffer to read |
[in] | blen | The size of the buffer |
[out] | length | How many bytes the variable size integer used |
uint64_t imquic_read_varint | ( | uint8_t * | bytes, |
size_t | blen, | ||
uint8_t * | length ) |
Read a variable size integer from a buffer.
[in] | bytes | The buffer to read |
[in] | blen | The size of the buffer |
[out] | length | How many bytes the variable size integer used |
size_t imquic_strlcat | ( | char * | dest, |
const char * | src, | ||
size_t | dest_size ) |
Helper method to concatenate strings and log an error if truncation occurred.
[in] | dest | Destination buffer, already containing one nul-terminated string |
[in] | src | Source buffer |
[in] | dest_size | Length of dest buffer in bytes (not length of existing string inside dest) |
int imquic_strlcat_fast | ( | char * | dest, |
const char * | src, | ||
size_t | dest_size, | ||
size_t * | offset ) |
Alternative helper method to concatenate strings and log an error if truncation occurred, which uses memccpy instead of g_strlcat and so is supposed to be faster.
[in] | dest | Destination buffer, already containing one nul-terminated string |
[in] | src | Source buffer |
[in] | dest_size | Length of dest buffer in bytes (not length of existing string inside dest) |
[in] | offset | Offset of where to start appending, in the destination buffer |
uint8_t imquic_write_pfxint | ( | uint64_t | number, |
uint8_t | n, | ||
uint8_t * | bytes, | ||
size_t | blen ) |
Write a prefixed integer to a buffer (QPACK only)
[in] | number | The number to write as a variable size integer |
[in] | n | The N prefix |
[in] | bytes | The buffer to write to |
[in] | blen | The size of the buffer |
uint8_t imquic_write_varint | ( | uint64_t | number, |
uint8_t * | bytes, | ||
size_t | blen ) |
Write a variable size integer to a buffer.
[in] | number | The number to write as a variable size integer |
[in] | bytes | The buffer to write to |
[in] | blen | The size of the buffer |