summaryrefslogtreecommitdiffstats
path: root/source/HTTPServer
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2013-10-05 23:08:16 +0200
committermadmaxoft <github@xoft.cz>2013-10-05 23:08:16 +0200
commitb5c90d7b20fede4e643e96417684c7c009d063cb (patch)
tree16729dacd792717ae4818dbe019b0fd02c58048a /source/HTTPServer
parentFixed Base64Decode() returning wrong value. (diff)
downloadcuberite-b5c90d7b20fede4e643e96417684c7c009d063cb.tar
cuberite-b5c90d7b20fede4e643e96417684c7c009d063cb.tar.gz
cuberite-b5c90d7b20fede4e643e96417684c7c009d063cb.tar.bz2
cuberite-b5c90d7b20fede4e643e96417684c7c009d063cb.tar.lz
cuberite-b5c90d7b20fede4e643e96417684c7c009d063cb.tar.xz
cuberite-b5c90d7b20fede4e643e96417684c7c009d063cb.tar.zst
cuberite-b5c90d7b20fede4e643e96417684c7c009d063cb.zip
Diffstat (limited to '')
-rw-r--r--source/HTTPServer/HTTPFormParser.cpp5
-rw-r--r--source/HTTPServer/HTTPMessage.cpp17
-rw-r--r--source/HTTPServer/HTTPMessage.h3
-rw-r--r--source/HTTPServer/HTTPServer.cpp15
-rw-r--r--source/HTTPServer/HTTPServer.h3
5 files changed, 28 insertions, 15 deletions
diff --git a/source/HTTPServer/HTTPFormParser.cpp b/source/HTTPServer/HTTPFormParser.cpp
index 85a789f7d..7db7b4e6d 100644
--- a/source/HTTPServer/HTTPFormParser.cpp
+++ b/source/HTTPServer/HTTPFormParser.cpp
@@ -32,7 +32,7 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba
}
if ((a_Request.GetMethod() == "POST") || (a_Request.GetMethod() == "PUT"))
{
- if (a_Request.GetContentType() == "application/x-www-form-urlencoded")
+ if (strncmp(a_Request.GetContentType().c_str(), "application/x-www-form-urlencoded", 33) == 0)
{
m_Kind = fpkFormUrlEncoded;
return;
@@ -44,7 +44,8 @@ cHTTPFormParser::cHTTPFormParser(cHTTPRequest & a_Request, cCallbacks & a_Callba
return;
}
}
- ASSERT(!"Unhandled request method");
+ // Invalid method / content type combination, this is not a HTTP form
+ m_IsValid = false;
}
diff --git a/source/HTTPServer/HTTPMessage.cpp b/source/HTTPServer/HTTPMessage.cpp
index 6cf9464a3..ab23866e6 100644
--- a/source/HTTPServer/HTTPMessage.cpp
+++ b/source/HTTPServer/HTTPMessage.cpp
@@ -120,6 +120,23 @@ int cHTTPRequest::ParseHeaders(const char * a_Data, int a_Size)
+AString cHTTPRequest::GetBareURL(void) const
+{
+ size_t idxQM = m_URL.find('?');
+ if (idxQM != AString::npos)
+ {
+ return m_URL.substr(0, idxQM);
+ }
+ else
+ {
+ return m_URL;
+ }
+}
+
+
+
+
+
int cHTTPRequest::ParseRequestLine(const char * a_Data, int a_Size)
{
m_IncomingHeaderData.append(a_Data, a_Size);
diff --git a/source/HTTPServer/HTTPMessage.h b/source/HTTPServer/HTTPMessage.h
index 151eb468f..f5284c535 100644
--- a/source/HTTPServer/HTTPMessage.h
+++ b/source/HTTPServer/HTTPMessage.h
@@ -82,6 +82,9 @@ public:
/// Returns the URL used in the request
const AString & GetURL(void) const { return m_URL; }
+ /// Returns the URL used in the request, without any parameters
+ AString GetBareURL(void) const;
+
/// Sets the UserData pointer that is stored within this request. The request doesn't touch this data (doesn't delete it)!
void SetUserData(void * a_UserData) { m_UserData = a_UserData; }
diff --git a/source/HTTPServer/HTTPServer.cpp b/source/HTTPServer/HTTPServer.cpp
index 43bb751c4..7e216c629 100644
--- a/source/HTTPServer/HTTPServer.cpp
+++ b/source/HTTPServer/HTTPServer.cpp
@@ -127,25 +127,16 @@ cHTTPServer::cHTTPServer(void) :
-bool cHTTPServer::Initialize(cIniFile & a_IniFile)
+bool cHTTPServer::Initialize(const AString & a_PortsIPv4, const AString & a_PortsIPv6)
{
- if (!a_IniFile.GetValueSetB("WebAdmin", "Enabled", false))
- {
- // The WebAdmin is disabled
- return true;
- }
bool HasAnyPort;
- HasAnyPort = m_ListenThreadIPv4.Initialize(a_IniFile.GetValueSet("WebAdmin", "Port", "8081"));
- HasAnyPort = m_ListenThreadIPv6.Initialize(a_IniFile.GetValueSet("WebAdmin", "PortsIPv6", "8082, 3300")) || HasAnyPort;
+ HasAnyPort = m_ListenThreadIPv4.Initialize(a_PortsIPv4);
+ HasAnyPort = m_ListenThreadIPv6.Initialize(a_PortsIPv6) || HasAnyPort;
if (!HasAnyPort)
{
- LOG("WebAdmin is disabled");
return false;
}
- // DEBUG:
- return Start(g_DebugCallbacks);
-
return true;
}
diff --git a/source/HTTPServer/HTTPServer.h b/source/HTTPServer/HTTPServer.h
index efe60809d..2ecb75fdd 100644
--- a/source/HTTPServer/HTTPServer.h
+++ b/source/HTTPServer/HTTPServer.h
@@ -51,7 +51,8 @@ public:
cHTTPServer(void);
- bool Initialize(cIniFile & a_IniFile);
+ /// Initializes the server on the specified ports
+ bool Initialize(const AString & a_PortsIPv4, const AString & a_PortsIPv6);
/// Starts the server and assigns the callbacks to use for incoming requests
bool Start(cCallbacks & a_Callbacks);