summaryrefslogtreecommitdiff
path: root/src/websockets/qwebsocket_p.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/websockets/qwebsocket_p.cpp')
-rw-r--r--src/websockets/qwebsocket_p.cpp31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index be8cb88..8f55e24 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -60,6 +60,7 @@
#ifndef QT_NO_SSL
#include <QtNetwork/QSslConfiguration>
#include <QtNetwork/QSslError>
+#include <QtNetwork/QSslPreSharedKeyAuthenticator>
#endif
#include <QtCore/QDebug>
@@ -304,11 +305,9 @@ QWebSocket *QWebSocketPrivate::upgradeFrom(QTcpSocket *pTcpSocket,
QWebSocket *pWebSocket = new QWebSocket(pTcpSocket, response.acceptedVersion(), parent);
if (Q_LIKELY(pWebSocket)) {
QNetworkRequest netRequest(request.requestUrl());
- QMapIterator<QString, QString> headerIter(request.headers());
- while (headerIter.hasNext()) {
- headerIter.next();
- netRequest.setRawHeader(headerIter.key().toLatin1(), headerIter.value().toLatin1());
- }
+ const auto headers = request.headers();
+ for (auto it = headers.begin(), end = headers.end(); it != end; ++it)
+ netRequest.setRawHeader(it.key().toLatin1(), it.value().toLatin1());
#ifndef QT_NO_SSL
if (QSslSocket *sslSock = qobject_cast<QSslSocket *>(pTcpSocket))
pWebSocket->setSslConfiguration(sslSock->sslConfiguration());
@@ -592,6 +591,8 @@ void QWebSocketPrivate::makeConnections(const QTcpSocket *pTcpSocket)
#ifndef QT_NO_SSL
const QSslSocket * const sslSocket = qobject_cast<const QSslSocket *>(pTcpSocket);
if (sslSocket) {
+ QObject::connect(sslSocket, &QSslSocket::preSharedKeyAuthenticationRequired, q,
+ &QWebSocket::preSharedKeyAuthenticationRequired);
QObject::connect(sslSocket, &QSslSocket::encryptedBytesWritten, q,
&QWebSocket::bytesWritten);
typedef void (QSslSocket:: *sslErrorSignalType)(const QList<QSslError> &);
@@ -708,12 +709,11 @@ QByteArray QWebSocketPrivate::getFrameHeader(QWebSocketProtocol::OpCode opCode,
bool lastFrame)
{
QByteArray header;
- quint8 byte = 0x00;
bool ok = payloadLength <= 0x7FFFFFFFFFFFFFFFULL;
if (Q_LIKELY(ok)) {
//FIN, RSV1-3, opcode (RSV-1, RSV-2 and RSV-3 are zero)
- byte = static_cast<quint8>((opCode & 0x0F) | (lastFrame ? 0x80 : 0x00));
+ quint8 byte = static_cast<quint8>((opCode & 0x0F) | (lastFrame ? 0x80 : 0x00));
header.append(static_cast<char>(byte));
byte = 0x00;
@@ -773,7 +773,6 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
if (Q_UNLIKELY(numFrames == 0))
numFrames = 1;
quint64 currentPosition = 0;
- qint64 bytesWritten = 0;
quint64 bytesLeft = data.size();
for (int i = 0; i < numFrames; ++i) {
@@ -789,7 +788,7 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
: QWebSocketProtocol::OpCodeContinue;
//write header
- bytesWritten += m_pSocket->write(getFrameHeader(opcode, size, maskingKey, isLastFrame));
+ m_pSocket->write(getFrameHeader(opcode, size, maskingKey, isLastFrame));
//write payload
if (Q_LIKELY(size > 0)) {
@@ -798,7 +797,6 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
QWebSocketProtocol::mask(currentData, size, maskingKey);
qint64 written = m_pSocket->write(currentData, static_cast<qint64>(size));
if (Q_LIKELY(written > 0)) {
- bytesWritten += written;
payloadWritten += written;
} else {
m_pSocket->flush();
@@ -881,7 +879,7 @@ qint64 QWebSocketPrivate::writeFrame(const QByteArray &frame)
/*!
\internal
*/
-QString readLine(QTcpSocket *pSocket)
+static QString readLine(QTcpSocket *pSocket)
{
Q_ASSERT(pSocket);
QString line;
@@ -1087,7 +1085,8 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS
m_key = generateKey();
QList<QPair<QString, QString> > headers;
- foreach (const QByteArray &key, m_request.rawHeaderList())
+ const auto keys = m_request.rawHeaderList();
+ for (const QByteArray &key : keys)
headers << qMakePair(QString::fromLatin1(key),
QString::fromLatin1(m_request.rawHeader(key)));
@@ -1203,7 +1202,7 @@ QString QWebSocketPrivate::createHandShakeRequest(QString resourceName,
QString extensions,
QString protocols,
QByteArray key,
- QList<QPair<QString, QString> > headers)
+ const QList<QPair<QString, QString> > &headers)
{
QStringList handshakeRequest;
if (resourceName.contains(QStringLiteral("\r\n"))) {
@@ -1246,11 +1245,9 @@ QString QWebSocketPrivate::createHandShakeRequest(QString resourceName,
if (protocols.length() > 0)
handshakeRequest << QStringLiteral("Sec-WebSocket-Protocol: ") % protocols;
- QListIterator<QPair<QString, QString> > headerIter(headers);
- while (headerIter.hasNext()) {
- const QPair<QString,QString> &header = headerIter.next();
+ for (const auto &header : headers)
handshakeRequest << header.first % QStringLiteral(": ") % header.second;
- }
+
handshakeRequest << QStringLiteral("\r\n");
return handshakeRequest.join(QStringLiteral("\r\n"));