hyperion.ng
QtHttpServer.h
1 #ifndef QTHTTPSERVER_H
2 #define QTHTTPSERVER_H
3 
4 #include <QObject>
5 #include <QString>
6 #include <QHash>
7 #include <QTcpServer>
8 #include <QTcpSocket>
9 #include <QSslCertificate>
10 #include <QSslKey>
11 #include <QSslSocket>
12 #include <QHostAddress>
13 
14 class QTcpSocket;
15 class QTcpServer;
16 
17 class QtHttpRequest;
18 class QtHttpReply;
20 
21 class QtHttpServerWrapper : public QTcpServer {
22  Q_OBJECT
23 
24 public:
25  explicit QtHttpServerWrapper (QObject * parent = Q_NULLPTR);
26  virtual ~QtHttpServerWrapper (void);
27 
28  void setUseSecure (const bool ssl = true);
29 
30 protected:
31  void incomingConnection (qintptr handle) Q_DECL_OVERRIDE;
32 
33 private:
34  bool m_useSsl;
35 };
36 
37 class QtHttpServer : public QObject {
38  Q_OBJECT
39 
40 public:
41  explicit QtHttpServer (QObject * parent = Q_NULLPTR);
42 
43  static const QString & HTTP_VERSION;
44 
45  typedef void (QSslSocket::* SslErrorSignal) (const QList<QSslError> &);
46 
47  const QString & getServerName (void) const;
48 
49  quint16 getServerPort (void) const;
50  QString getErrorString (void) const;
51 
52  bool isListening(void) { return m_sockServer->isListening(); };
53 
54 public slots:
55  void start (quint16 port = 0);
56  void stop (void);
57  void setServerName (const QString & serverName);
58  void setUseSecure (const bool ssl = true);
59  void setPrivateKey (const QSslKey & key);
60  void setCertificates (const QList<QSslCertificate> & certs);
61 
62 signals:
63  void started (quint16 port);
64  void stopped (void);
65  void error (const QString & msg);
66  void clientConnected (const QString & guid);
67  void clientDisconnected (const QString & guid);
68  void requestNeedsReply (QtHttpRequest * request, QtHttpReply * reply);
69 
70 private slots:
71  void onClientConnected (void);
72  void onClientDisconnected (void);
73  void onClientSslEncrypted (void);
74  void onClientSslPeerVerifyError (const QSslError & err);
75  void onClientSslErrors (const QList<QSslError> & errors);
76  void onClientSslModeChanged (QSslSocket::SslMode mode);
77 
78 private:
79  bool m_useSsl;
80  QSslKey m_sslKey;
81  QList<QSslCertificate> m_sslCerts;
82  QString m_serverName;
83  QtHttpServerWrapper * m_sockServer;
84  QHash<QTcpSocket *, QtHttpClientWrapper *> m_socksClientsHash;
85 };
86 
87 #endif // QTHTTPSERVER_H
88 
Definition: QtHttpServer.h:21
Definition: QtHttpRequest.h:17
Definition: QtHttpServer.h:37
Definition: QtHttpReply.h:11
Definition: QtHttpClientWrapper.h:15