1
0
Fork 0

Renamed the HTTP classes to indicate they're for server.

This commit is contained in:
Mattes D 2015-12-25 19:42:50 +01:00
parent 48532d86cf
commit 2dbc54a148
9 changed files with 75 additions and 77 deletions

View File

@ -6,31 +6,31 @@ include_directories ("${PROJECT_SOURCE_DIR}/../")
SET (SRCS
EnvelopeParser.cpp
HTTPConnection.cpp
HTTPFormParser.cpp
HTTPMessage.cpp
HTTPServer.cpp
HTTPServerConnection.cpp
MultipartParser.cpp
NameValueParser.cpp
SslHTTPConnection.cpp
SslHTTPServerConnection.cpp
UrlParser.cpp
)
SET (HDRS
EnvelopeParser.h
HTTPConnection.h
HTTPFormParser.h
HTTPMessage.h
HTTPServer.h
HTTPServerConnection.h
MultipartParser.h
NameValueParser.h
SslHTTPConnection.h
SslHTTPServerConnection.h
UrlParser.h
)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set_source_files_properties(HTTPServer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=global-constructors ")
set_source_files_properties(HTTPConnection.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum")
set_source_files_properties(HTTPServerConnection.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum")
set_source_files_properties(HTTPMessage.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=tautological-compare")
endif()

View File

@ -6,9 +6,9 @@
#include "Globals.h"
#include "HTTPServer.h"
#include "HTTPMessage.h"
#include "HTTPConnection.h"
#include "HTTPServerConnection.h"
#include "HTTPFormParser.h"
#include "SslHTTPConnection.h"
#include "SslHTTPServerConnection.h"
@ -28,7 +28,7 @@ class cDebugCallbacks :
public cHTTPServer::cCallbacks,
protected cHTTPFormParser::cCallbacks
{
virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override
virtual void OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request) override
{
UNUSED(a_Connection);
@ -39,7 +39,7 @@ class cDebugCallbacks :
}
virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override
virtual void OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override
{
UNUSED(a_Connection);
@ -51,7 +51,7 @@ class cDebugCallbacks :
}
virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override
virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request) override
{
cHTTPFormParser * FormParser = reinterpret_cast<cHTTPFormParser *>(a_Request.GetUserData());
if (FormParser != nullptr)
@ -268,11 +268,11 @@ cTCPLink::cCallbacksPtr cHTTPServer::OnIncomingConnection(const AString & a_Remo
if (m_Cert.get() != nullptr)
{
return std::make_shared<cSslHTTPConnection>(*this, m_Cert, m_CertPrivKey);
return std::make_shared<cSslHTTPServerConnection>(*this, m_Cert, m_CertPrivKey);
}
else
{
return std::make_shared<cHTTPConnection>(*this);
return std::make_shared<cHTTPServerConnection>(*this);
}
}
@ -280,7 +280,7 @@ cTCPLink::cCallbacksPtr cHTTPServer::OnIncomingConnection(const AString & a_Remo
void cHTTPServer::NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
void cHTTPServer::NewRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request)
{
m_Callbacks->OnRequestBegun(a_Connection, a_Request);
}
@ -289,7 +289,7 @@ void cHTTPServer::NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Re
void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size)
void cHTTPServer::RequestBody(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size)
{
m_Callbacks->OnRequestBody(a_Connection, a_Request, a_Data, a_Size);
}
@ -298,7 +298,7 @@ void cHTTPServer::RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_R
void cHTTPServer::RequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
void cHTTPServer::RequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request)
{
m_Callbacks->OnRequestFinished(a_Connection, a_Request);
a_Connection.AwaitNextRequest();

View File

@ -23,9 +23,7 @@
class cHTTPMessage;
class cHTTPRequest;
class cHTTPResponse;
class cHTTPConnection;
typedef std::vector<cHTTPConnection *> cHTTPConnections;
class cHTTPServerConnection;
@ -42,14 +40,14 @@ public:
/** Called when a new request arrives over a connection and all its headers have been parsed.
The request body needn't have arrived yet. */
virtual void OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0;
virtual void OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request) = 0;
/** Called when another part of request body has arrived.
May be called multiple times for a single request. */
virtual void OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) = 0;
virtual void OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) = 0;
/** Called when the request body has been fully received in previous calls to OnRequestBody() */
virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) = 0;
virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request) = 0;
} ;
cHTTPServer(void);
@ -65,8 +63,8 @@ public:
void Stop(void);
protected:
friend class cHTTPConnection;
friend class cSslHTTPConnection;
friend class cHTTPServerConnection;
friend class cSslHTTPServerConnection;
friend class cHTTPServerListenCallbacks;
/** The cNetwork API handle for the listening socket. */
@ -86,15 +84,15 @@ protected:
Returns the connection instance to be used as the cTCPLink callbacks. */
cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort);
/** Called by cHTTPConnection when it finishes parsing the request header */
void NewRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
/** Called by cHTTPServerConnection when it finishes parsing the request header */
void NewRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request);
/** Called by cHTTPConenction when it receives more data for the request body.
May be called multiple times for a single request. */
void RequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size);
void RequestBody(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size);
/** Called by cHTTPConnection when it detects that the request has finished (all of its body has been received) */
void RequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
/** Called by cHTTPServerConnection when it detects that the request has finished (all of its body has been received) */
void RequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request);
} ;

