diff options
-rw-r--r-- | src/websockets/qwebsocket_p.cpp | 4 | ||||
-rw-r--r-- | src/websockets/qwebsocketframe_p.cpp | 2 | ||||
-rw-r--r-- | src/websockets/qwebsocketprotocol_p.cpp | 14 | ||||
-rw-r--r-- | src/websockets/qwebsocketprotocol_p.h | 2 | ||||
-rw-r--r-- | tests/auto/websocketprotocol/tst_websocketprotocol.cpp | 6 |
5 files changed, 21 insertions, 7 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index b9d7e62..d6ff2c4 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -641,7 +641,9 @@ QByteArray QWebSocketPrivate::getFrameHeader(QWebSocketProtocol::OpCode opCode, //Write mask if (maskingKey != 0) { - header.append(static_cast<const char *>(static_cast<const void *>(&maskingKey)), sizeof(quint32)); + //TODO: to big endian? + const quint32 mask = qToBigEndian<quint32>(maskingKey); + header.append(static_cast<const char *>(static_cast<const void *>(&mask)), sizeof(quint32)); } } else diff --git a/src/websockets/qwebsocketframe_p.cpp b/src/websockets/qwebsocketframe_p.cpp index d93bd59..324e701 100644 --- a/src/websockets/qwebsocketframe_p.cpp +++ b/src/websockets/qwebsocketframe_p.cpp @@ -410,6 +410,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice) { if (pIoDevice->bytesAvailable() >= 4) { + //TODO: big endian conversion? bytesRead = pIoDevice->read(reinterpret_cast<char *>(&frame.m_mask), sizeof(frame.m_mask)); if (bytesRead == -1) { @@ -418,6 +419,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice) } else { + frame.m_mask = qFromBigEndian(frame.m_mask); processingState = PS_READ_PAYLOAD; } } diff --git a/src/websockets/qwebsocketprotocol_p.cpp b/src/websockets/qwebsocketprotocol_p.cpp index ff34ff4..47ecc4a 100644 --- a/src/websockets/qwebsocketprotocol_p.cpp +++ b/src/websockets/qwebsocketprotocol_p.cpp @@ -163,9 +163,9 @@ void mask(QByteArray *payload, quint32 maskingKey) Masks the \a payload of length \a size with the given \a maskingKey and stores the result back in \a payload. \internal */ -void mask(Q_DECL_ALIGN(4) char *payload, quint64 size, quint32 maskingKey) +void mask(char *payload, quint64 size, quint32 maskingKey) { - quint32 *payloadData = reinterpret_cast<quint32 *>(payload); +/* quint32 *payloadData = reinterpret_cast<quint32 *>(payload); quint32 numIterations = static_cast<quint32>(size / sizeof(quint32)); quint32 remainder = size % sizeof(quint32); const quint32 offset = numIterations * sizeof(quint32); @@ -182,6 +182,16 @@ void mask(Q_DECL_ALIGN(4) char *payload, quint64 size, quint32 maskingKey) { *payload++ ^= *mask++; } + }*/ + const quint8 mask[] = { static_cast<quint8>((maskingKey & 0xFF000000u) >> 24), + static_cast<quint8>((maskingKey & 0x00FF0000u) >> 16), + static_cast<quint8>((maskingKey & 0x0000FF00u) >> 8), + static_cast<quint8>((maskingKey & 0x000000FFu)) + }; + int i = 0; + while (size-- > 0) + { + *payload++ ^= mask[i++ % 4]; } } } //end namespace WebSocketProtocol diff --git a/src/websockets/qwebsocketprotocol_p.h b/src/websockets/qwebsocketprotocol_p.h index 26411f7..e775179 100644 --- a/src/websockets/qwebsocketprotocol_p.h +++ b/src/websockets/qwebsocketprotocol_p.h @@ -67,7 +67,7 @@ inline bool isCloseCodeValid(int closeCode) } void Q_AUTOTEST_EXPORT mask(QByteArray *payload, quint32 maskingKey); -void Q_AUTOTEST_EXPORT mask(Q_DECL_ALIGN(4) char *payload, quint64 size, quint32 maskingKey); +void Q_AUTOTEST_EXPORT mask(char *payload, quint64 size, quint32 maskingKey); } //end namespace QWebSocketProtocol QT_END_NAMESPACE diff --git a/tests/auto/websocketprotocol/tst_websocketprotocol.cpp b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp index 714700e..ab39aa6 100644 --- a/tests/auto/websocketprotocol/tst_websocketprotocol.cpp +++ b/tests/auto/websocketprotocol/tst_websocketprotocol.cpp @@ -105,9 +105,9 @@ void tst_WebSocketProtocol::tst_validMasks_data() // QTest::newRow("ASCII payload of 8 characters") << qToBigEndian<quint32>(0x12345678u) << QString("abcdefgh") << QByteArray("\x19\x34\x57\x76\x1D\x30\x53\x7A"); // QTest::newRow("ASCII payload of 9 characters") << qToBigEndian<quint32>(0x12345678u) << QString("abcdefghi") << QByteArray("\x19\x34\x57\x76\x1D\x30\x53\x7A\x11"); // QTest::newRow("UTF-8 payload") << qToBigEndian<quint32>(0x12345678u) << QString("∫∂ƒ©øØ") << QByteArray("\x47\x69\x0B\xBB\x80\x8E"); - QTest::newRow("ASCII payload of 8 characters") << qToBigEndian<quint32>(0x12345678u) << QString("abcdefgh") << QByteArray("\x73\x56\x35\x1C\x77\x52\x31\x10"); - QTest::newRow("ASCII payload of 9 characters") << qToBigEndian<quint32>(0x12345678u) << QString("abcdefghi") << QByteArray("\x73\x56\x35\x1C\x77\x52\x31\x10\x7B"); - QTest::newRow("UTF-8 payload") << qToBigEndian<quint32>(0x12345678u) << QString("∫∂ƒ©øØ") << QByteArray("\x2D\x0B\x69\xD1\xEA\xEC"); + QTest::newRow("ASCII payload of 8 characters") << 0x12345678u << QString("abcdefgh") << QByteArray("\x73\x56\x35\x1C\x77\x52\x31\x10"); + QTest::newRow("ASCII payload of 9 characters") << 0x12345678u << QString("abcdefghi") << QByteArray("\x73\x56\x35\x1C\x77\x52\x31\x10\x7B"); + QTest::newRow("UTF-8 payload") << 0x12345678u << QString("∫∂ƒ©øØ") << QByteArray("\x2D\x0B\x69\xD1\xEA\xEC"); } void tst_WebSocketProtocol::tst_validMasks() |