summaryrefslogtreecommitdiffstats
path: root/src/HTTP/TransferEncodingParser.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-03-01 16:58:43 +0100
committerMattes D <github@xoft.cz>2016-03-01 16:58:43 +0100
commit7cc8f8dd2213cade66633d196f579895385a869a (patch)
tree83219a6eaf87a2050c10662fb8caa5d1514a6af4 /src/HTTP/TransferEncodingParser.h
parentMerge pull request #3057 from tonibm19/master (diff)
parentHTTP: Fixed typos and bad leftovers. (diff)
downloadcuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar
cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.gz
cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.bz2
cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.lz
cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.xz
cuberite-7cc8f8dd2213cade66633d196f579895385a869a.tar.zst
cuberite-7cc8f8dd2213cade66633d196f579895385a869a.zip
Diffstat (limited to '')
-rw-r--r--src/HTTP/TransferEncodingParser.h76
1 files changed, 76 insertions, 0 deletions
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<cTransferEncodingParser> 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)
+ {
+ }
+};
+
+
+
+