| Code Coverage: vinyl-cache/bin/vinyld/hpack/vhp.h |
| |
| 82217aa4fc7094b3610340078afaf78cd95a8ec9 |
| |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2016 Varnish Software AS |
| 2 |
|
* All rights reserved. |
| 3 |
|
* |
| 4 |
|
* Author: Martin Blix Grydeland <martin@varnish-software.com> |
| 5 |
|
* |
| 6 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 7 |
|
* |
| 8 |
|
* Redistribution and use in source and binary forms, with or without |
| 9 |
|
* modification, are permitted provided that the following conditions |
| 10 |
|
* are met: |
| 11 |
|
* 1. Redistributions of source code must retain the above copyright |
| 12 |
|
* notice, this list of conditions and the following disclaimer. |
| 13 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
* notice, this list of conditions and the following disclaimer in the |
| 15 |
|
* documentation and/or other materials provided with the distribution. |
| 16 |
|
* |
| 17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 |
|
* SUCH DAMAGE. |
| 28 |
|
* |
| 29 |
|
*/ |
| 30 |
|
|
| 31 |
|
#include <stdint.h> |
| 32 |
|
|
| 33 |
|
/* VHT - Vinyl HPACK Table */ |
| 34 |
|
|
| 35 |
2306 |
#define VHT_ENTRY_SIZE 32U |
| 36 |
|
|
| 37 |
|
struct vht_entry { |
| 38 |
|
unsigned magic; |
| 39 |
|
#define VHT_ENTRY_MAGIC 0xc06dd892 |
| 40 |
|
unsigned offset; |
| 41 |
|
unsigned namelen; |
| 42 |
|
unsigned valuelen; |
| 43 |
|
}; |
| 44 |
|
|
| 45 |
|
struct vht_table { |
| 46 |
|
unsigned magic; |
| 47 |
|
#define VHT_TABLE_MAGIC 0x6bbdc683 |
| 48 |
|
unsigned n; |
| 49 |
|
unsigned size; |
| 50 |
|
unsigned maxsize; /* n * 32 + size <= maxsize */ |
| 51 |
|
unsigned protomax; |
| 52 |
|
unsigned bufsize; |
| 53 |
|
char *buf; |
| 54 |
|
}; |
| 55 |
|
|
| 56 |
|
void VHT_NewEntry(struct vht_table *); |
| 57 |
|
int VHT_NewEntry_Indexed(struct vht_table *, unsigned); |
| 58 |
|
void VHT_AppendName(struct vht_table *, const char *, ssize_t); |
| 59 |
|
void VHT_AppendValue(struct vht_table *, const char *, ssize_t); |
| 60 |
|
int VHT_SetMaxTableSize(struct vht_table *, size_t); |
| 61 |
|
int VHT_SetProtoMax(struct vht_table *, size_t); |
| 62 |
|
const char *VHT_LookupName(const struct vht_table *, unsigned, size_t *); |
| 63 |
|
const char *VHT_LookupValue(const struct vht_table *, unsigned, size_t *); |
| 64 |
|
int VHT_Init(struct vht_table *, size_t); |
| 65 |
|
void VHT_Fini(struct vht_table *); |
| 66 |
|
|
| 67 |
|
/* VHD - Vinyl HPACK Decoder */ |
| 68 |
|
|
| 69 |
|
enum vhd_ret_e { |
| 70 |
|
#define VHD_RET(NAME, VAL, DESC) \ |
| 71 |
|
VHD_##NAME = VAL, |
| 72 |
|
#include "tbl/vhd_return.h" |
| 73 |
|
}; |
| 74 |
|
|
| 75 |
|
struct vhd_int { |
| 76 |
|
uint8_t magic; |
| 77 |
|
#define VHD_INT_MAGIC 0x05 |
| 78 |
|
|
| 79 |
|
uint8_t pfx; |
| 80 |
|
uint8_t m; |
| 81 |
|
unsigned v; |
| 82 |
|
}; |
| 83 |
|
|
| 84 |
|
struct vhd_raw { |
| 85 |
|
uint8_t magic; |
| 86 |
|
#define VHD_RAW_MAGIC 0xa0 |
| 87 |
|
|
| 88 |
|
unsigned l; |
| 89 |
|
}; |
| 90 |
|
|
| 91 |
|
struct vhd_huffman { |
| 92 |
|
uint8_t magic; |
| 93 |
|
#define VHD_HUFFMAN_MAGIC 0x56 |
| 94 |
|
|
| 95 |
|
uint8_t blen; |
| 96 |
|
uint16_t bits; |
| 97 |
|
uint16_t pos; |
| 98 |
|
unsigned len; |
| 99 |
|
}; |
| 100 |
|
|
| 101 |
|
struct vhd_lookup { |
| 102 |
|
uint8_t magic; |
| 103 |
|
#define VHD_LOOKUP_MAGIC 0x65 |
| 104 |
|
|
| 105 |
|
unsigned l; |
| 106 |
|
}; |
| 107 |
|
|
| 108 |
|
struct vhd_decode { |
| 109 |
|
unsigned magic; |
| 110 |
|
#define VHD_DECODE_MAGIC 0x9cbc72b2 |
| 111 |
|
|
| 112 |
|
unsigned index; |
| 113 |
|
uint16_t state; |
| 114 |
|
int8_t error; |
| 115 |
|
uint8_t first; |
| 116 |
|
|
| 117 |
|
union { |
| 118 |
|
struct vhd_int integer[1]; |
| 119 |
|
struct vhd_lookup lookup[1]; |
| 120 |
|
struct vhd_raw raw[1]; |
| 121 |
|
struct vhd_huffman huffman[1]; |
| 122 |
|
}; |
| 123 |
|
}; |
| 124 |
|
|
| 125 |
|
void VHD_Init(struct vhd_decode *); |
| 126 |
|
enum vhd_ret_e VHD_Decode(struct vhd_decode *, struct vht_table *, |
| 127 |
|
const uint8_t *in, size_t inlen, size_t *p_inused, |
| 128 |
|
char *out, size_t outlen, size_t *p_outused); |
| 129 |
|
const char *VHD_Error(enum vhd_ret_e); |