From fea556ca1b8aeec975f5276d5d829ee6275841d9 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 3 Jan 2016 15:59:55 +0100 Subject: Renamed HTTPServer folder to HTTP. It contains client code as well. --- src/HTTP/TransferEncodingParser.h | 76 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/HTTP/TransferEncodingParser.h (limited to 'src/HTTP/TransferEncodingParser.h') diff --git a/src/HTTP/TransferEncodingParser.h b/src/HTTP/TransferEncodingParser.h new file mode 100644 index 000000000..ce3d01df7 --- /dev/null +++ b/src/HTTP/TransferEncodingParser.h @@ -0,0 +1,76 @@ + +// TransferEncodingParser.h + +// Declares the cTransferEncodingParser class representing the parser for the various transfer encodings (chunked etc.) + +#pragma once + + + + + +// fwd: +class cTransferEncodingParser; +typedef SharedPtr cTransferEncodingParserPtr; + + + + + +/** Used as both the interface that all the parsers share and the (static) factory creating such parsers. */ +class cTransferEncodingParser +{ +public: + class cCallbacks + { + public: + // Force a virtual destructor in descendants + virtual ~cCallbacks() {} + + /** Called when an error has occured while parsing. */ + virtual void OnError(const AString & a_ErrorDescription) = 0; + + /** Called for each chunk of the incoming body data. */ + virtual void OnBodyData(const void * a_Data, size_t a_Size) = 0; + + /** Called when the entire body has been reported by OnBodyData(). */ + virtual void OnBodyFinished(void) = 0; + }; + + + // Force a virtual destructor in all descendants + virtual ~cTransferEncodingParser() {} + + /** Parses the incoming data and calls the appropriate callbacks. + Returns the number of bytes from the end of a_Data that is already not part of this message (if the parser can detect it). + Returns AString::npos on an error. */ + virtual size_t Parse(const char * a_Data, size_t a_Size) = 0; + + /** To be called when the stream is terminated from the source (connection closed). + Flushes any buffers and calls appropriate callbacks. */ + virtual void Finish(void) = 0; + + /** Creates a new parser for the specified encoding. + If the encoding is not known, returns a nullptr. + a_ContentLength is the length of the content, received in a Content-Length header. + It is used for the Identity encoding, it is ignored for the Chunked encoding. */ + static cTransferEncodingParserPtr Create( + cCallbacks & a_Callbacks, + const AString & a_TransferEncoding, + size_t a_ContentLength + ); + +protected: + /** The callbacks used to report progress. */ + cCallbacks & m_Callbacks; + + + cTransferEncodingParser(cCallbacks & a_Callbacks): + m_Callbacks(a_Callbacks) + { + } +}; + + + + -- cgit v1.2.3