summaryrefslogtreecommitdiffstats
path: root/src/HTTPServer
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-05-01 15:08:15 +0200
committermadmaxoft <github@xoft.cz>2014-05-01 15:08:15 +0200
commit60850fe3e8da936d5b24460f33a1bf8f4d321ace (patch)
tree1720c81696ea344517d7d8b7456ca232445e421c /src/HTTPServer
parentAdded a mention to run as admin. (diff)
downloadcuberite-60850fe3e8da936d5b24460f33a1bf8f4d321ace.tar
cuberite-60850fe3e8da936d5b24460f33a1bf8f4d321ace.tar.gz
cuberite-60850fe3e8da936d5b24460f33a1bf8f4d321ace.tar.bz2
cuberite-60850fe3e8da936d5b24460f33a1bf8f4d321ace.tar.lz
cuberite-60850fe3e8da936d5b24460f33a1bf8f4d321ace.tar.xz
cuberite-60850fe3e8da936d5b24460f33a1bf8f4d321ace.tar.zst
cuberite-60850fe3e8da936d5b24460f33a1bf8f4d321ace.zip
Diffstat (limited to '')
-rw-r--r--src/HTTPServer/HTTPConnection.cpp14
-rw-r--r--src/HTTPServer/HTTPConnection.h12
-rw-r--r--src/HTTPServer/SslHTTPConnection.cpp10
-rw-r--r--src/HTTPServer/SslHTTPConnection.h2
4 files changed, 24 insertions, 14 deletions
diff --git a/src/HTTPServer/HTTPConnection.cpp b/src/HTTPServer/HTTPConnection.cpp
index 8e95eff2d..b127e7091 100644
--- a/src/HTTPServer/HTTPConnection.cpp
+++ b/src/HTTPServer/HTTPConnection.cpp
@@ -145,7 +145,7 @@ void cHTTPConnection::Terminate(void)
-void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
+bool cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
{
switch (m_State)
{
@@ -163,12 +163,12 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
m_CurrentRequest = NULL;
m_State = wcsInvalid;
m_HTTPServer.CloseConnection(*this);
- return;
+ return true;
}
if (m_CurrentRequest->IsInHeaders())
{
// The request headers are not yet complete
- return;
+ return false;
}
// The request has finished parsing its headers successfully, notify of it:
@@ -184,13 +184,12 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
// Process the rest of the incoming data into the request body:
if (a_Size > BytesConsumed)
{
- cHTTPConnection::DataReceived(a_Data + BytesConsumed, a_Size - BytesConsumed);
+ return cHTTPConnection::DataReceived(a_Data + BytesConsumed, a_Size - BytesConsumed);
}
else
{
- cHTTPConnection::DataReceived("", 0); // If the request has zero body length, let it be processed right-away
+ return cHTTPConnection::DataReceived("", 0); // If the request has zero body length, let it be processed right-away
}
- break;
}
case wcsRecvBody:
@@ -210,7 +209,7 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
{
m_State = wcsInvalid;
m_HTTPServer.CloseConnection(*this);
- return;
+ return true;
}
delete m_CurrentRequest;
m_CurrentRequest = NULL;
@@ -224,6 +223,7 @@ void cHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
break;
}
}
+ return false;
}
diff --git a/src/HTTPServer/HTTPConnection.h b/src/HTTPServer/HTTPConnection.h
index fc11f1ba6..6ea8a1ae8 100644
--- a/src/HTTPServer/HTTPConnection.h
+++ b/src/HTTPServer/HTTPConnection.h
@@ -91,9 +91,15 @@ protected:
// cSocketThreads::cCallback overrides:
- virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
- virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
- virtual void SocketClosed (void) override; // The socket has been closed for any reason
+ /** Data is received from the client.
+ Returns true if the connection has been closed as the result of parsing the data. */
+ virtual bool DataReceived(const char * a_Data, size_t a_Size) override;
+
+ /** Data can be sent to client */
+ virtual void GetOutgoingData(AString & a_Data) override;
+
+ /** The socket has been closed for any reason */
+ virtual void SocketClosed(void) override;
} ;
typedef std::vector<cHTTPConnection *> cHTTPConnections;
diff --git a/src/HTTPServer/SslHTTPConnection.cpp b/src/HTTPServer/SslHTTPConnection.cpp
index fff96bb2e..b6b222b47 100644
--- a/src/HTTPServer/SslHTTPConnection.cpp
+++ b/src/HTTPServer/SslHTTPConnection.cpp
@@ -25,7 +25,7 @@ cSslHTTPConnection::cSslHTTPConnection(cHTTPServer & a_HTTPServer, const cX509Ce
-void cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
+bool cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
{
// If there is outgoing data in the queue, notify the server that it should write it out:
if (!m_OutgoingData.empty())
@@ -52,13 +52,17 @@ void cSslHTTPConnection::DataReceived(const char * a_Data, size_t a_Size)
int NumRead = m_Ssl.ReadPlain(Buffer, sizeof(Buffer));
if (NumRead > 0)
{
- super::DataReceived(Buffer, (size_t)NumRead);
+ if (super::DataReceived(Buffer, (size_t)NumRead))
+ {
+ // The socket has been closed, and the object is already deleted. Bail out.
+ return true;
+ }
}
// If both failed, bail out:
if ((BytesWritten == 0) && (NumRead <= 0))
{
- return;
+ return false;
}
}
}
diff --git a/src/HTTPServer/SslHTTPConnection.h b/src/HTTPServer/SslHTTPConnection.h
index 2a648e8c8..653acbfce 100644
--- a/src/HTTPServer/SslHTTPConnection.h
+++ b/src/HTTPServer/SslHTTPConnection.h
@@ -36,7 +36,7 @@ protected:
cPublicKeyPtr m_PrivateKey;
// cHTTPConnection overrides:
- virtual void DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
+ virtual bool DataReceived (const char * a_Data, size_t a_Size) override; // Data is received from the client
virtual void GetOutgoingData(AString & a_Data) override; // Data can be sent to client
} ;