summaryrefslogtreecommitdiffstats
path: root/src/HTTPServer/TransferEncodingParser.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-01-03 15:59:55 +0100
committerMattes D <github@xoft.cz>2016-03-01 16:19:56 +0100
commitfea556ca1b8aeec975f5276d5d829ee6275841d9 (patch)
tree9a61a61edbb232c01bfb34e1c2959542d470887e /src/HTTPServer/TransferEncodingParser.cpp
parentAdded HTTPResponseParser. (diff)
downloadcuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.gz
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.bz2
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.lz
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.xz
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.tar.zst
cuberite-fea556ca1b8aeec975f5276d5d829ee6275841d9.zip
Diffstat (limited to 'src/HTTPServer/TransferEncodingParser.cpp')
-rw-r--r--src/HTTPServer/TransferEncodingParser.cpp132
1 files changed, 0 insertions, 132 deletions
diff --git a/src/HTTPServer/TransferEncodingParser.cpp b/src/HTTPServer/TransferEncodingParser.cpp
deleted file mode 100644
index 8b703fd42..000000000
--- a/src/HTTPServer/TransferEncodingParser.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-
-// TransferEncodingParser.cpp
-
-// Implements the cTransferEncodingParser class and its descendants representing the parser for the various transfer encodings (chunked etc.)
-
-#include "Globals.h"
-#include "TransferEncodingParser.h"
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// cChunkedTEParser:
-
-class cChunkedTEParser:
- public cTransferEncodingParser
-{
- typedef cTransferEncodingParser Super;
-
-public:
- cChunkedTEParser(cCallbacks & a_Callbacks):
- Super(a_Callbacks),
- m_IsFinished(false)
- {
- }
-
-
-protected:
-
- /** True if the datastream has finished (zero-length chunk received). */
- bool m_IsFinished;
-
-
- // cTransferEncodingParser overrides:
- virtual size_t Parse(const char * a_Data, size_t a_Size) override
- {
- // TODO
- m_Callbacks.OnError("cChunkedTEParser not implemented yet");
- return AString::npos;
- }
-
- virtual void Finish(void) override
- {
- if (!m_IsFinished)
- {
- m_Callbacks.OnError("ChunkedTransferEncoding: Finish signal received before the data stream ended");
- }
- m_IsFinished = true;
- }
-};
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// cIdentityTEParser:
-
-class cIdentityTEParser:
- public cTransferEncodingParser
-{
- typedef cTransferEncodingParser Super;
-
-public:
- cIdentityTEParser(cCallbacks & a_Callbacks, size_t a_ContentLength):
- Super(a_Callbacks),
- m_BytesLeft(a_ContentLength)
- {
- }
-
-
-protected:
- /** How many bytes of content are left before the message ends. */
- size_t m_BytesLeft;
-
- // cTransferEncodingParser overrides:
- virtual size_t Parse(const char * a_Data, size_t a_Size) override
- {
- auto size = std::min(a_Size, m_BytesLeft);
- if (size > 0)
- {
- m_Callbacks.OnBodyData(a_Data, size);
- }
- m_BytesLeft -= size;
- if (m_BytesLeft == 0)
- {
- m_Callbacks.OnBodyFinished();
- }
- return a_Size - size;
- }
-
- virtual void Finish(void) override
- {
- if (m_BytesLeft > 0)
- {
- m_Callbacks.OnError("IdentityTransferEncoding: body was truncated");
- }
- else
- {
- // BodyFinished has already been called, just bail out
- }
- }
-};
-
-
-
-
-
-////////////////////////////////////////////////////////////////////////////////
-// cTransferEncodingParser:
-
-cTransferEncodingParserPtr cTransferEncodingParser::Create(
- cCallbacks & a_Callbacks,
- const AString & a_TransferEncoding,
- size_t a_ContentLength
-)
-{
- if (a_TransferEncoding == "chunked")
- {
- return std::make_shared<cChunkedTEParser>(a_Callbacks);
- }
- if (a_TransferEncoding.empty())
- {
- return std::make_shared<cIdentityTEParser>(a_Callbacks, a_ContentLength);
- }
- return nullptr;
-}
-
-
-
-