diff options
author | madmaxoft <github@xoft.cz> | 2013-10-04 09:30:15 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2013-10-04 13:10:30 +0200 |
commit | d8229a55316183b523c61f28f88d64e6c8f3a96a (patch) | |
tree | 6971c74a08f6e01ab22bc08e849fa3bb987fa3bd /source/HTTPServer/MultipartParser.h | |
parent | Added cNameValueParser. (diff) | |
download | cuberite-d8229a55316183b523c61f28f88d64e6c8f3a96a.tar cuberite-d8229a55316183b523c61f28f88d64e6c8f3a96a.tar.gz cuberite-d8229a55316183b523c61f28f88d64e6c8f3a96a.tar.bz2 cuberite-d8229a55316183b523c61f28f88d64e6c8f3a96a.tar.lz cuberite-d8229a55316183b523c61f28f88d64e6c8f3a96a.tar.xz cuberite-d8229a55316183b523c61f28f88d64e6c8f3a96a.tar.zst cuberite-d8229a55316183b523c61f28f88d64e6c8f3a96a.zip |
Diffstat (limited to '')
-rw-r--r-- | source/HTTPServer/MultipartParser.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/source/HTTPServer/MultipartParser.h b/source/HTTPServer/MultipartParser.h new file mode 100644 index 000000000..d853929ed --- /dev/null +++ b/source/HTTPServer/MultipartParser.h @@ -0,0 +1,76 @@ + +// MultipartParser.h + +// Declares the cMultipartParser class that parses messages in "multipart/*" encoding into the separate parts + + + + + +#pragma once + +#include "EnvelopeParser.h" + + + + + +class cMultipartParser : + protected cEnvelopeParser::cCallbacks +{ +public: + class cCallbacks + { + public: + /// Called when a new part starts + virtual void OnPartStart(void) = 0; + + /// Called when a complete header line is received for a part + virtual void OnPartHeader(const AString & a_Key, const AString & a_Value) = 0; + + /// Called when body for a part is received + virtual void OnPartData(const char * a_Data, int a_Size) = 0; + + /// Called when the current part ends + virtual void OnPartEnd(void) = 0; + } ; + + /// Creates the parser, expects to find the boundary in a_ContentType + cMultipartParser(const AString & a_ContentType, cCallbacks & a_Callbacks); + + /// Parses more incoming data + void Parse(const char * a_Data, int a_Size); + +protected: + /// The callbacks to call for various parsing events + cCallbacks & m_Callbacks; + + /// True if the data parsed so far is valid; if false, further parsing is skipped + bool m_IsValid; + + /// Parser for each part's envelope + cEnvelopeParser m_EnvelopeParser; + + /// Buffer for the incoming data until it is parsed + AString m_IncomingData; + + /// The boundary, excluding both the initial "--" and the terminating CRLF + AString m_Boundary; + + /// Set to true if some data for the current part has already been signalized to m_Callbacks. Used for proper CRLF inserting. + bool m_HasHadData; + + + /// Parse one line of incoming data. The CRLF has already been stripped from a_Data / a_Size + void ParseLine(const char * a_Data, int a_Size); + + /// Parse one line of incoming data in the headers section of a part. The CRLF has already been stripped from a_Data / a_Size + void ParseHeaderLine(const char * a_Data, int a_Size); + + // cEnvelopeParser overrides: + virtual void OnHeaderLine(const AString & a_Key, const AString & a_Value) override; +} ; + + + + |