2 * Decompression of the Huffman encoding used for HTTP fields in HPACK (HTTP/2)
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/tvbuff.h>
15 #include <epan/nghttp2_hd_huffman.h>
17 static wmem_strbuf_t
*
18 get_hpack_huffman_strbuf(wmem_allocator_t
*scope
, const uint8_t *ptr
, size_t len
)
20 wmem_strbuf_t
*strbuf
;
21 strbuf
= wmem_strbuf_new_sized(scope
, len
+ 1);
23 nghttp2_huff_decode node
= {0, 0};
24 const nghttp2_huff_decode
*nodep
= &node
;
29 nodep
= &huff_decode_table
[nodep
->fstate
& 0x1ff][ch
>> 4];
30 if (nodep
->fstate
& NGHTTP2_HUFF_SYM
) {
31 wmem_strbuf_append_c(strbuf
, nodep
->sym
);
34 nodep
= &huff_decode_table
[nodep
->fstate
& 0x1ff][ch
& 0xf];
35 if (nodep
->fstate
& NGHTTP2_HUFF_SYM
) {
36 wmem_strbuf_append_c(strbuf
, nodep
->sym
);
42 if (!(nodep
->fstate
& NGHTTP2_HUFF_ACCEPTED
)) {
43 wmem_strbuf_destroy(strbuf
);
51 tvb_get_hpack_huffman_strbuf(wmem_allocator_t
*scope
, tvbuff_t
*tvb
, const int offset
, const int len
)
53 return get_hpack_huffman_strbuf(scope
, tvb_get_ptr(tvb
, offset
, len
), len
);
57 tvb_child_uncompress_hpack_huff(tvbuff_t
* parent
, int offset
, int length
)
60 wmem_strbuf_t
*strbuf
;
64 strbuf
= tvb_get_hpack_huffman_strbuf(NULL
, parent
, offset
, length
);
67 len
= wmem_strbuf_get_len(strbuf
);
68 data
= wmem_strbuf_finalize(strbuf
);
70 tvb
= tvb_new_child_real_data(parent
, (const uint8_t*)data
, (unsigned)len
, (int)len
);
72 tvb_set_free_cb(tvb
, g_free
);