MythTV
master
|
#include <mythhttpserver.h>
Public Slots | |
void | ThreadFinished () |
Public Slots inherited from MythHTTPThreadPool | |
void | ThreadFinished () |
void | ThreadUpgraded (QThread *Thread) |
Signals | |
void | EnableHTTP (bool Enable) |
void | AddPaths (const QStringList &Paths) |
void | RemovePaths (const QStringList &Paths) |
void | AddHandlers (const HTTPHandlers &Handlers) |
void | RemoveHandlers (const HTTPHandlers &Handlers) |
void | AddServices (const HTTPServices &Services) |
void | RemoveServices (const HTTPServices &Services) |
void | AddErrorPageHandler (const HTTPHandler &Handler) |
void | PathsChanged (const QStringList &Paths) |
void | HandlersChanged (const HTTPHandlers &Handlers) |
void | ServicesChanged (const HTTPServices &Services) |
void | OriginsChanged (const QStringList &Origins) |
void | HostsChanged (const QStringList &Hosts) |
void | ErrorHandlerChanged (const HTTPHandler &Handler) |
void | MasterResolved (QHostInfo Info) |
void | HostResolved (QHostInfo Info) |
void | ProcessTCPQueue () |
Signals inherited from ServerPool | |
void | newConnection (QTcpSocket *) |
void | newDatagram (QByteArray, QHostAddress, quint16) |
Protected Slots | |
void | newTcpConnection (qintptr socket) override |
void | EnableDisable (bool Enable) |
void | NewPaths (const QStringList &Paths) |
Add new paths that will serve simple files. More... | |
void | StalePaths (const QStringList &Paths) |
void | NewHandlers (const HTTPHandlers &Handlers) |
Add new handlers. More... | |
void | StaleHandlers (const HTTPHandlers &Handlers) |
void | NewServices (const HTTPServices &Services) |
void | StaleServices (const HTTPServices &Services) |
void | ResolveMaster (QHostInfo Info) |
Add master backend addresses to the allowed Origins list. More... | |
void | ResolveHost (QHostInfo Info) |
Add the results of a reverse lookup to our allowed list. More... | |
void | NewErrorPageHandler (const HTTPHandler &Handler) |
Add new error page handler. More... | |
void | ProcessTCPQueueHandler () |
Protected Slots inherited from ServerPool | |
virtual void | newUdpDatagram (void) |
virtual void | newTcpConnection (qintptr socket) |
Protected Member Functions | |
MythHTTPServer () | |
~MythHTTPServer () override | |
Private Member Functions | |
void | Init () |
Initialise server configuration. More... | |
void | Started (bool Tcp, bool Ssl) |
void | Stopped () |
void | BuildHosts () |
void | BuildOrigins () |
Generate a list of allowed 'Origins' for validating CORS requests. More... | |
void | DebugHosts () |
void | DebugOrigins () |
Static Private Member Functions | |
static bool | ReservedPath (const QString &Path) |
static QStringList | BuildAddressList (QHostInfo &Info) |
Private Attributes | |
int | m_originLookups { 0 } |
int | m_hostLookups { 0 } |
MythHTTPConfig | m_config |
int | m_masterStatusPort { 0 } |
int | m_masterSSLPort { 0 } |
QString | m_masterIPAddress |
QQueue< qintptr > | m_connectionQueue |
int | m_threadNum { 0 } |
Friends | |
class | MythHTTPInstance |
Additional Inherited Members | |
Public Member Functions inherited from MythHTTPThreadPool | |
MythHTTPThreadPool () | |
~MythHTTPThreadPool () override | |
size_t | AvailableThreads () const |
size_t | MaxThreads () const |
size_t | ThreadCount () const |
void | AddThread (MythHTTPThread *Thread) |
Public Member Functions inherited from ServerPool | |
ServerPool (QObject *parent=nullptr) | |
~ServerPool (void) override | |
bool | listen (QList< QHostAddress > addrs, quint16 port, bool requireall=true, PoolServerType type=kTCPServer) |
bool | listen (QStringList addrs, quint16 port, bool requireall=true, PoolServerType type=kTCPServer) |
bool | listen (quint16 port, bool requireall=true, PoolServerType type=kTCPServer) |
bool | bind (QList< QHostAddress > addrs, quint16 port, bool requireall=true) |
bool | bind (QStringList addrs, quint16 port, bool requireall=true) |
bool | bind (quint16 port, bool requireall=true) |
qint64 | writeDatagram (const char *data, qint64 size, const QHostAddress &addr, quint16 port) |
qint64 | writeDatagram (const QByteArray &datagram, const QHostAddress &addr, quint16 port) |
bool | isListening (void) const |
int | maxPendingConnections (void) const |
void | setMaxPendingConnections (int n) |
quint16 | serverPort (void) const |
QNetworkProxy | proxy (void) |
void | setProxy (const QNetworkProxy &proxy) |
void | close (void) |
int | tryListeningPort (int baseport, int range=1) |
tryListeningPort More... | |
int | tryBindingPort (int baseport, int range=1) |
tryBindingPort More... | |
Static Public Member Functions inherited from ServerPool | |
static void | RefreshDefaultListen (void) |
static QList< QHostAddress > | DefaultListen (void) |
static QList< QHostAddress > | DefaultListenIPv4 (void) |
static QList< QHostAddress > | DefaultListenIPv6 (void) |
static QList< QHostAddress > | DefaultBroadcast (void) |
static QList< QHostAddress > | DefaultBroadcastIPv4 (void) |
static QList< QHostAddress > | DefaultBroadcastIPv6 (void) |
static int | tryListeningPort (QTcpServer *server, int baseport, int range=1, bool *isipv6=nullptr) |
tryListeningPort More... | |
static int | tryBindingPort (QUdpSocket *socket, int baseport, int range=1, bool *isipv6=nullptr) |
tryBindingPort More... | |
Definition at line 12 of file mythhttpserver.h.
|
protected |
Definition at line 31 of file mythhttpserver.cpp.
|
overrideprotected |
Definition at line 71 of file mythhttpserver.cpp.
|
signal |
Referenced by MythHTTPInstance::EnableHTTPService(), and MythHTTPServer().
|
signal |
Referenced by MythHTTPInstance::AddPaths(), and MythHTTPServer().
|
signal |
Referenced by MythHTTPServer(), and MythHTTPInstance::RemovePaths().
|
signal |
Referenced by MythHTTPInstance::AddHandlers(), and MythHTTPServer().
|
signal |
Referenced by MythHTTPServer(), and MythHTTPInstance::RemoveHandlers().
|
signal |
Referenced by MythHTTPInstance::Addservices(), and MythHTTPServer().
|
signal |
Referenced by MythHTTPServer(), and MythHTTPInstance::RemoveServices().
|
signal |
Referenced by MythHTTPInstance::AddErrorPageHandler(), and MythHTTPServer().
|
signal |
Referenced by NewPaths(), MythHTTPThread::run(), and StalePaths().
|
signal |
Referenced by NewHandlers(), MythHTTPThread::run(), and StaleHandlers().
|
signal |
Referenced by NewServices(), MythHTTPThread::run(), and StaleServices().
|
signal |
Referenced by ResolveMaster(), and MythHTTPThread::run().
|
signal |
Referenced by ResolveHost(), and MythHTTPThread::run().
|
signal |
Referenced by NewErrorPageHandler().
|
signal |
Referenced by BuildOrigins(), and MythHTTPServer().
|
signal |
Referenced by BuildHosts(), and MythHTTPServer().
|
signal |
Referenced by MythHTTPServer(), newTcpConnection(), and ThreadFinished().
|
slot |
Definition at line 241 of file mythhttpserver.cpp.
Referenced by ProcessTCPQueueHandler().
|
overrideprotectedslot |
Definition at line 267 of file mythhttpserver.cpp.
|
protectedslot |
Definition at line 76 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Add new paths that will serve simple files.
File paths should not be duplicated (as it will reduce performance) but this function will only warn when an attempt is made to add a path for a second time. This ensures the server's behaviour does not break if a duplicated path is removed dynamically (i.e. before the server quits).
File paths are handled after all other handlers and are only called if another handler for the given path does not provide a response. This allows a dynamic handler to process specific requests for the given path, falling back to a regular file handler for anything it does not recognise.
Paths are not recursive and each directory must be added explicitly (e.g. "/images/" will only serve files from the /images/ directory and not /images/icons/). This improves performance and adds an additional modicum of security.
It is assumed file paths are largely used for static server content (e.g. css, images etc). As a result, caching defaults to 'long life', authorisation is never requested and there is no filtering of files (i.e. any request for a readable file in the given directory will result in the file being sent).
Definition at line 308 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Definition at line 325 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Add new handlers.
Handlers allow dynamic content to be served for the given path.
The underlying function reference is a std::function. This allows the handler to be a lambda, a functor, a static member function or a full blown member function
It should be noted that the supplied function will be called from multiple threads, so the code must ensure thread safety. The webserver code attempts to maximise concurrency (and hence responsiveness) by avoiding blocking the socket thread. It is expected that individual handlers will attempt to do the same.
As for regular file paths, handlers paths are not recursive.
Definition at line 361 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Definition at line 385 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Definition at line 402 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Definition at line 426 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Add master backend addresses to the allowed Origins list.
The master backend may be using both http and https so we need to account for both here.
Definition at line 558 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Add the results of a reverse lookup to our allowed list.
Definition at line 592 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Add new error page handler.
Handler to return error page when no other content is found.
Used for single page web apps (eg. backend web app)
Definition at line 450 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
protectedslot |
Definition at line 249 of file mythhttpserver.cpp.
Referenced by MythHTTPServer().
|
private |
Initialise server configuration.
This is called before we ask the server to start listening, which allows us to stop and restart the server with different settings (new port etc)
Definition at line 125 of file mythhttpserver.cpp.
Referenced by EnableDisable().
Definition at line 190 of file mythhttpserver.cpp.
Referenced by EnableDisable().
|
private |
Definition at line 226 of file mythhttpserver.cpp.
Referenced by EnableDisable(), Init(), and ~MythHTTPServer().
|
private |
Definition at line 457 of file mythhttpserver.cpp.
Referenced by Started().
|
private |
Generate a list of allowed 'Origins' for validating CORS requests.
This is not as straightforward as it might first appear. We need the IP addresses AND host names for all origins that are deemed safe. This is limited to the current machine (for addresses/interfaces that ServerPool is listening on), the master backend and any additional overrides from the 'AllowedOriginsList' setting. Furthermore the port is optional and there will be the usual additional complications for IPv6 addresses...
Definition at line 513 of file mythhttpserver.cpp.
Referenced by Started().
|
private |
Definition at line 611 of file mythhttpserver.cpp.
Referenced by ResolveHost().
|
private |
Definition at line 579 of file mythhttpserver.cpp.
Referenced by ResolveMaster().
|
staticprivate |
Definition at line 276 of file mythhttpserver.cpp.
Referenced by NewHandlers(), NewPaths(), and NewServices().
|
staticprivate |
Definition at line 534 of file mythhttpserver.cpp.
Referenced by ResolveHost(), and ResolveMaster().
|
friend |
Definition at line 16 of file mythhttpserver.h.
|
private |
Definition at line 77 of file mythhttpserver.h.
Referenced by BuildOrigins(), and ResolveMaster().
|
private |
Definition at line 78 of file mythhttpserver.h.
Referenced by BuildHosts(), and ResolveHost().
|
private |
Definition at line 79 of file mythhttpserver.h.
Referenced by BuildHosts(), BuildOrigins(), DebugHosts(), DebugOrigins(), EnableDisable(), Init(), MythHTTPServer(), NewErrorPageHandler(), NewHandlers(), NewPaths(), NewServices(), ProcessTCPQueueHandler(), ResolveHost(), ResolveMaster(), StaleHandlers(), StalePaths(), StaleServices(), Started(), and Stopped().
|
private |
Definition at line 80 of file mythhttpserver.h.
Referenced by Init(), and ResolveMaster().
|
private |
Definition at line 81 of file mythhttpserver.h.
Referenced by Init(), and ResolveMaster().
|
private |
Definition at line 82 of file mythhttpserver.h.
Referenced by BuildOrigins(), and Init().
|
private |
Definition at line 83 of file mythhttpserver.h.
Referenced by newTcpConnection(), ProcessTCPQueueHandler(), and ThreadFinished().
|
private |
Definition at line 84 of file mythhttpserver.h.
Referenced by ProcessTCPQueueHandler().