qwebsocketserver.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWebSockets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QWEBSOCKETSERVER_H
  40. #define QWEBSOCKETSERVER_H
  41. #include "QtWebSockets/qwebsockets_global.h"
  42. #include "QtWebSockets/qwebsocketprotocol.h"
  43. #include <QtCore/QObject>
  44. #include <QtCore/QString>
  45. #include <QtNetwork/QHostAddress>
  46. #ifndef QT_NO_SSL
  47. #include <QtNetwork/QSslConfiguration>
  48. #include <QtNetwork/QSslError>
  49. #endif
  50. QT_BEGIN_NAMESPACE
  51. class QWebSocketServerPrivate;
  52. class QWebSocket;
  53. class QWebSocketCorsAuthenticator;
  54. class Q_WEBSOCKETS_EXPORT QWebSocketServer : public QObject
  55. {
  56. Q_OBJECT
  57. Q_DISABLE_COPY(QWebSocketServer)
  58. Q_DECLARE_PRIVATE(QWebSocketServer)
  59. Q_ENUMS(SslMode)
  60. public:
  61. enum SslMode {
  62. #ifndef QT_NO_SSL
  63. SecureMode,
  64. #endif
  65. NonSecureMode
  66. };
  67. explicit QWebSocketServer(const QString &serverName, SslMode secureMode,
  68. QObject *parent = Q_NULLPTR);
  69. virtual ~QWebSocketServer();
  70. bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
  71. void close();
  72. bool isListening() const;
  73. void setMaxPendingConnections(int numConnections);
  74. int maxPendingConnections() const;
  75. quint16 serverPort() const;
  76. QHostAddress serverAddress() const;
  77. QUrl serverUrl() const;
  78. SslMode secureMode() const;
  79. bool setSocketDescriptor(int socketDescriptor);
  80. int socketDescriptor() const;
  81. bool hasPendingConnections() const;
  82. virtual QWebSocket *nextPendingConnection();
  83. QWebSocketProtocol::CloseCode error() const;
  84. QString errorString() const;
  85. void pauseAccepting();
  86. void resumeAccepting();
  87. void setServerName(const QString &serverName);
  88. QString serverName() const;
  89. #ifndef QT_NO_NETWORKPROXY
  90. void setProxy(const QNetworkProxy &networkProxy);
  91. QNetworkProxy proxy() const;
  92. #endif
  93. #ifndef QT_NO_SSL
  94. void setSslConfiguration(const QSslConfiguration &sslConfiguration);
  95. QSslConfiguration sslConfiguration() const;
  96. #endif
  97. QList<QWebSocketProtocol::Version> supportedVersions() const;
  98. Q_SIGNALS:
  99. void acceptError(QAbstractSocket::SocketError socketError);
  100. void serverError(QWebSocketProtocol::CloseCode closeCode);
  101. //TODO: should use a delegate iso of a synchronous signal
  102. //see also QTBUG-16251
  103. void originAuthenticationRequired(QWebSocketCorsAuthenticator *pAuthenticator);
  104. void newConnection();
  105. #ifndef QT_NO_SSL
  106. void peerVerifyError(const QSslError &error);
  107. void sslErrors(const QList<QSslError> &errors);
  108. #endif
  109. void closed();
  110. };
  111. QT_END_NAMESPACE
  112. #endif // QWEBSOCKETSERVER_H