summaryrefslogtreecommitdiffstats
path: root/source/HTTPServer/HTTPFormParser.h
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-09-28 19:30:25 +0200
committermadmaxoft <github@xoft.cz>2013-09-28 19:30:25 +0200
commit8130e6dd5439e381aae18532ede48441a4b46155 (patch)
tree679ffa469ffb3e00629128a353bd2cb2347f915f /source/HTTPServer/HTTPFormParser.h
parentAdded URLDecode() and ReplaceAllCharOccurrences() to StringUtils. (diff)
downloadcuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar
cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.gz
cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.bz2
cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.lz
cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.xz
cuberite-8130e6dd5439e381aae18532ede48441a4b46155.tar.zst
cuberite-8130e6dd5439e381aae18532ede48441a4b46155.zip
Diffstat (limited to 'source/HTTPServer/HTTPFormParser.h')
-rw-r--r--source/HTTPServer/HTTPFormParser.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/source/HTTPServer/HTTPFormParser.h b/source/HTTPServer/HTTPFormParser.h
new file mode 100644
index 000000000..72a7dfc05
--- /dev/null
+++ b/source/HTTPServer/HTTPFormParser.h
@@ -0,0 +1,64 @@
+
+// HTTPFormParser.h
+
+// Declares the cHTTPFormParser class representing a parser for forms sent over HTTP
+
+
+
+
+#pragma once
+
+
+
+
+
+// fwd:
+class cHTTPRequest;
+
+
+
+
+
+class cHTTPFormParser :
+ public std::map<AString, AString>
+{
+public:
+ cHTTPFormParser(cHTTPRequest & a_Request);
+
+ /// Adds more data into the parser, as the request body is received
+ void Parse(const char * a_Data, int a_Size);
+
+ /** Notifies that there's no more data incoming and the parser should finish its parsing.
+ Returns true if parsing successful
+ */
+ bool Finish(void);
+
+ /// Returns true if the headers suggest the request has form data parseable by this class
+ static bool HasFormData(const cHTTPRequest & a_Request);
+
+protected:
+ enum eKind
+ {
+ fpkURL, ///< The form has been transmitted as parameters to a GET request
+ fpkFormUrlEncoded, ///< The form has been POSTed or PUT, with Content-Type of "application/x-www-form-urlencoded"
+ fpkMultipart, ///< The form has been POSTed or PUT, with Content-Type of "multipart/*". Currently unsupported
+ };
+
+ /// The kind of the parser (decided in the constructor, used in Parse()
+ eKind m_Kind;
+
+ AString m_IncomingData;
+
+ bool m_IsValid;
+
+
+ /// Parses m_IncomingData as form-urlencoded data (fpkURL or fpkFormUrlEncoded kinds)
+ void ParseFormUrlEncoded(void);
+
+ /// Parses m_IncomingData as multipart data (fpkMultipart kind)
+ void ParseMultipart(void);
+} ;
+
+
+
+