Torc  0.1
Classes | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Slots | Protected Member Functions | Static Protected Attributes | Friends | List of all members
TorcHTTPServer Class Referencefinal

An HTTP server. More...

#include <torchttpserver.h>

Inheritance diagram for TorcHTTPServer:
[legend]

Classes

class  Status
 

Public Slots

void NewConnection (qintptr SocketDescriptor)
 

Signals

void HandlersChanged (void)
 

Public Member Functions

virtual ~TorcHTTPServer ()
 

Static Public Member Functions

static QString ServerDescription (void)
 
static Status GetStatus (void)
 
static void Authorise (const QString &Host, TorcHTTPRequest &Request, bool ForceCheck)
 Ensures remote user is authorised to access this request. More...
 
static void AuthenticateUser (TorcHTTPRequest &Request)
 
static void AddAuthenticationHeader (TorcHTTPRequest &Request)
 
static void ValidateOrigin (TorcHTTPRequest &Request)
 Check the Origin header for validity and respond appropriately. More...
 
static void RegisterHandler (TorcHTTPHandler *Handler)
 
static void DeregisterHandler (TorcHTTPHandler *Handler)
 
static void HandleRequest (const QString &PeerAddress, int PeerPort, const QString &LocalAddress, int LocalPort, TorcHTTPRequest &Request)
 
static QVariantMap HandleRequest (const QString &Method, const QVariant &Parameters, QObject *Connection, bool Authenticated)
 Process an incoming RPC request. More...
 
static QVariantMap GetServiceHandlers (void)
 
static QVariantMap GetServiceDescription (const QString &Service)
 
static TorcWebSocketThreadTakeSocket (TorcWebSocketThread *Socket)
 
static QString PlatformName (void)
 

Protected Slots

void PortChanged (int Port)
 
void SecureChanged (bool Secure)
 
void UPnPChanged (bool UPnP)
 
void UPnPSearchChanged (bool Search)
 
void UPnPAdvertChanged (bool Advert)
 
void BonjourChanged (bool Bonjour)
 
void BonjourSearchChanged (bool Search)
 
void BonjourAdvertChanged (bool Advert)
 
void IPv6Changed (bool IPv6)
 
void Restart (void)
 

Protected Member Functions

 TorcHTTPServer ()
 
bool event (QEvent *Event) overridefinal
 
bool Open (void)
 
void Close (void)
 
TorcWebSocketThreadTakeSocketPriv (TorcWebSocketThread *Socket)
 

Static Protected Attributes

static TorcHTTPServergWebServer = nullptr
 
static Status gWebServerStatus = TorcHTTPServer::Status()
 
static QMutex gWebServerLock
 
static QString gPlatform = QStringLiteral("")
 
static QString gOriginWhitelist = QStringLiteral("")
 
static QReadWriteLock gOriginWhitelistLock
 

Friends

class TorcHTTPServerObject
 

Detailed Description

An HTTP server.

TorcHTTPServer listens for incoming TCP connections. The default port is 4840 though any available port may be used if the default is unavailable. New connections are passed to TorcWebSocketPool.

Register new content handlers with RegisterHandler and remove them with DeregisterHandler. These can then be used with the static HandleRequest methods.

See also
TorcHTTPRequest
TorcHTTPHandler

Definition at line 25 of file torchttpserver.h.

Constructor & Destructor Documentation

TorcHTTPServer::~TorcHTTPServer ( )
virtual

Definition at line 399 of file torchttpserver.cpp.

TorcHTTPServer::TorcHTTPServer ( )
protected

Definition at line 273 of file torchttpserver.cpp.

Member Function Documentation

void TorcHTTPServer::AddAuthenticationHeader ( TorcHTTPRequest Request)
static

Definition at line 546 of file torchttpserver.cpp.

void TorcHTTPServer::AuthenticateUser ( TorcHTTPRequest Request)
static

Definition at line 588 of file torchttpserver.cpp.

void TorcHTTPServer::Authorise ( const QString &  Host,
TorcHTTPRequest Request,
bool  ForceCheck 
)
static

Ensures remote user is authorised to access this request.

The 'Authorization' header is used for standard HTTP requests.

Authentication credentials supplied via the url are used for WebSocket upgrade requests - and it is assumed the if the initial request is authenticated, the entire socket is then authenticated for that user.

Definition at line 495 of file torchttpserver.cpp.

void TorcHTTPServer::BonjourAdvertChanged ( bool  Advert)
protectedslot

Definition at line 729 of file torchttpserver.cpp.

void TorcHTTPServer::BonjourChanged ( bool  Bonjour)
protectedslot

Definition at line 719 of file torchttpserver.cpp.

void TorcHTTPServer::BonjourSearchChanged ( bool  Search)
protectedslot

Definition at line 738 of file torchttpserver.cpp.

void TorcHTTPServer::Close ( void  )
protected

Definition at line 811 of file torchttpserver.cpp.

void TorcHTTPServer::DeregisterHandler ( TorcHTTPHandler Handler)
static

Definition at line 98 of file torchttpserver.cpp.

