mirror of
https://github.com/NohamR/RMHook-Win.git
synced 2026-05-26 13:30:12 +00:00
Add Qt libs and headers
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QDEFAULTMASKGENERATOR_P_H
|
||||
#define QDEFAULTMASKGENERATOR_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtWebSockets/qmaskgenerator.h>
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QObject;
|
||||
|
||||
class Q_AUTOTEST_EXPORT QDefaultMaskGenerator : public QMaskGenerator
|
||||
{
|
||||
Q_DISABLE_COPY(QDefaultMaskGenerator)
|
||||
|
||||
public:
|
||||
explicit QDefaultMaskGenerator(QObject *parent = nullptr);
|
||||
~QDefaultMaskGenerator() override;
|
||||
|
||||
bool seed() noexcept override;
|
||||
quint32 nextMask() noexcept override;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QDEFAULTMASKGENERATOR_P_H
|
||||
@@ -0,0 +1,242 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKET_P_H
|
||||
#define QWEBSOCKET_P_H
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
#endif
|
||||
#ifndef QT_NO_SSL
|
||||
#include <QtNetwork/QSslConfiguration>
|
||||
#include <QtNetwork/QSslError>
|
||||
#include <QtNetwork/QSslSocket>
|
||||
#endif
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <private/qobject_p.h>
|
||||
|
||||
#include "qwebsocket.h"
|
||||
#include "qwebsockethandshakeoptions.h"
|
||||
#include "qwebsocketprotocol.h"
|
||||
#include "qwebsocketdataprocessor_p.h"
|
||||
#include "qdefaultmaskgenerator_p.h"
|
||||
|
||||
#ifdef Q_OS_WASM
|
||||
# include <emscripten/websocket.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWebSocketHandshakeRequest;
|
||||
class QWebSocketHandshakeResponse;
|
||||
class QTcpSocket;
|
||||
class QWebSocket;
|
||||
class QMaskGenerator;
|
||||
|
||||
struct QWebSocketConfiguration
|
||||
{
|
||||
Q_DISABLE_COPY(QWebSocketConfiguration)
|
||||
|
||||
public:
|
||||
QWebSocketConfiguration();
|
||||
|
||||
public:
|
||||
#ifndef QT_NO_SSL
|
||||
QSslConfiguration m_sslConfiguration;
|
||||
QList<QSslError> m_ignoredSslErrors;
|
||||
bool m_ignoreSslErrors;
|
||||
#endif
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
QNetworkProxy m_proxy;
|
||||
#endif
|
||||
QTcpSocket *m_pSocket;
|
||||
};
|
||||
|
||||
class QWebSocketPrivate : public QObjectPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(QWebSocketPrivate)
|
||||
|
||||
public:
|
||||
Q_DECLARE_PUBLIC(QWebSocket)
|
||||
explicit QWebSocketPrivate(const QString &origin,
|
||||
QWebSocketProtocol::Version version);
|
||||
~QWebSocketPrivate() override;
|
||||
|
||||
// both constants are taken from the default settings of Apache
|
||||
// see: http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize and
|
||||
// http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfields
|
||||
static constexpr int MAX_HEADERLINE_LENGTH = 8 * 1024; // maximum length of a http request header line
|
||||
static constexpr int MAX_HEADERLINES = 100; // maximum number of http request header lines
|
||||
|
||||
void init();
|
||||
void abort();
|
||||
QAbstractSocket::SocketError error() const;
|
||||
QString errorString() const;
|
||||
bool flush();
|
||||
bool isValid() const;
|
||||
QHostAddress localAddress() const;
|
||||
quint16 localPort() const;
|
||||
QAbstractSocket::PauseModes pauseMode() const;
|
||||
QHostAddress peerAddress() const;
|
||||
QString peerName() const;
|
||||
quint16 peerPort() const;
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
QNetworkProxy proxy() const;
|
||||
void setProxy(const QNetworkProxy &networkProxy);
|
||||
#endif
|
||||
void setMaskGenerator(const QMaskGenerator *maskGenerator);
|
||||
const QMaskGenerator *maskGenerator() const;
|
||||
qint64 readBufferSize() const;
|
||||
void resume();
|
||||
void setPauseMode(QAbstractSocket::PauseModes pauseMode);
|
||||
void setReadBufferSize(qint64 size);
|
||||
QAbstractSocket::SocketState state() const;
|
||||
|
||||
QWebSocketProtocol::Version version() const;
|
||||
QString resourceName() const;
|
||||
QNetworkRequest request() const;
|
||||
QString origin() const;
|
||||
QWebSocketHandshakeOptions handshakeOptions() const;
|
||||
QString protocol() const;
|
||||
QString extension() const;
|
||||
QWebSocketProtocol::CloseCode closeCode() const;
|
||||
QString closeReason() const;
|
||||
|
||||
qint64 sendTextMessage(const QString &message);
|
||||
qint64 sendBinaryMessage(const QByteArray &data);
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
void ignoreSslErrors(const QList<QSslError> &errors);
|
||||
void ignoreSslErrors();
|
||||
void continueInterruptedHandshake();
|
||||
void setSslConfiguration(const QSslConfiguration &sslConfiguration);
|
||||
QSslConfiguration sslConfiguration() const;
|
||||
void _q_updateSslConfiguration();
|
||||
#endif
|
||||
|
||||
void closeGoingAway();
|
||||
void close(QWebSocketProtocol::CloseCode closeCode, QString reason);
|
||||
void open(const QNetworkRequest &request, const QWebSocketHandshakeOptions &options, bool mask);
|
||||
void ping(const QByteArray &payload);
|
||||
void setSocketState(QAbstractSocket::SocketState state);
|
||||
|
||||
void setMaxAllowedIncomingFrameSize(quint64 maxAllowedIncomingFrameSize);
|
||||
quint64 maxAllowedIncomingFrameSize() const;
|
||||
void setMaxAllowedIncomingMessageSize(quint64 maxAllowedIncomingMessageSize);
|
||||
quint64 maxAllowedIncomingMessageSize() const;
|
||||
static quint64 maxIncomingMessageSize();
|
||||
static quint64 maxIncomingFrameSize();
|
||||
|
||||
void setOutgoingFrameSize(quint64 outgoingFrameSize);
|
||||
quint64 outgoingFrameSize() const;
|
||||
static quint64 maxOutgoingFrameSize();
|
||||
#ifdef Q_OS_WASM
|
||||
void setSocketClosed(const EmscriptenWebSocketCloseEvent *emCloseEvent);
|
||||
QString closeCodeToString(QWebSocketProtocol::CloseCode code);
|
||||
#endif
|
||||
private:
|
||||
QWebSocketPrivate(QTcpSocket *pTcpSocket, QWebSocketProtocol::Version version);
|
||||
void setVersion(QWebSocketProtocol::Version version);
|
||||
void setResourceName(const QString &resourceName);
|
||||
void setRequest(const QNetworkRequest &request, const QWebSocketHandshakeOptions &options = {});
|
||||
void setOrigin(const QString &origin);
|
||||
void setProtocol(const QString &protocol);
|
||||
void setExtension(const QString &extension);
|
||||
void enableMasking(bool enable);
|
||||
void setErrorString(const QString &errorString);
|
||||
|
||||
QStringList requestedSubProtocols() const;
|
||||
|
||||
void socketDestroyed(QObject *socket);
|
||||
|
||||
void processData();
|
||||
void processPing(const QByteArray &data);
|
||||
void processPong(const QByteArray &data);
|
||||
void processClose(QWebSocketProtocol::CloseCode closeCode, QString closeReason);
|
||||
void processHandshake(QTcpSocket *pSocket);
|
||||
void processStateChanged(QAbstractSocket::SocketState socketState);
|
||||
|
||||
Q_REQUIRED_RESULT qint64 doWriteFrames(const QByteArray &data, bool isBinary);
|
||||
|
||||
void makeConnections(QTcpSocket *pTcpSocket);
|
||||
void releaseConnections(const QTcpSocket *pTcpSocket);
|
||||
|
||||
QByteArray getFrameHeader(QWebSocketProtocol::OpCode opCode, quint64 payloadLength,
|
||||
quint32 maskingKey, bool lastFrame);
|
||||
QString calculateAcceptKey(const QByteArray &key) const;
|
||||
QString createHandShakeRequest(QString resourceName,
|
||||
QString host,
|
||||
QString origin,
|
||||
QString extensions,
|
||||
const QStringList &options,
|
||||
QByteArray key,
|
||||
const QList<QPair<QString, QString> > &headers);
|
||||
|
||||
Q_REQUIRED_RESULT static QWebSocket *
|
||||
upgradeFrom(QTcpSocket *tcpSocket,
|
||||
const QWebSocketHandshakeRequest &request,
|
||||
const QWebSocketHandshakeResponse &response,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
quint32 generateMaskingKey() const;
|
||||
QByteArray generateKey() const;
|
||||
Q_REQUIRED_RESULT qint64 writeFrames(const QList<QByteArray> &frames);
|
||||
Q_REQUIRED_RESULT qint64 writeFrame(const QByteArray &frame);
|
||||
void emitErrorOccurred(QAbstractSocket::SocketError error);
|
||||
|
||||
QTcpSocket *m_pSocket;
|
||||
QString m_errorString;
|
||||
QWebSocketProtocol::Version m_version;
|
||||
QUrl m_resource;
|
||||
QString m_resourceName;
|
||||
QNetworkRequest m_request;
|
||||
QWebSocketHandshakeOptions m_options;
|
||||
QString m_origin;
|
||||
QString m_protocol;
|
||||
QString m_extension;
|
||||
QAbstractSocket::SocketState m_socketState;
|
||||
QAbstractSocket::PauseModes m_pauseMode;
|
||||
qint64 m_readBufferSize;
|
||||
|
||||
QByteArray m_key; //identification key used in handshake requests
|
||||
|
||||
bool m_mustMask; //a server must not mask the frames it sends
|
||||
|
||||
bool m_isClosingHandshakeSent;
|
||||
bool m_isClosingHandshakeReceived;
|
||||
QWebSocketProtocol::CloseCode m_closeCode;
|
||||
QString m_closeReason;
|
||||
|
||||
QElapsedTimer m_pingTimer;
|
||||
|
||||
QWebSocketDataProcessor *m_dataProcessor = new QWebSocketDataProcessor();
|
||||
QWebSocketConfiguration m_configuration;
|
||||
|
||||
QMaskGenerator *m_pMaskGenerator;
|
||||
QDefaultMaskGenerator m_defaultMaskGenerator;
|
||||
|
||||
quint64 m_outgoingFrameSize;
|
||||
|
||||
friend class QWebSocketServerPrivate;
|
||||
#ifdef Q_OS_WASM
|
||||
EMSCRIPTEN_WEBSOCKET_T m_socketContext = 0;
|
||||
uint16_t m_readyState = 0;
|
||||
#endif
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKET_H
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
#ifndef QWEBSOCKETCORSAUTHENTICATOR_P_H
|
||||
#define QWEBSOCKETCORSAUTHENTICATOR_P_H
|
||||
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
#include <QtCore/QString>
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWebSocketCorsAuthenticatorPrivate
|
||||
{
|
||||
public:
|
||||
QWebSocketCorsAuthenticatorPrivate(const QString &origin, bool allowed);
|
||||
~QWebSocketCorsAuthenticatorPrivate();
|
||||
|
||||
QString m_origin;
|
||||
bool m_isAllowed;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETCORSAUTHENTICATOR_P_H
|
||||
@@ -0,0 +1,95 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKETDATAPROCESSOR_P_H
|
||||
#define QWEBSOCKETDATAPROCESSOR_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringDecoder>
|
||||
#include <QtCore/QTimer>
|
||||
#include "qwebsocketframe_p.h"
|
||||
#include "qwebsocketprotocol.h"
|
||||
#include "qwebsocketprotocol_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIODevice;
|
||||
class QWebSocketFrame;
|
||||
|
||||
const quint64 MAX_MESSAGE_SIZE_IN_BYTES = std::numeric_limits<int>::max() - 1;
|
||||
|
||||
class Q_AUTOTEST_EXPORT QWebSocketDataProcessor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(QWebSocketDataProcessor)
|
||||
|
||||
public:
|
||||
explicit QWebSocketDataProcessor(QObject *parent = nullptr);
|
||||
~QWebSocketDataProcessor() override;
|
||||
|
||||
void setMaxAllowedFrameSize(quint64 maxAllowedFrameSize);
|
||||
quint64 maxAllowedFrameSize() const;
|
||||
void setMaxAllowedMessageSize(quint64 maxAllowedMessageSize);
|
||||
quint64 maxAllowedMessageSize() const;
|
||||
static quint64 maxMessageSize();
|
||||
static quint64 maxFrameSize();
|
||||
|
||||
Q_SIGNALS:
|
||||
void pingReceived(const QByteArray &data);
|
||||
void pongReceived(const QByteArray &data);
|
||||
void closeReceived(QWebSocketProtocol::CloseCode closeCode, const QString &closeReason);
|
||||
void textFrameReceived(const QString &frame, bool lastFrame);
|
||||
void binaryFrameReceived(const QByteArray &frame, bool lastFrame);
|
||||
void textMessageReceived(const QString &message);
|
||||
void binaryMessageReceived(const QByteArray &message);
|
||||
void errorEncountered(QWebSocketProtocol::CloseCode code, const QString &description);
|
||||
|
||||
public Q_SLOTS:
|
||||
bool process(QIODevice *pIoDevice);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
PS_READ_HEADER,
|
||||
PS_READ_PAYLOAD_LENGTH,
|
||||
PS_READ_BIG_PAYLOAD_LENGTH,
|
||||
PS_READ_MASK,
|
||||
PS_READ_PAYLOAD,
|
||||
PS_DISPATCH_RESULT
|
||||
} m_processingState;
|
||||
|
||||
bool m_isFinalFrame;
|
||||
bool m_isFragmented;
|
||||
QWebSocketProtocol::OpCode m_opCode;
|
||||
bool m_isControlFrame;
|
||||
bool m_hasMask;
|
||||
quint32 m_mask;
|
||||
QByteArray m_binaryMessage;
|
||||
QString m_textMessage;
|
||||
quint64 m_payloadLength;
|
||||
QStringDecoder m_decoder;
|
||||
QWebSocketFrame frame;
|
||||
QTimer *m_waitTimer;
|
||||
quint64 m_maxAllowedMessageSize = MAX_MESSAGE_SIZE_IN_BYTES;
|
||||
|
||||
bool processControlFrame(const QWebSocketFrame &frame);
|
||||
void timeout();
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETDATAPROCESSOR_P_H
|
||||
@@ -0,0 +1,101 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKETFRAME_P_H
|
||||
#define QWEBSOCKETFRAME_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <limits>
|
||||
|
||||
#include "qwebsockets_global.h"
|
||||
#include "qwebsocketprotocol.h"
|
||||
#include "qwebsocketprotocol_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QIODevice;
|
||||
|
||||
const quint64 MAX_FRAME_SIZE_IN_BYTES = std::numeric_limits<int>::max() - 1;
|
||||
|
||||
class Q_AUTOTEST_EXPORT QWebSocketFrame
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(QWebSocketFrame)
|
||||
|
||||
public:
|
||||
QWebSocketFrame() = default;
|
||||
|
||||
void setMaxAllowedFrameSize(quint64 maxAllowedFrameSize);
|
||||
quint64 maxAllowedFrameSize() const;
|
||||
static quint64 maxFrameSize();
|
||||
|
||||
QWebSocketProtocol::CloseCode closeCode() const;
|
||||
QString closeReason() const;
|
||||
bool isFinalFrame() const;
|
||||
bool isControlFrame() const;
|
||||
bool isDataFrame() const;
|
||||
bool isContinuationFrame() const;
|
||||
bool hasMask() const;
|
||||
quint32 mask() const; //returns 0 if no mask
|
||||
inline bool rsv1() const { return m_rsv1; }
|
||||
inline bool rsv2() const { return m_rsv2; }
|
||||
inline bool rsv3() const { return m_rsv3; }
|
||||
QWebSocketProtocol::OpCode opCode() const;
|
||||
QByteArray payload() const;
|
||||
|
||||
void clear();
|
||||
|
||||
bool isValid() const;
|
||||
bool isDone() const;
|
||||
|
||||
void readFrame(QIODevice *pIoDevice);
|
||||
|
||||
private:
|
||||
QString m_closeReason;
|
||||
QByteArray m_payload;
|
||||
quint64 m_length = 0;
|
||||
quint32 m_mask = 0;
|
||||
QWebSocketProtocol::CloseCode m_closeCode = QWebSocketProtocol::CloseCodeNormal;
|
||||
QWebSocketProtocol::OpCode m_opCode = QWebSocketProtocol::OpCodeReservedC;
|
||||
|
||||
enum ProcessingState
|
||||
{
|
||||
PS_READ_HEADER,
|
||||
PS_READ_PAYLOAD_LENGTH,
|
||||
PS_READ_MASK,
|
||||
PS_READ_PAYLOAD,
|
||||
PS_DISPATCH_RESULT,
|
||||
PS_WAIT_FOR_MORE_DATA
|
||||
} m_processingState = PS_READ_HEADER;
|
||||
|
||||
bool m_isFinalFrame = true;
|
||||
bool m_rsv1 = false;
|
||||
bool m_rsv2 = false;
|
||||
bool m_rsv3 = false;
|
||||
bool m_isValid = false;
|
||||
quint64 m_maxAllowedFrameSize = MAX_FRAME_SIZE_IN_BYTES;
|
||||
|
||||
ProcessingState readFrameHeader(QIODevice *pIoDevice);
|
||||
ProcessingState readFramePayloadLength(QIODevice *pIoDevice);
|
||||
ProcessingState readFrameMask(QIODevice *pIoDevice);
|
||||
ProcessingState readFramePayload(QIODevice *pIoDevice);
|
||||
|
||||
void setError(QWebSocketProtocol::CloseCode code, const QString &closeReason);
|
||||
bool checkValidity();
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETFRAME_P_H
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright (C) 2022 Menlo Systems GmbH, author Arno Rehn <a.rehn@menlosystems.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKETHANDSHAKEOPTIONS_P_H
|
||||
#define QWEBSOCKETHANDSHAKEOPTIONS_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QSharedData>
|
||||
|
||||
#include "qwebsockethandshakeoptions.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class Q_AUTOTEST_EXPORT QWebSocketHandshakeOptionsPrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
inline bool operator==(const QWebSocketHandshakeOptionsPrivate &other) const
|
||||
{ return subprotocols == other.subprotocols; }
|
||||
|
||||
QStringList subprotocols;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETHANDSHAKEOPTIONS_P_H
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKETHANDSHAKEREQUEST_P_H
|
||||
#define QWEBSOCKETHANDSHAKEREQUEST_P_H
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtNetwork/private/qhttpheaderparser_p.h>
|
||||
|
||||
#include "qwebsocketprotocol.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QTextStream;
|
||||
|
||||
class Q_AUTOTEST_EXPORT QWebSocketHandshakeRequest
|
||||
{
|
||||
Q_DISABLE_COPY(QWebSocketHandshakeRequest)
|
||||
|
||||
public:
|
||||
QWebSocketHandshakeRequest(int port, bool isSecure);
|
||||
virtual ~QWebSocketHandshakeRequest();
|
||||
|
||||
void clear();
|
||||
|
||||
int port() const;
|
||||
bool isSecure() const;
|
||||
bool isValid() const;
|
||||
QList<QPair<QByteArray, QByteArray>> headers() const;
|
||||
bool hasHeader(const QByteArray &name) const;
|
||||
QList<QWebSocketProtocol::Version> versions() const;
|
||||
QString key() const;
|
||||
QString origin() const;
|
||||
QList<QString> protocols() const;
|
||||
QList<QString> extensions() const;
|
||||
QUrl requestUrl() const;
|
||||
QString resourceName() const;
|
||||
QString host() const;
|
||||
|
||||
void readHandshake(QByteArrayView header, int maxHeaderLineLength);
|
||||
|
||||
private:
|
||||
|
||||
int m_port;
|
||||
bool m_isSecure;
|
||||
bool m_isValid;
|
||||
QHttpHeaderParser m_parser;
|
||||
QList<QWebSocketProtocol::Version> m_versions;
|
||||
QString m_key;
|
||||
QString m_origin;
|
||||
QList<QString> m_protocols;
|
||||
QList<QString> m_extensions;
|
||||
QUrl m_requestUrl;
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETHANDSHAKEREQUEST_P_H
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKETHANDSHAKERESPONSE_P_H
|
||||
#define QWEBSOCKETHANDSHAKERESPONSE_P_H
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QList>
|
||||
#include "qwebsocketprotocol.h"
|
||||
#include "private/qglobal_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QWebSocketHandshakeRequest;
|
||||
class QString;
|
||||
class QTextStream;
|
||||
|
||||
class Q_AUTOTEST_EXPORT QWebSocketHandshakeResponse : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(QWebSocketHandshakeResponse)
|
||||
|
||||
public:
|
||||
QWebSocketHandshakeResponse(const QWebSocketHandshakeRequest &request,
|
||||
const QString &serverName,
|
||||
bool isOriginAllowed,
|
||||
const QList<QWebSocketProtocol::Version> &supportedVersions,
|
||||
const QList<QString> &supportedProtocols,
|
||||
const QList<QString> &supportedExtensions);
|
||||
|
||||
~QWebSocketHandshakeResponse() override;
|
||||
|
||||
bool isValid() const;
|
||||
bool canUpgrade() const;
|
||||
QString acceptedProtocol() const;
|
||||
QString acceptedExtension() const;
|
||||
QWebSocketProtocol::Version acceptedVersion() const;
|
||||
|
||||
QWebSocketProtocol::CloseCode error() const;
|
||||
QString errorString() const;
|
||||
|
||||
private:
|
||||
bool m_isValid;
|
||||
bool m_canUpgrade;
|
||||
QString m_response;
|
||||
QString m_acceptedProtocol;
|
||||
QString m_acceptedExtension;
|
||||
QWebSocketProtocol::Version m_acceptedVersion;
|
||||
QWebSocketProtocol::CloseCode m_error;
|
||||
QString m_errorString;
|
||||
|
||||
QString calculateAcceptKey(const QString &key) const;
|
||||
QString getHandshakeResponse(const QWebSocketHandshakeRequest &request,
|
||||
const QString &serverName,
|
||||
bool isOriginAllowed,
|
||||
const QList<QWebSocketProtocol::Version> &supportedVersions,
|
||||
const QList<QString> &supportedProtocols,
|
||||
const QList<QString> &supportedExtensions);
|
||||
|
||||
QTextStream &writeToStream(QTextStream &textStream) const;
|
||||
Q_AUTOTEST_EXPORT friend QTextStream & operator <<(QTextStream &stream,
|
||||
const QWebSocketHandshakeResponse &response);
|
||||
};
|
||||
|
||||
Q_AUTOTEST_EXPORT QTextStream & operator <<(QTextStream &stream,
|
||||
const QWebSocketHandshakeResponse &response);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETHANDSHAKERESPONSE_P_H
|
||||
@@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKETPROTOCOL_P_H
|
||||
#define QWEBSOCKETPROTOCOL_P_H
|
||||
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
#include "QtWebSockets/qwebsocketprotocol.h"
|
||||
|
||||
#include <QtCore/qstringview.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QByteArray;
|
||||
|
||||
namespace QWebSocketProtocol
|
||||
{
|
||||
enum OpCode
|
||||
{
|
||||
OpCodeContinue = 0x0,
|
||||
OpCodeText = 0x1,
|
||||
OpCodeBinary = 0x2,
|
||||
OpCodeReserved3 = 0x3,
|
||||
OpCodeReserved4 = 0x4,
|
||||
OpCodeReserved5 = 0x5,
|
||||
OpCodeReserved6 = 0x6,
|
||||
OpCodeReserved7 = 0x7,
|
||||
OpCodeClose = 0x8,
|
||||
OpCodePing = 0x9,
|
||||
OpCodePong = 0xA,
|
||||
OpCodeReservedB = 0xB,
|
||||
OpCodeReservedC = 0xC,
|
||||
OpCodeReservedD = 0xD,
|
||||
OpCodeReservedE = 0xE,
|
||||
OpCodeReservedF = 0xF
|
||||
};
|
||||
|
||||
inline bool isOpCodeReserved(OpCode code)
|
||||
{
|
||||
return ((code > OpCodeBinary) && (code < OpCodeClose)) || (code > OpCodePong);
|
||||
}
|
||||
|
||||
inline bool isCloseCodeValid(int closeCode)
|
||||
{
|
||||
return (closeCode > 999) && (closeCode < 5000) &&
|
||||
(closeCode != CloseCodeReserved1004) && //see RFC6455 7.4.1
|
||||
(closeCode != CloseCodeMissingStatusCode) &&
|
||||
(closeCode != CloseCodeAbnormalDisconnection) &&
|
||||
((closeCode >= 3000) || (closeCode < 1012));
|
||||
}
|
||||
|
||||
inline Version currentVersion() { return VersionLatest; }
|
||||
Version Q_AUTOTEST_EXPORT versionFromString(QStringView versionString);
|
||||
|
||||
void Q_AUTOTEST_EXPORT mask(QByteArray *payload, quint32 maskingKey);
|
||||
void Q_AUTOTEST_EXPORT mask(char *payload, quint64 size, quint32 maskingKey);
|
||||
} //end namespace QWebSocketProtocol
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETPROTOCOL_P_H
|
||||
@@ -0,0 +1,120 @@
|
||||
// Copyright (C) 2016 Kurt Pattyn <pattyn.kurt@gmail.com>.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||
|
||||
#ifndef QWEBSOCKETSERVER_P_H
|
||||
#define QWEBSOCKETSERVER_P_H
|
||||
//
|
||||
// W A R N I N G
|
||||
// -------------
|
||||
//
|
||||
// This file is not part of the Qt API. It exists purely as an
|
||||
// implementation detail. This header file may change from version to
|
||||
// version without notice, or even be removed.
|
||||
//
|
||||
// We mean it.
|
||||
//
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QQueue>
|
||||
#include <QtCore/QString>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
#include <private/qobject_p.h>
|
||||
#include "qwebsocketserver.h"
|
||||
#include "qwebsocket.h"
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
#include <QtNetwork/QSslConfiguration>
|
||||
#include <QtNetwork/QSslError>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QTcpServer;
|
||||
class QTcpSocket;
|
||||
|
||||
class QWebSocketServerPrivate : public QObjectPrivate
|
||||
{
|
||||
Q_DISABLE_COPY(QWebSocketServerPrivate)
|
||||
|
||||
public:
|
||||
Q_DECLARE_PUBLIC(QWebSocketServer)
|
||||
enum SslMode
|
||||
{
|
||||
SecureMode = true,
|
||||
NonSecureMode
|
||||
};
|
||||
|
||||
explicit QWebSocketServerPrivate(const QString &serverName, SslMode secureMode);
|
||||
~QWebSocketServerPrivate() override;
|
||||
|
||||
void init();
|
||||
void close(bool aboutToDestroy = false);
|
||||
QString errorString() const;
|
||||
bool hasPendingConnections() const;
|
||||
bool isListening() const;
|
||||
bool listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
|
||||
int maxPendingConnections() const;
|
||||
int handshakeTimeout() const {
|
||||
return m_handshakeTimeout;
|
||||
}
|
||||
virtual QWebSocket *nextPendingConnection();
|
||||
void pauseAccepting();
|
||||
#ifndef QT_NO_NETWORKPROXY
|
||||
QNetworkProxy proxy() const;
|
||||
void setProxy(const QNetworkProxy &networkProxy);
|
||||
#endif
|
||||
void resumeAccepting();
|
||||
QHostAddress serverAddress() const;
|
||||
QWebSocketProtocol::CloseCode serverError() const;
|
||||
quint16 serverPort() const;
|
||||
void setMaxPendingConnections(int numConnections);
|
||||
void setHandshakeTimeout(int msec);
|
||||
bool setSocketDescriptor(qintptr socketDescriptor);
|
||||
qintptr socketDescriptor() const;
|
||||
|
||||
QList<QWebSocketProtocol::Version> supportedVersions() const;
|
||||
void setSupportedSubprotocols(const QStringList &protocols);
|
||||
QStringList supportedSubprotocols() const;
|
||||
QStringList supportedExtensions() const;
|
||||
|
||||
void setServerName(const QString &serverName);
|
||||
QString serverName() const;
|
||||
|
||||
SslMode secureMode() const;
|
||||
|
||||
#ifndef QT_NO_SSL
|
||||
void setSslConfiguration(const QSslConfiguration &sslConfiguration);
|
||||
QSslConfiguration sslConfiguration() const;
|
||||
#endif
|
||||
|
||||
void setError(QWebSocketProtocol::CloseCode code, const QString &errorString);
|
||||
|
||||
void handleConnection(QTcpSocket *pTcpSocket) const;
|
||||
|
||||
private slots:
|
||||
void startHandshakeTimeout(QTcpSocket *pTcpSocket);
|
||||
|
||||
private:
|
||||
QTcpServer *m_pTcpServer;
|
||||
QString m_serverName;
|
||||
SslMode m_secureMode;
|
||||
QStringList m_supportedSubprotocols;
|
||||
QQueue<QWebSocket *> m_pendingConnections;
|
||||
QWebSocketProtocol::CloseCode m_error;
|
||||
QString m_errorString;
|
||||
int m_maxPendingConnections;
|
||||
int m_handshakeTimeout;
|
||||
|
||||
void addPendingConnection(QWebSocket *pWebSocket);
|
||||
void setErrorFromSocketError(QAbstractSocket::SocketError error,
|
||||
const QString &errorDescription);
|
||||
|
||||
void onNewConnection();
|
||||
void onSocketDisconnected();
|
||||
void handshakeReceived();
|
||||
void finishHandshakeTimeout(QTcpSocket *pTcpSocket);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QWEBSOCKETSERVER_P_H
|
||||
Reference in New Issue
Block a user