]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ChunkedCodingParser.h
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / ChunkedCodingParser.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9 #ifndef SQUID_CHUNKEDCODINGPARSER_H
10 #define SQUID_CHUNKEDCODINGPARSER_H
11
12 class MemBuf;
13
14 /**
15 \ingroup ChunkEncodingAPI Chunked Encoding API
16 \par
17 * ChunkedCodingParser is an incremental parser for chunked transfer coding
18 * used by HTTP and ICAP. The parser shovels content bytes from the raw
19 * input buffer into the content output buffer, both caller-supplied.
20 * Ignores chunk extensions except for ICAP's ieof.
21 * Has a trailer-handling placeholder.
22 */
23 class ChunkedCodingParser
24 {
25
26 public:
27 ChunkedCodingParser();
28
29 void reset();
30
31 /**
32 \retval true complete success
33 \retval false needs more data
34 \throws ?? error.
35 */
36 bool parse(MemBuf *rawData, MemBuf *parsedContent);
37
38 bool needsMoreData() const;
39 bool needsMoreSpace() const;
40
41 private:
42 typedef void (ChunkedCodingParser::*Step)();
43
44 private:
45 bool mayContinue() const;
46
47 void parseChunkSize();
48 void parseUnusedChunkExtension();
49 void parseLastChunkExtension();
50 void parseChunkBeg();
51 void parseChunkBody();
52 void parseChunkEnd();
53 void parseTrailer();
54 void parseTrailerHeader();
55 void parseMessageEnd();
56
57 bool findCrlf(size_t &crlfBeg, size_t &crlfEnd);
58 bool findCrlf(size_t &crlfBeg, size_t &crlfEnd, bool &quoted, bool &slashed);
59
60 private:
61 static Step psChunkSize;
62 static Step psUnusedChunkExtension;
63 static Step psLastChunkExtension;
64 static Step psChunkBody;
65 static Step psChunkEnd;
66 static Step psTrailer;
67 static Step psMessageEnd;
68
69 MemBuf *theIn;
70 MemBuf *theOut;
71
72 Step theStep;
73 uint64_t theChunkSize;
74 uint64_t theLeftBodySize;
75 bool doNeedMoreData;
76 bool inQuoted; ///< stores parsing state for incremental findCrlf
77 bool inSlashed; ///< stores parsing state for incremental findCrlf
78
79 public:
80 int64_t useOriginBody;
81 };
82
83 #endif /* SQUID_CHUNKEDCODINGPARSER_H */