bool TorcHTTPServer::event ( QEvent *  Event)
finaloverrideprotected

Definition at line 932 of file torchttpserver.cpp.

QVariantMap TorcHTTPServer::GetServiceDescription ( const QString &  Service)
static

Definition at line 221 of file torchttpserver.cpp.

QVariantMap TorcHTTPServer::GetServiceHandlers ( void  )
static

Definition at line 200 of file torchttpserver.cpp.

TorcHTTPServer::Status TorcHTTPServer::GetStatus ( void  )
static

Definition at line 239 of file torchttpserver.cpp.

void TorcHTTPServer::HandleRequest ( const QString &  PeerAddress,
int  PeerPort,
const QString &  LocalAddress,
int  LocalPort,
TorcHTTPRequest Request 
)
static

Definition at line 127 of file torchttpserver.cpp.

QVariantMap TorcHTTPServer::HandleRequest ( const QString &  Method,
const QVariant &  Parameters,
QObject *  Connection,
bool  Authenticated 
)
static

Process an incoming RPC request.

Remote procedure calls are only allowed for 'service' directories and will be ignored for anything else (e.g. attempts to retrieve static content and other files).

Note
The structure of responses is largely consistent with the JSON-RPC 2.0 specification. As such, successful requests will have a 'result' entry and failed requests will have an 'error' field with an error code and error message.

Definition at line 172 of file torchttpserver.cpp.

void TorcHTTPServer::HandlersChanged ( void  )
signal
void TorcHTTPServer::IPv6Changed ( bool  IPv6)
protectedslot

Definition at line 747 of file torchttpserver.cpp.

void TorcHTTPServer::NewConnection ( qintptr  SocketDescriptor)
slot

Definition at line 969 of file torchttpserver.cpp.

bool TorcHTTPServer::Open ( void  )
protected

Definition at line 758 of file torchttpserver.cpp.

QString TorcHTTPServer::PlatformName ( void  )
static

Definition at line 246 of file torchttpserver.cpp.

void TorcHTTPServer::PortChanged ( int  Port)
protectedslot

Definition at line 828 of file torchttpserver.cpp.

void TorcHTTPServer::RegisterHandler ( TorcHTTPHandler Handler)
static

Definition at line 66 of file torchttpserver.cpp.

void TorcHTTPServer::Restart ( void  )
protectedslot

Definition at line 926 of file torchttpserver.cpp.

void TorcHTTPServer::SecureChanged ( bool  Secure)
protectedslot

Definition at line 839 of file torchttpserver.cpp.

QString TorcHTTPServer::ServerDescription ( void  )
static

Definition at line 803 of file torchttpserver.cpp.

TorcWebSocketThread * TorcHTTPServer::TakeSocket ( TorcWebSocketThread Socket)
static

Definition at line 480 of file torchttpserver.cpp.

TorcWebSocketThread * TorcHTTPServer::TakeSocketPriv ( TorcWebSocketThread Socket)
protected

Definition at line 964 of file torchttpserver.cpp.

void TorcHTTPServer::UPnPAdvertChanged ( bool  Advert)
protectedslot

Definition at line 894 of file torchttpserver.cpp.

void TorcHTTPServer::UPnPChanged ( bool  UPnP)
protectedslot

Definition at line 884 of file torchttpserver.cpp.

void TorcHTTPServer::UPnPSearchChanged ( bool  Search)
protectedslot

Definition at line 910 of file torchttpserver.cpp.

void TorcHTTPServer::ValidateOrigin ( TorcHTTPRequest Request)
static

Check the Origin header for validity and respond appropriately.

Cross domain requests are not common from well behaved clients/browsers. There can however be confusion when the IP address is a localhost (IPv4 or IPv6) and we can never guarantee that the domain will 'look' equivalent. So validate the incoming origin (which is good practice anyway) and set the outgoing headers as necessary. Override CORS behaviour using TorcHTTPRequest::SetAllowCors (e.g. MPEG-DASH players)

Definition at line 569 of file torchttpserver.cpp.

Friends And Related Function Documentation

friend class TorcHTTPServerObject
friend

Definition at line 29 of file torchttpserver.h.

Member Data Documentation

QString TorcHTTPServer::gOriginWhitelist = QStringLiteral("")
staticprotected

Definition at line 93 of file torchttpserver.h.

QReadWriteLock TorcHTTPServer::gOriginWhitelistLock
staticprotected

Definition at line 94 of file torchttpserver.h.

QString TorcHTTPServer::gPlatform = QStringLiteral("")
staticprotected

Definition at line 92 of file torchttpserver.h.

TorcHTTPServer * TorcHTTPServer::gWebServer = nullptr
staticprotected

Definition at line 89 of file torchttpserver.h.

QMutex TorcHTTPServer::gWebServerLock
staticprotected

Definition at line 91 of file torchttpserver.h.

TorcHTTPServer::Status TorcHTTPServer::gWebServerStatus = TorcHTTPServer::Status()
staticprotected

Definition at line 90 of file torchttpserver.h.


The documentation for this class was generated from the following files: