2 * Declarations of routines handling protocols with a request/response line,
3 * headers, a blank line, and an optional body.
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
12 #ifndef __REQ_RESP_HDRS_H__
13 #define __REQ_RESP_HDRS_H__
15 #include "ws_symbol_export.h"
16 #include "wsutil/strtoi.h"
19 * Optionally do reassembly of the request/response line, headers, and body.
21 * @param tvb The buffer.
22 * @param offset The offset in the buffer to begin inspection.
23 * @param pinfo Packet info from the parent protocol.
24 * @param desegment_headers Do desegmentation on headers.
25 * @param desegment_body Do desegmentation on body.
26 * @param desegment_until_fin When desegment_body is enabled and no
27 * Content-Length header is found, assume that all data following the headers
28 * are part of the body.
29 * @param[in,out] last_chunk_offset For the chunked Transfer-Encoding,
30 * the offset (relative to the initial tvb offset) of the last chunk size
31 * found. The result can be fed back into a future call in order to skip
32 * to a later chunk and reduce processing from O(N^2) to O(N). Use 0 for
33 * the initial call. Only set when chunked TE is found. May be NULL.
34 * @param streaming_subdissector_table For searching a streaming reassembly
35 * mode supported subdissector on it by the content-type header value.
36 * @param[out] streaming_chunk_handle Only set when this is the beginning of
37 * a chunk stream. (There is 'Transfer-Encoding: chunked' header and a
38 * streaming reassembly mode supported subdissector is found according to
39 * Content-Type header)
40 * @return true if desegmentation is complete otherwise false
43 req_resp_hdrs_do_reassembly(tvbuff_t
*tvb
, const int offset
, packet_info
*pinfo
,
44 const bool desegment_headers
, const bool desegment_body
,
45 bool desegment_until_fin
, int *last_chunk_offset
,
46 dissector_table_t streaming_subdissector_table
, dissector_handle_t
*streaming_chunk_handle
);
48 /** Check whether the first line is the beginning of a chunk. */
50 starts_with_chunk_size(tvbuff_t
* tvb
, const int offset
, packet_info
* pinfo
)
52 unsigned chunk_size
= 0;
53 int linelen
= tvb_find_line_end(tvb
, offset
, tvb_reported_length_remaining(tvb
, offset
), NULL
, true);
58 char* chunk_string
= tvb_get_string_enc(pinfo
->pool
, tvb
, offset
, linelen
, ENC_ASCII
);
59 char* c
= chunk_string
;
61 /* ignore extensions, including optional BWS ("bad whitespace")
62 * in the grammar for historical reasons, see RFC 9112 7.1.1.
64 if ((c
= strpbrk(c
, "; \t"))) {
68 if (!ws_hexstrtou32(chunk_string
, NULL
, &chunk_size
)) {
69 return false; /* can not get chunk size*/
70 } else if (chunk_size
> (1U << 31)) {
71 return false; /* chunk size is unreasonable */