qwebsocket.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 QWEBSOCKET_H
  40. #define QWEBSOCKET_H
  41. #include <QtCore/QUrl>
  42. #include <QtNetwork/QAbstractSocket>
  43. #include <QtNetwork/QNetworkRequest>
  44. #ifndef QT_NO_NETWORKPROXY
  45. #include <QtNetwork/QNetworkProxy>
  46. #endif
  47. #ifndef QT_NO_SSL
  48. #include <QtNetwork/QSslError>
  49. #include <QtNetwork/QSslConfiguration>
  50. #endif
  51. #include "QtWebSockets/qwebsockets_global.h"
  52. #include "QtWebSockets/qwebsocketprotocol.h"
  53. QT_BEGIN_NAMESPACE
  54. class QTcpSocket;
  55. class QWebSocketPrivate;
  56. class QMaskGenerator;
  57. class Q_WEBSOCKETS_EXPORT QWebSocket : public QObject
  58. {
  59. Q_OBJECT
  60. Q_DISABLE_COPY(QWebSocket)
  61. Q_DECLARE_PRIVATE(QWebSocket)
  62. public:
  63. explicit QWebSocket(const QString &origin = QString(),
  64. QWebSocketProtocol::Version version = QWebSocketProtocol::VersionLatest,
  65. QObject *parent = Q_NULLPTR);
  66. virtual ~QWebSocket();
  67. void abort();
  68. QAbstractSocket::SocketError error() const;
  69. QString errorString() const;
  70. bool flush();
  71. bool isValid() const;
  72. QHostAddress localAddress() const;
  73. quint16 localPort() const;
  74. QAbstractSocket::PauseModes pauseMode() const;
  75. QHostAddress peerAddress() const;
  76. QString peerName() const;
  77. quint16 peerPort() const;
  78. #ifndef QT_NO_NETWORKPROXY
  79. QNetworkProxy proxy() const;
  80. void setProxy(const QNetworkProxy &networkProxy);
  81. #endif
  82. void setMaskGenerator(const QMaskGenerator *maskGenerator);
  83. const QMaskGenerator *maskGenerator() const;
  84. qint64 readBufferSize() const;
  85. void setReadBufferSize(qint64 size);
  86. void resume();
  87. void setPauseMode(QAbstractSocket::PauseModes pauseMode);
  88. QAbstractSocket::SocketState state() const;
  89. QWebSocketProtocol::Version version() const;
  90. QString resourceName() const;
  91. QUrl requestUrl() const;
  92. QNetworkRequest request() const;
  93. QString origin() const;
  94. QWebSocketProtocol::CloseCode closeCode() const;
  95. QString closeReason() const;
  96. qint64 sendTextMessage(const QString &message);
  97. qint64 sendBinaryMessage(const QByteArray &data);
  98. #ifndef QT_NO_SSL
  99. void ignoreSslErrors(const QList<QSslError> &errors);
  100. void setSslConfiguration(const QSslConfiguration &sslConfiguration);
  101. QSslConfiguration sslConfiguration() const;
  102. #endif
  103. public Q_SLOTS:
  104. void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CloseCodeNormal,
  105. const QString &reason = QString());
  106. void open(const QUrl &url);
  107. void open(const QNetworkRequest &request);
  108. void ping(const QByteArray &payload = QByteArray());
  109. #ifndef QT_NO_SSL
  110. void ignoreSslErrors();
  111. #endif
  112. Q_SIGNALS:
  113. void aboutToClose();
  114. void connected();
  115. void disconnected();
  116. void stateChanged(QAbstractSocket::SocketState state);
  117. #ifndef QT_NO_NETWORKPROXY
  118. void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *pAuthenticator);
  119. #endif
  120. void readChannelFinished();
  121. void textFrameReceived(const QString &frame, bool isLastFrame);
  122. void binaryFrameReceived(const QByteArray &frame, bool isLastFrame);
  123. void textMessageReceived(const QString &message);
  124. void binaryMessageReceived(const QByteArray &message);
  125. void error(QAbstractSocket::SocketError error);
  126. void pong(quint64 elapsedTime, const QByteArray &payload);
  127. void bytesWritten(qint64 bytes);
  128. #ifndef QT_NO_SSL
  129. void sslErrors(const QList<QSslError> &errors);
  130. #endif
  131. private:
  132. QWebSocket(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version,
  133. QObject *parent = Q_NULLPTR);
  134. };
  135. QT_END_NAMESPACE
  136. #endif // QWEBSOCKET_H