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;
|
|
|
|
|
2017-04-03 05:19:05 +02:00
|
|
|
class QtHttpServerWrapper : public QTcpServer {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit QtHttpServerWrapper (QObject * parent = Q_NULLPTR);
|
|
|
|
virtual ~QtHttpServerWrapper (void);
|
|
|
|
|
|
|
|
void setUseSecure (const bool ssl = true);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void incomingConnection (qintptr handle) Q_DECL_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool m_useSsl;
|
|
|
|
};
|
|
|
|
|
2016-06-12 22:27:24 +02:00
|
|
|
class QtHttpServer : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit QtHttpServer (QObject * parent = Q_NULLPTR);
|
|
|
|
|
|
|
|
static const QString & HTTP_VERSION;
|
2017-04-03 05:19:05 +02:00
|
|
|
|
|
|
|
typedef void (QSslSocket::* SslErrorSignal) (const QList<QSslError> &);
|
|
|
|
|
2017-01-14 19:04:58 +01:00
|
|
|
const QString & getServerName (void) const;
|
2017-04-03 05:19:05 +02:00
|
|
|
|
|
|
|
quint16 getServerPort (void) const;
|
2017-01-14 19:04:58 +01:00
|
|
|
QString getErrorString (void) const;
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
public slots:
|
2017-04-03 05:19:05 +02:00
|
|
|
void start (quint16 port = 0);
|
|
|
|
void stop (void);
|
|
|
|
void setServerName (const QString & serverName);
|
|
|
|
void setUseSecure (const bool ssl = true);
|
|
|
|
void setPrivateKey (const QSslKey & key);
|
|
|
|
void setCertificates (const QList<QSslCertificate> & certs);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
signals:
|
|
|
|
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);
|
|
|
|
|
|
|
|
private slots:
|
2017-04-03 05:19:05 +02:00
|
|
|
void onClientConnected (void);
|
|
|
|
void onClientDisconnected (void);
|
|
|
|
void onClientSslEncrypted (void);
|
|
|
|
void onClientSslPeerVerifyError (const QSslError & err);
|
|
|
|
void onClientSslErrors (const QList<QSslError> & errors);
|
|
|
|
void onClientSslModeChanged (QSslSocket::SslMode mode);
|
2016-06-12 22:27:24 +02:00
|
|
|
|
|
|
|
private:
|
2017-04-03 05:19:05 +02:00
|
|
|
bool m_useSsl;
|
|
|
|
QSslKey m_sslKey;
|
|
|
|
QList<QSslCertificate> m_sslCerts;
|
2016-06-12 22:27:24 +02:00
|
|
|
QString m_serverName;
|
2017-04-03 05:19:05 +02:00
|
|
|
QtHttpServerWrapper * m_sockServer;
|
2016-06-12 22:27:24 +02:00
|
|
|
QHash<QTcpSocket *, QtHttpClientWrapper *> m_socksClientsHash;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // QTHTTPSERVER_H
|
2017-04-03 05:19:05 +02:00
|
|
|
|