View File

@ -1,10 +1,10 @@
// HTTPConnection.cpp
// Implements the cHTTPConnection class representing a single persistent connection in the HTTP server.
// Implements the cHTTPServerConnection class representing a single persistent connection in the HTTP server.
#include "Globals.h"
#include "HTTPConnection.h"
#include "HTTPServerConnection.h"
#include "HTTPMessage.h"
#include "HTTPServer.h"
@ -12,7 +12,7 @@
cHTTPConnection::cHTTPConnection(cHTTPServer & a_HTTPServer) :
cHTTPServerConnection::cHTTPServerConnection(cHTTPServer & a_HTTPServer) :
m_HTTPServer(a_HTTPServer),
m_State(wcsRecvHeaders),
m_CurrentRequest(nullptr),
@ -25,7 +25,7 @@ cHTTPConnection::cHTTPConnection(cHTTPServer & a_HTTPServer) :
cHTTPConnection::~cHTTPConnection()
cHTTPServerConnection::~cHTTPServerConnection()
{
// LOGD("HTTP: Connection deleting: %p", this);
delete m_CurrentRequest;
@ -36,7 +36,7 @@ cHTTPConnection::~cHTTPConnection()
void cHTTPConnection::SendStatusAndReason(int a_StatusCode, const AString & a_Response)
void cHTTPServerConnection::SendStatusAndReason(int a_StatusCode, const AString & a_Response)
{
SendData(Printf("HTTP/1.1 %d %s\r\n", a_StatusCode, a_Response.c_str()));
SendData(Printf("Content-Length: %u\r\n\r\n", static_cast<unsigned>(a_Response.size())));
@ -48,7 +48,7 @@ void cHTTPConnection::SendStatusAndReason(int a_StatusCode, const AString & a_Re
void cHTTPConnection::SendNeedAuth(const AString & a_Realm)
void cHTTPServerConnection::SendNeedAuth(const AString & a_Realm)
{
SendData(Printf("HTTP/1.1 401 Unauthorized\r\nWWW-Authenticate: Basic realm=\"%s\"\r\nContent-Length: 0\r\n\r\n", a_Realm.c_str()));
m_State = wcsRecvHeaders;
@ -58,7 +58,7 @@ void cHTTPConnection::SendNeedAuth(const AString & a_Realm)
void cHTTPConnection::Send(const cHTTPResponse & a_Response)
void cHTTPServerConnection::Send(const cHTTPResponse & a_Response)
{
ASSERT(m_State == wcsRecvIdle);
AString toSend;
@ -71,7 +71,7 @@ void cHTTPConnection::Send(const cHTTPResponse & a_Response)
void cHTTPConnection::Send(const void * a_Data, size_t a_Size)
void cHTTPServerConnection::Send(const void * a_Data, size_t a_Size)
{
ASSERT(m_State == wcsSendingResp);
// We're sending in Chunked transfer encoding
@ -84,7 +84,7 @@ void cHTTPConnection::Send(const void * a_Data, size_t a_Size)
void cHTTPConnection::FinishResponse(void)
void cHTTPServerConnection::FinishResponse(void)
{
ASSERT(m_State == wcsSendingResp);
SendData("0\r\n\r\n");
@ -95,7 +95,7 @@ void cHTTPConnection::FinishResponse(void)
void cHTTPConnection::AwaitNextRequest(void)
void cHTTPServerConnection::AwaitNextRequest(void)
{
switch (m_State)
{
@ -133,7 +133,7 @@ void cHTTPConnection::AwaitNextRequest(void)
void cHTTPConnection::Terminate(void)
void cHTTPServerConnection::Terminate(void)
{
if (m_CurrentRequest != nullptr)
{
@ -146,7 +146,7 @@ void cHTTPConnection::Terminate(void)
void cHTTPConnection::OnLinkCreated(cTCPLinkPtr a_Link)
void cHTTPServerConnection::OnLinkCreated(cTCPLinkPtr a_Link)
{
ASSERT(m_Link == nullptr);
m_Link = a_Link;
@ -156,7 +156,7 @@ void cHTTPConnection::OnLinkCreated(cTCPLinkPtr a_Link)
void cHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size)
void cHTTPServerConnection::OnReceivedData(const char * a_Data, size_t a_Size)
{
ASSERT(m_Link != nullptr);
@ -198,12 +198,12 @@ void cHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size)
// Process the rest of the incoming data into the request body:
if (a_Size > BytesConsumed)
{
cHTTPConnection::OnReceivedData(a_Data + BytesConsumed, a_Size - BytesConsumed);
cHTTPServerConnection::OnReceivedData(a_Data + BytesConsumed, a_Size - BytesConsumed);
return;
}
else
{
cHTTPConnection::OnReceivedData("", 0); // If the request has zero body length, let it be processed right-away
cHTTPServerConnection::OnReceivedData("", 0); // If the request has zero body length, let it be processed right-away
return;
}
}
@ -246,7 +246,7 @@ void cHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size)
void cHTTPConnection::OnRemoteClosed(void)
void cHTTPServerConnection::OnRemoteClosed(void)
{
if (m_CurrentRequest != nullptr)
{
@ -260,7 +260,7 @@ void cHTTPConnection::OnRemoteClosed(void)
void cHTTPConnection::OnError(int a_ErrorCode, const AString & a_ErrorMsg)
void cHTTPServerConnection::OnError(int a_ErrorCode, const AString & a_ErrorMsg)
{
OnRemoteClosed();
}
@ -268,7 +268,7 @@ void cHTTPConnection::OnError(int a_ErrorCode, const AString & a_ErrorMsg)
void cHTTPConnection::SendData(const void * a_Data, size_t a_Size)
void cHTTPServerConnection::SendData(const void * a_Data, size_t a_Size)
{
m_Link->Send(a_Data, a_Size);
}

View File

@ -24,7 +24,7 @@ class cHTTPRequest;
class cHTTPConnection :
class cHTTPServerConnection :
public cTCPLink::cCallbacks
{
public:
@ -38,8 +38,8 @@ public:
wcsInvalid, ///< The request was malformed, the connection is closing
} ;
cHTTPConnection(cHTTPServer & a_HTTPServer);
virtual ~cHTTPConnection();
cHTTPServerConnection(cHTTPServer & a_HTTPServer);
virtual ~cHTTPServerConnection();
/** Sends HTTP status code together with a_Reason (used for HTTP errors).
Sends the a_Reason as the body as well, so that browsers display it. */
@ -116,7 +116,7 @@ protected:
}
} ;
typedef std::vector<cHTTPConnection *> cHTTPConnections;
typedef std::vector<cHTTPServerConnection *> cHTTPServerConnections;

View File

@ -1,17 +1,17 @@
// SslHTTPConnection.cpp
// Implements the cSslHTTPConnection class representing a HTTP connection made over a SSL link
// Implements the cSslHTTPServerConnection class representing a HTTP connection made over a SSL link
#include "Globals.h"
#include "SslHTTPConnection.h"
#include "SslHTTPServerConnection.h"
#include "HTTPServer.h"
cSslHTTPConnection::cSslHTTPConnection(cHTTPServer & a_HTTPServer, const cX509CertPtr & a_Cert, const cCryptoKeyPtr & a_PrivateKey) :
cSslHTTPServerConnection::cSslHTTPServerConnection(cHTTPServer & a_HTTPServer, const cX509CertPtr & a_Cert, const cCryptoKeyPtr & a_PrivateKey) :
super(a_HTTPServer),
m_Ssl(64000),
m_Cert(a_Cert),
@ -25,7 +25,7 @@ cSslHTTPConnection::cSslHTTPConnection(cHTTPServer & a_HTTPServer, const cX509Ce
cSslHTTPConnection::~cSslHTTPConnection()
cSslHTTPServerConnection::~cSslHTTPServerConnection()
{
m_Ssl.NotifyClose();
}
@ -34,7 +34,7 @@ cSslHTTPConnection::~cSslHTTPConnection()
void cSslHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size)
void cSslHTTPServerConnection::OnReceivedData(const char * a_Data, size_t a_Size)
{
// Process the received data:
const char * Data = a_Data;
@ -77,7 +77,7 @@ void cSslHTTPConnection::OnReceivedData(const char * a_Data, size_t a_Size)
void cSslHTTPConnection::SendData(const void * a_Data, size_t a_Size)
void cSslHTTPServerConnection::SendData(const void * a_Data, size_t a_Size)
{
const char * OutgoingData = reinterpret_cast<const char *>(a_Data);
size_t pos = 0;

View File

@ -1,7 +1,7 @@
// SslHTTPConnection.h
// SslHTTPServerConnection.h
// Declared the cSslHTTPConnection class representing a HTTP connection made over a SSL link
// Declared the cSslHTTPServerConnection class representing a HTTP connection made over a SSL link
@ -9,24 +9,24 @@
#pragma once
#include "HTTPConnection.h"
#include "HTTPServerConnection.h"
#include "PolarSSL++/BufferedSslContext.h"
class cSslHTTPConnection :
public cHTTPConnection
class cSslHTTPServerConnection :
public cHTTPServerConnection
{
typedef cHTTPConnection super;
typedef cHTTPServerConnection super;
public:
/** Creates a new connection on the specified server.
Sends the specified cert as the server certificate, uses the private key for decryption. */
cSslHTTPConnection(cHTTPServer & a_HTTPServer, const cX509CertPtr & a_Cert, const cCryptoKeyPtr & a_PrivateKey);
cSslHTTPServerConnection(cHTTPServer & a_HTTPServer, const cX509CertPtr & a_Cert, const cCryptoKeyPtr & a_PrivateKey);
~cSslHTTPConnection();
~cSslHTTPServerConnection();
protected:
cBufferedSslContext m_Ssl;

View File

@ -13,7 +13,7 @@
#include "Root.h"
#include "HTTPServer/HTTPMessage.h"
#include "HTTPServer/HTTPConnection.h"
#include "HTTPServer/HTTPServerConnection.h"
@ -212,7 +212,7 @@ bool cWebAdmin::LoadLoginTemplate(void)
void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
void cWebAdmin::HandleWebadminRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request)
{
if (!a_Request.HasAuth())
{
@ -349,7 +349,7 @@ void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPReque
void cWebAdmin::HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
void cWebAdmin::HandleRootRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request)
{
UNUSED(a_Request);
@ -364,7 +364,7 @@ void cWebAdmin::HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest &
void cWebAdmin::HandleFileRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
void cWebAdmin::HandleFileRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request)
{
AString FileURL = a_Request.GetURL();
std::replace(FileURL.begin(), FileURL.end(), '\\', '/');
@ -621,7 +621,7 @@ AString cWebAdmin::GetBaseURL(const AStringVector & a_URLSplit)
void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
void cWebAdmin::OnRequestBegun(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request)
{
UNUSED(a_Connection);
const AString & URL = a_Request.GetURL();
@ -645,7 +645,7 @@ void cWebAdmin::OnRequestBegun(cHTTPConnection & a_Connection, cHTTPRequest & a_
void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size)
void cWebAdmin::OnRequestBody(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size)
{
UNUSED(a_Connection);
cRequestData * Data = reinterpret_cast<cRequestData *>(a_Request.GetUserData());
@ -660,7 +660,7 @@ void cWebAdmin::OnRequestBody(cHTTPConnection & a_Connection, cHTTPRequest & a_R
void cWebAdmin::OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
void cWebAdmin::OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request)
{
const AString & URL = a_Request.GetURL();
if (

View File

@ -236,18 +236,18 @@ protected:
cHTTPServer m_HTTPServer;
/** Handles requests coming to the "/webadmin" or "/~webadmin" URLs */
void HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
void HandleWebadminRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request);
/** Handles requests for the root page */
void HandleRootRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
void HandleRootRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request);
/** Handles requests for a file */
void HandleFileRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request);
void HandleFileRequest(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request);
// cHTTPServer::cCallbacks overrides:
virtual void OnRequestBegun (cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override;
virtual void OnRequestBody (cHTTPConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override;
virtual void OnRequestFinished(cHTTPConnection & a_Connection, cHTTPRequest & a_Request) override;
virtual void OnRequestBegun (cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request) override;
virtual void OnRequestBody (cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request, const char * a_Data, size_t a_Size) override;
virtual void OnRequestFinished(cHTTPServerConnection & a_Connection, cHTTPRequest & a_Request) override;
} ; // tolua_export