summaryrefslogtreecommitdiffstats
path: root/source/HTTPServer/HTTPFormParser.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-09-28 23:02:16 +0200
committermadmaxoft <github@xoft.cz>2013-09-28 23:02:16 +0200
commitbb0fb0aa3055d797e58bc17d515e55a447c9e6a3 (patch)
tree18361e979751a43bc7d7161fb72c4961ed753d24 /source/HTTPServer/HTTPFormParser.cpp
parentFixed recognition of multipart-form-data forms. (diff)
downloadcuberite-bb0fb0aa3055d797e58bc17d515e55a447c9e6a3.tar
cuberite-bb0fb0aa3055d797e58bc17d515e55a447c9e6a3.tar.gz
cuberite-bb0fb0aa3055d797e58bc17d515e55a447c9e6a3.tar.bz2
cuberite-bb0fb0aa3055d797e58bc17d515e55a447c9e6a3.tar.lz
cuberite-bb0fb0aa3055d797e58bc17d515e55a447c9e6a3.tar.xz
cuberite-bb0fb0aa3055d797e58bc17d515e55a447c9e6a3.tar.zst
cuberite-bb0fb0aa3055d797e58bc17d515e55a447c9e6a3.zip
Diffstat (limited to 'source/HTTPServer/HTTPFormParser.cpp')
-rw-r--r--source/HTTPServer/HTTPFormParser.cpp69
1 files changed, 12 insertions, 57 deletions
diff --git a/source/HTTPServer/HTTPFormParser.cpp b/source/HTTPServer/HTTPFormParser.cpp
index 6f6dc02b2..631424391 100644
--- a/source/HTTPServer/HTTPFormParser.cpp
+++ b/source/HTTPServer/HTTPFormParser.cpp
@@ -11,6 +11,13 @@
+AString cHTTPFormParser::m_FormURLEncoded("application/x-www-form-urlencoded");
+AString cHTTPFormParser::m_MultipartFormData("multipart/form-data");
+
+
+
+
+
cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request) :
m_IsValid(true)
{
@@ -29,12 +36,12 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request) :
}
if ((a_Request.GetMethod() == "POST") || (a_Request.GetMethod() == "PUT"))
{
- if (a_Request.GetContentType() == "application/x-www-form-urlencoded")
+ if (a_Request.GetContentType() == m_FormURLEncoded)
{
m_Kind = fpkFormUrlEncoded;
return;
}
- if (strncmp(a_Request.GetContentType().c_str(), "multipart/form-data", 19) == 0)
+ if (a_Request.GetContentType().substr(0, m_MultipartFormData.length()) == m_MultipartFormData)
{
m_Kind = fpkMultipart;
return;
@@ -96,9 +103,10 @@ bool cHTTPFormParser::Finish(void)
bool cHTTPFormParser::HasFormData(const cHTTPRequest & a_Request)
{
+ const AString & ContentType = a_Request.GetContentType();
return (
- (a_Request.GetContentType() == "application/x-www-form-urlencoded") ||
- (strncmp(a_Request.GetContentType().c_str(), "multipart/form-data", 19) == 0) ||
+ (ContentType == m_FormURLEncoded) ||
+ (ContentType.substr(0, m_MultipartFormData.length()) == m_MultipartFormData) ||
(
(a_Request.GetMethod() == "GET") &&
(a_Request.GetURL().find('?') != AString::npos)
@@ -142,59 +150,6 @@ void cHTTPFormParser::ParseFormUrlEncoded(void)
}
} // for itr - Lines[]
m_IncomingData.clear();
-
- /*
- size_t len = m_IncomingData.size();
- if (len == 0)
- {
- // No values in the form, consider this valid, too.
- return;
- }
- size_t len1 = len - 1;
-
- for (size_t i = 0; i < len; )
- {
- char ch = m_IncomingData[i];
- AString Name;
- AString Value;
- while ((i < len1) && (ch != '=') && (ch != '&'))
- {
- if (ch == '+')
- {
- ch = ' ';
- }
- Name.push_back(ch);
- ch = m_IncomingData[++i];
- }
- if (i == len1)
- {
- Value.push_back(ch);
- }
-
- if (ch == '=')
- {
- ch = m_IncomingData[++i];
- while ((i < len1) && (ch != '&'))
- {
- if (ch == '+')
- {
- ch = ' ';
- }
- Value.push_back(ch);
- ch = m_IncomingData[++i];
- }
- if (i == len1)
- {
- Value.push_back(ch);
- }
- }
- (*this)[URLDecode(Name)] = URLDecode(Value);
- if (ch == '&')
- {
- ++i;
- }
- } // for i - m_IncomingData[]
- */
}