2016-06-12 22:27:24 +02:00
|
|
|
#ifndef QTHTTPSERVER_H
|
|
|
|
#define QTHTTPSERVER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QHash>
|
2017-04-03 05:19:05 +02:00
|
|
|
#include <QTcpServer>
|
|
|
|
#include <QTcpSocket>
|
|
|
|
#include <QSslCertificate>
|
|
|
|
#include <QSslKey>
|
|
|
|
#include <QSslSocket>
|
|
|
|
#include <QHostAddress>
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
class QTcpSocket;
|
|
|
|
class QTcpServer;
|
|
|
|
class QtHttpRequest;
|
|
|
|
class QtHttpReply;
|
|
|
|
class QtHttpClientWrapper;
|
2019-07-12 16:54:26 +02:00
|
|
|
class NetOrigin;
|
2016-06-12 22:27:24 +02:00
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
class QtHttpServerWrapper : public QTcpServer
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2017-04-03 05:19:05 +02:00
|
|
|
|
|
|
|
public:
|
2019-07-21 15:03:50 +02:00
|
|
|
explicit QtHttpServerWrapper (QObject * parent = Q_NULLPTR);
|
|
|
|
virtual ~QtHttpServerWrapper (void);
|
2017-04-03 05:19:05 +02:00
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
void setUseSecure (const bool ssl = true);
|
2017-04-03 05:19:05 +02:00
|
|
|
|
|
|
|
protected:
|
2019-07-21 15:03:50 +02:00
|
|
|
void incomingConnection (qintptr handle) Q_DECL_OVERRIDE;
|
2017-04-03 05:19:05 +02:00
|
|
|
|
|
|
|
private:
|
2019-07-21 15:03:50 +02:00
|
|
|
bool m_useSsl;
|
2017-04-03 05:19:05 +02:00
|
|
|
};
|
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
class QtHttpServer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
public:
|
2019-07-21 15:03:50 +02:00
|
|
|
explicit QtHttpServer (QObject * parent = Q_NULLPTR);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
static const QString & HTTP_VERSION;
|
2017-04-03 05:19:05 +02:00
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
typedef void (QSslSocket::* SslErrorSignal) (const QList<QSslError> &);
|
2017-04-03 05:19:05 +02:00
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
const QString & getServerName (void) const { return m_serverName; };
|
2017-04-03 05:19:05 +02:00
|
|
|
|
2019-07-21 15:03:50 +02:00
|
|
|
quint16 getServerPort (void) const { return m_sockServer->serverPort(); };
|
|
|
|
QString getErrorString (void) const { return m_sockServer->errorString(); };
|
|
|
|
bool isListening() { return m_sockServer->isListening(); };
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
public slots:
|
2019-07-21 15:03:50 +02:00
|
|
|
void start (quint16 port = 0);
|
|
|
|
void stop (void);
|
|
|
|
void setUseSecure (const bool ssl = true);
|
|
|
|
void setServerName (const QString & serverName) { m_serverName = serverName; };
|
|
|
|
void setPrivateKey (const QSslKey & key) { m_sslKey = key; };
|
|
|
|
void setCertificates (const QList<QSslCertificate> & certs) { m_sslCerts = certs; };
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
signals:
|
2019-07-21 15:03:50 +02:00
|
|
|
void started (quint16 port);
|
|
|
|
void stopped (void);
|
|
|
|
void error (const QString & msg);
|
|
|
|
void clientConnected (const QString & guid);
|
|
|
|
void clientDisconnected (const QString & guid);
|
|
|
|
void requestNeedsReply (QtHttpRequest * request, QtHttpReply * reply);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
private slots:
|
2019-07-21 15:03:50 +02:00
|
|
|
void onClientConnected (void);
|
|
|
|
void onClientDisconnected (void);
|
|
|
|
void onClientSslEncrypted (void) { };
|
|
|
|
void onClientSslPeerVerifyError (const QSslError & err) { Q_UNUSED (err) };
|
|
|
|
void onClientSslErrors (const QList<QSslError> & errors) { Q_UNUSED (errors) };
|
|
|
|
void onClientSslModeChanged (QSslSocket::SslMode mode) { Q_UNUSED (mode) };
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
private:
|
2019-07-21 15:03:50 +02:00
|
|
|
bool m_useSsl;
|
|
|
|
QSslKey m_sslKey;
|
|
|
|
QList<QSslCertificate> m_sslCerts;
|
|
|
|
QString m_serverName;
|
2019-07-12 16:54:26 +02:00
|
|
|
NetOrigin* m_netOrigin;
|
2019-07-21 15:03:50 +02:00
|
|
|
QtHttpServerWrapper * m_sockServer;
|
|
|
|
QHash<QTcpSocket *, QtHttpClientWrapper *> m_socksClientsHash;
|
2016-06-12 22:27:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QTHTTPSERVER_H
|