]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ChunkedCodingParser.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ChunkedCodingParser.h
CommitLineData
774c051c 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
774c051c 3 *
bbc27441
AJ
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.
774c051c 7 */
bbc27441 8
774c051c 9#ifndef SQUID_CHUNKEDCODINGPARSER_H
10#define SQUID_CHUNKEDCODINGPARSER_H
11
e1f7507e 12class MemBuf;
774c051c 13
e1f7507e
AJ
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 */
774c051c 23class ChunkedCodingParser
24{
25
26public:
27 ChunkedCodingParser();
28
29 void reset();
30
e1f7507e
AJ
31 /**
32 \retval true complete success
33 \retval false needs more data
34 \throws ?? error.
35 */
36 bool parse(MemBuf *rawData, MemBuf *parsedContent);
774c051c 37
38 bool needsMoreData() const;
39 bool needsMoreSpace() const;
774c051c 40
41private:
42 typedef void (ChunkedCodingParser::*Step)();
43
44private:
45 bool mayContinue() const;
46
5c550f5f
AR
47 void parseChunkSize();
48 void parseUnusedChunkExtension();
49 void parseLastChunkExtension();
774c051c 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);
5c550f5f 58 bool findCrlf(size_t &crlfBeg, size_t &crlfEnd, bool &quoted, bool &slashed);
774c051c 59
60private:
5c550f5f
AR
61 static Step psChunkSize;
62 static Step psUnusedChunkExtension;
63 static Step psLastChunkExtension;
774c051c 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;
47f6e231 73 uint64_t theChunkSize;
74 uint64_t theLeftBodySize;
774c051c 75 bool doNeedMoreData;
5c550f5f
AR
76 bool inQuoted; ///< stores parsing state for incremental findCrlf
77 bool inSlashed; ///< stores parsing state for incremental findCrlf
83c51da9
CT
78
79public:
80 int64_t useOriginBody;
774c051c 81};
82
83#endif /* SQUID_CHUNKEDCODINGPARSER_H */
f53969cc 84