From: Amos Jeffries Date: Sun, 29 Mar 2015 04:38:29 +0000 (-0700) Subject: Shuffle ChunkedCodingParser into Http1:: namespace X-Git-Tag: merge-candidate-3-v1~86^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51c3e7f00a7b69740b3872402cce1b78a17e7a98;p=thirdparty%2Fsquid.git Shuffle ChunkedCodingParser into Http1:: namespace --- diff --git a/src/adaptation/icap/ModXact.cc b/src/adaptation/icap/ModXact.cc index c4af75942e..638bb7f985 100644 --- a/src/adaptation/icap/ModXact.cc +++ b/src/adaptation/icap/ModXact.cc @@ -1104,7 +1104,7 @@ void Adaptation::Icap::ModXact::decideOnParsingBody() debugs(93, 5, HERE << "expecting a body"); state.parsing = State::psBody; replyHttpBodySize = 0; - bodyParser = new ChunkedCodingParser; + bodyParser = new Http1::ChunkedCodingParser; makeAdaptedBodyPipe("adapted response from the ICAP server"); Must(state.sending == State::sendingAdapted); } else { diff --git a/src/adaptation/icap/ModXact.h b/src/adaptation/icap/ModXact.h index a186e0a0f5..56e4bc9d1a 100644 --- a/src/adaptation/icap/ModXact.h +++ b/src/adaptation/icap/ModXact.h @@ -14,6 +14,7 @@ #include "adaptation/icap/Launcher.h" #include "adaptation/icap/Xaction.h" #include "BodyPipe.h" +#include "http/one/forward.h" /* * ICAPModXact implements ICAP REQMOD and RESPMOD transaction using @@ -25,8 +26,6 @@ * receive the HTTP body. */ -class ChunkedCodingParser; - namespace Adaptation { namespace Icap @@ -250,7 +249,7 @@ private: uint64_t virginConsumed; // virgin data consumed so far Preview preview; // use for creating (writing) the preview - ChunkedCodingParser *bodyParser; // ICAP response body parser + Http1::ChunkedCodingParser *bodyParser; // ICAP response body parser bool canStartBypass; // enables bypass of transaction failures bool protectGroupBypass; // protects ServiceGroup-wide bypass of failures diff --git a/src/client_side.cc b/src/client_side.cc index 9c4b0d119b..6493a76bbe 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -3275,7 +3275,7 @@ ConnStateData::handleChunkedRequestBody(size_t &putSize) if (in.buf.isEmpty()) // nothing to do return ERR_NONE; - MemBuf raw; // ChunkedCodingParser only works with MemBufs + MemBuf raw; // Http1::ChunkedCodingParser only works with MemBufs // add one because MemBuf will assert if it cannot 0-terminate raw.init(in.buf.length(), in.buf.length()+1); raw.append(in.buf.c_str(), in.buf.length()); @@ -4773,7 +4773,7 @@ ConnStateData::startDechunkingRequest() Must(bodyPipe != NULL); debugs(33, 5, HERE << "start dechunking" << bodyPipe->status()); assert(!in.bodyParser); - in.bodyParser = new ChunkedCodingParser; + in.bodyParser = new Http1::ChunkedCodingParser; } /// put parsed content into input buffer and clean up diff --git a/src/client_side.h b/src/client_side.h index 1e93498778..9c17e95142 100644 --- a/src/client_side.h +++ b/src/client_side.h @@ -28,7 +28,6 @@ class ConnStateData; class ClientHttpRequest; class clientStreamNode; -class ChunkedCodingParser; namespace AnyP { class PortCfg; @@ -208,7 +207,7 @@ public: ~In(); bool maybeMakeSpaceAvailable(); - ChunkedCodingParser *bodyParser; ///< parses chunked request body + Http1::ChunkedCodingParser *bodyParser; ///< parses chunked request body SBuf buf; } in; diff --git a/src/http.cc b/src/http.cc index 7f7cde90b0..c6d4a7b2f9 100644 --- a/src/http.cc +++ b/src/http.cc @@ -788,7 +788,7 @@ HttpStateData::processReplyHeader() flags.chunked = false; if (newrep->sline.protocol == AnyP::PROTO_HTTP && newrep->header.chunked()) { flags.chunked = true; - httpChunkDecoder = new ChunkedCodingParser; + httpChunkDecoder = new Http1::ChunkedCodingParser; } if (!peerSupportsConnectionPinning()) diff --git a/src/http.h b/src/http.h index 53f5f60d50..6b812838a9 100644 --- a/src/http.h +++ b/src/http.h @@ -11,9 +11,9 @@ #include "clients/Client.h" #include "comm.h" +#include "http/forward.h" #include "HttpStateFlags.h" -class ChunkedCodingParser; class FwdState; class HttpHeader; @@ -120,7 +120,7 @@ private: /// Parser being used at present to parse the HTTP/ICY server response. Http1::ResponseParserPointer hp; - ChunkedCodingParser *httpChunkDecoder; + Http1::ChunkedCodingParser *httpChunkDecoder; /// amount of message payload/body received so far. int64_t payloadSeen; diff --git a/src/http/one/ChunkedCodingParser.cc b/src/http/one/ChunkedCodingParser.cc index c74ddae089..aabbf28134 100644 --- a/src/http/one/ChunkedCodingParser.cc +++ b/src/http/one/ChunkedCodingParser.cc @@ -13,20 +13,21 @@ #include "MemBuf.h" #include "Parsing.h" -ChunkedCodingParser::Step ChunkedCodingParser::psChunkSize = &ChunkedCodingParser::parseChunkSize; -ChunkedCodingParser::Step ChunkedCodingParser::psUnusedChunkExtension = &ChunkedCodingParser::parseUnusedChunkExtension; -ChunkedCodingParser::Step ChunkedCodingParser::psLastChunkExtension = &ChunkedCodingParser::parseLastChunkExtension; -ChunkedCodingParser::Step ChunkedCodingParser::psChunkBody = &ChunkedCodingParser::parseChunkBody; -ChunkedCodingParser::Step ChunkedCodingParser::psChunkEnd = &ChunkedCodingParser::parseChunkEnd; -ChunkedCodingParser::Step ChunkedCodingParser::psTrailer = &ChunkedCodingParser::parseTrailer; -ChunkedCodingParser::Step ChunkedCodingParser::psMessageEnd = &ChunkedCodingParser::parseMessageEnd; - -ChunkedCodingParser::ChunkedCodingParser() +Http::One::ChunkedCodingParser::Step Http::One::ChunkedCodingParser::psChunkSize = &Http::One::ChunkedCodingParser::parseChunkSize; +Http::One::ChunkedCodingParser::Step Http::One::ChunkedCodingParser::psUnusedChunkExtension = &Http::One::ChunkedCodingParser::parseUnusedChunkExtension; +Http::One::ChunkedCodingParser::Step Http::One::ChunkedCodingParser::psLastChunkExtension = &Http::One::ChunkedCodingParser::parseLastChunkExtension; +Http::One::ChunkedCodingParser::Step Http::One::ChunkedCodingParser::psChunkBody = &Http::One::ChunkedCodingParser::parseChunkBody; +Http::One::ChunkedCodingParser::Step Http::One::ChunkedCodingParser::psChunkEnd = &Http::One::ChunkedCodingParser::parseChunkEnd; +Http::One::ChunkedCodingParser::Step Http::One::ChunkedCodingParser::psTrailer = &Http::One::ChunkedCodingParser::parseTrailer; +Http::One::ChunkedCodingParser::Step Http::One::ChunkedCodingParser::psMessageEnd = &Http::One::ChunkedCodingParser::parseMessageEnd; + +Http::One::ChunkedCodingParser::ChunkedCodingParser() { reset(); } -void ChunkedCodingParser::reset() +void +Http::One::ChunkedCodingParser::reset() { theStep = psChunkSize; theChunkSize = theLeftBodySize = 0; @@ -36,7 +37,8 @@ void ChunkedCodingParser::reset() inQuoted = inSlashed = false; } -bool ChunkedCodingParser::parse(MemBuf *rawData, MemBuf *parsedContent) +bool +Http::One::ChunkedCodingParser::parse(MemBuf *rawData, MemBuf *parsedContent) { Must(rawData && parsedContent); theIn = rawData; @@ -53,23 +55,27 @@ bool ChunkedCodingParser::parse(MemBuf *rawData, MemBuf *parsedContent) return theStep == psMessageEnd; } -bool ChunkedCodingParser::needsMoreData() const +bool +Http::One::ChunkedCodingParser::needsMoreData() const { return doNeedMoreData; } -bool ChunkedCodingParser::needsMoreSpace() const +bool +Http::One::ChunkedCodingParser::needsMoreSpace() const { assert(theOut); return theStep == psChunkBody && !theOut->hasPotentialSpace(); } -bool ChunkedCodingParser::mayContinue() const +bool +Http::One::ChunkedCodingParser::mayContinue() const { return !needsMoreData() && !needsMoreSpace() && theStep != psMessageEnd; } -void ChunkedCodingParser::parseChunkSize() +void +Http::One::ChunkedCodingParser::parseChunkSize() { Must(theChunkSize <= 0); // Should(), really @@ -98,7 +104,8 @@ void ChunkedCodingParser::parseChunkSize() throw TexcHere("corrupted chunk size"); } -void ChunkedCodingParser::parseUnusedChunkExtension() +void +Http::One::ChunkedCodingParser::parseUnusedChunkExtension() { size_t crlfBeg = 0; size_t crlfEnd = 0; @@ -112,7 +119,8 @@ void ChunkedCodingParser::parseUnusedChunkExtension() } } -void ChunkedCodingParser::parseChunkBody() +void +Http::One::ChunkedCodingParser::parseChunkBody() { Must(theLeftBodySize > 0); // Should, really @@ -132,7 +140,8 @@ void ChunkedCodingParser::parseChunkBody() Must(needsMoreData() || needsMoreSpace()); } -void ChunkedCodingParser::parseChunkEnd() +void +Http::One::ChunkedCodingParser::parseChunkEnd() { Must(theLeftBodySize == 0); // Should(), really @@ -154,7 +163,8 @@ void ChunkedCodingParser::parseChunkEnd() doNeedMoreData = true; } -void ChunkedCodingParser::parseTrailer() +void +Http::One::ChunkedCodingParser::parseTrailer() { Must(theChunkSize == 0); // Should(), really @@ -162,7 +172,8 @@ void ChunkedCodingParser::parseTrailer() parseTrailerHeader(); } -void ChunkedCodingParser::parseTrailerHeader() +void +Http::One::ChunkedCodingParser::parseTrailerHeader() { size_t crlfBeg = 0; size_t crlfEnd = 0; @@ -185,14 +196,16 @@ void ChunkedCodingParser::parseTrailerHeader() doNeedMoreData = true; } -void ChunkedCodingParser::parseMessageEnd() +void +Http::One::ChunkedCodingParser::parseMessageEnd() { // termination step, should not be called Must(false); // Should(), really } /// Finds next CRLF. Does not store parsing state. -bool ChunkedCodingParser::findCrlf(size_t &crlfBeg, size_t &crlfEnd) +bool +Http::One::ChunkedCodingParser::findCrlf(size_t &crlfBeg, size_t &crlfEnd) { bool quoted = false; bool slashed = false; @@ -201,7 +214,8 @@ bool ChunkedCodingParser::findCrlf(size_t &crlfBeg, size_t &crlfEnd) /// Finds next CRLF. Parsing state stored in quoted and slashed /// parameters. Incremental: can resume when more data is available. -bool ChunkedCodingParser::findCrlf(size_t &crlfBeg, size_t &crlfEnd, bool "ed, bool &slashed) +bool +Http::One::ChunkedCodingParser::findCrlf(size_t &crlfBeg, size_t &crlfEnd, bool "ed, bool &slashed) { // XXX: This code was copied, with permission, from another software. // There is a similar and probably better code inside httpHeaderParse @@ -263,7 +277,8 @@ bool ChunkedCodingParser::findCrlf(size_t &crlfBeg, size_t &crlfEnd, bool "e } // chunk-extension= *( ";" chunk-ext-name [ "=" chunk-ext-val ] ) -void ChunkedCodingParser::parseLastChunkExtension() +void +Http::One::ChunkedCodingParser::parseLastChunkExtension() { size_t crlfBeg = 0; size_t crlfEnd = 0; diff --git a/src/http/one/ChunkedCodingParser.h b/src/http/one/ChunkedCodingParser.h index 733dc05639..f7e9753eed 100644 --- a/src/http/one/ChunkedCodingParser.h +++ b/src/http/one/ChunkedCodingParser.h @@ -6,16 +6,24 @@ * Please see the COPYING and CONTRIBUTORS files for details. */ -#ifndef SQUID_CHUNKEDCODINGPARSER_H -#define SQUID_CHUNKEDCODINGPARSER_H +#ifndef SQUID_SRC_HTTP_ONE_CHUNKEDCODINGPARSER_H +#define SQUID_SRC_HTTP_ONE_CHUNKEDCODINGPARSER_H + +#include "http/one/forward.h" class MemBuf; +namespace Http +{ +namespace One +{ + /** - \ingroup ChunkEncodingAPI Chunked Encoding API - \par * ChunkedCodingParser is an incremental parser for chunked transfer coding - * used by HTTP and ICAP. The parser shovels content bytes from the raw + * defined in RFC 7230 section 4.1. + * http://tools.ietf.org/html/rfc7230#section-4.1 + * + * The parser shovels content bytes from the raw * input buffer into the content output buffer, both caller-supplied. * Ignores chunk extensions except for ICAP's ieof. * Has a trailer-handling placeholder. @@ -39,7 +47,7 @@ public: bool needsMoreSpace() const; private: - typedef void (ChunkedCodingParser::*Step)(); + typedef void (Http1::ChunkedCodingParser::*Step)(); private: bool mayContinue() const; @@ -80,5 +88,8 @@ public: int64_t useOriginBody; }; -#endif /* SQUID_CHUNKEDCODINGPARSER_H */ +} // namespace One +} // namespace Http + +#endif /* SQUID_SRC_HTTP_ONE_CHUNKEDCODINGPARSER_H */ diff --git a/src/http/one/forward.h b/src/http/one/forward.h index d7bf5ced11..afb4b5b88f 100644 --- a/src/http/one/forward.h +++ b/src/http/one/forward.h @@ -17,6 +17,8 @@ namespace One { class Parser; typedef RefCount ParserPointer; +class ChunkedCodingParser; + class RequestParser; typedef RefCount RequestParserPointer;