#include "dataprocessor_p.h"
#include "qwebsocketprotocol.h"
+#include "qwebsocket.h"
#include <QTcpSocket>
#include <QtEndian>
#include <limits.h>
bool ok = pSocket->waitForReadyRead(5000);
if (!ok)
{
- frame.setError(QWebSocketProtocol::CC_GOING_AWAY, "Timeout when reading data from socket.");
+ frame.setError(QWebSocketProtocol::CC_GOING_AWAY, QWebSocket::tr("Timeout when reading data from socket."));
isDone = true;
}
else
}
else if (payloadLength > MAX_FRAME_SIZE_IN_BYTES)
{
- frame.setError(QWebSocketProtocol::CC_TOO_MUCH_DATA, "Maximum framesize exceeded.");
+ frame.setError(QWebSocketProtocol::CC_TOO_MUCH_DATA, QWebSocket::tr("Maximum framesize exceeded."));
processingState = PS_DISPATCH_RESULT;
}
else
{
if (m_rsv1 || m_rsv2 || m_rsv3)
{
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Rsv field is non-zero");
+ setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Rsv field is non-zero"));
}
else if (QWebSocketProtocol::isOpCodeReserved(m_opCode))
{
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Used reserved opcode");
+ setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Used reserved opcode"));
}
else if (isControlFrame())
{
if (m_length > 125)
{
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Controle frame is larger than 125 bytes");
+ setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Controle frame is larger than 125 bytes"));
}
else if (!m_isFinalFrame)
{
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Controle frames cannot be fragmented");
+ setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Controle frames cannot be fragmented"));
}
else
{
if (!m_isFragmented && frame.isContinuationFrame())
{
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, "Received Continuation frame /*with FIN=true*/, while there is nothing to continue.");
+ Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("Received Continuation frame /*with FIN=true*/, while there is nothing to continue."));
return;
}
if (m_isFragmented && frame.isDataFrame() && !frame.isContinuationFrame())
{
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, "All data frames after the initial data frame must have opcode 0 (continuation).");
+ Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR, QWebSocket::tr("All data frames after the initial data frame must have opcode 0 (continuation)."));
return;
}
if (!frame.isContinuationFrame())
if ((messageLength + quint64(frame.getPayload().length())) > MAX_MESSAGE_SIZE_IN_BYTES)
{
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_TOO_MUCH_DATA, "Received message is too big.");
+ Q_EMIT errorEncountered(QWebSocketProtocol::CC_TOO_MUCH_DATA, QWebSocket::tr("Received message is too big."));
return;
}
if (failed)
{
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_WRONG_DATATYPE, "Invalid UTF-8 code encountered.");
+ Q_EMIT errorEncountered(QWebSocketProtocol::CC_WRONG_DATATYPE, QWebSocket::tr("Invalid UTF-8 code encountered."));
return;
}
else
{
if (state() == QAbstractSocket::ConnectedState)
{
- close(QWebSocketProtocol::CC_GOING_AWAY, "Connection closed");
+ close(QWebSocketProtocol::CC_GOING_AWAY, QWebSocket::tr("Connection closed"));
}
releaseConnections(m_pSocket);
m_pSocket->deleteLater();
}
else
{
- setErrorString("WebSocket::doWriteFrames: Error writing bytes to socket: " + m_pSocket->errorString());
+ setErrorString(QWebSocket::tr("Error writing bytes to socket: %1.").arg(m_pSocket->errorString()));
qDebug() << errorString();
m_pSocket->flush();
Q_EMIT q_ptr->error(QAbstractSocket::NetworkError);
}
if (payloadWritten != data.size())
{
- setErrorString("Bytes written " + QString::number(payloadWritten) + " != " + QString::number(data.size()));
+ setErrorString(QWebSocket::tr("Bytes written %1 != %2.").arg(payloadWritten).arg(data.size()));
qDebug() << errorString();
Q_EMIT q_ptr->error(QAbstractSocket::NetworkError);
}
}
if (!ok)
{
- errorDescription = "WebSocket::processHandshake: Invalid statusline in response: " + statusLine;
+ errorDescription = QWebSocket::tr("Invalid statusline in response: %1.").arg(statusLine);
}
else
{
ok = (accept == acceptKey);
if (!ok)
{
- errorDescription = "WebSocket::processHandshake: Accept-Key received from server " + acceptKey + " does not match the client key " + accept;
+ errorDescription = QWebSocket::tr("Accept-Key received from server %1 does not match the client key %2.").arg(acceptKey).arg(accept);
}
}
else
{
- errorDescription = "WebSocket::processHandshake: Invalid statusline in response: " + statusLine;
+ errorDescription = QWebSocket::tr("Invalid statusline in response: %1.").arg(statusLine);
}
}
else if (httpStatusCode == 400) //HTTP/1.1 400 Bad Request
{
//if needed to switch protocol version, then we are finished here
//because we cannot handle other protocols than the RFC one (v13)
- errorDescription = "WebSocket::processHandshake: Server requests a version that we don't support: " + versions.join(", ");
+ errorDescription = QWebSocket::tr("Handshake: Server requests a version that we don't support: %1.").arg(versions.join(", "));
ok = false;
}
else
{
//we tried v13, but something different went wrong
- errorDescription = "WebSocket::processHandshake: Unknown error condition encountered. Aborting connection.";
+ errorDescription = QWebSocket::tr("Unknown error condition encountered. Aborting connection.");
ok = false;
}
}
}
else
{
- errorDescription = "WebSocket::processHandshake: Unhandled http status code " + QString::number(httpStatusCode);
+ errorDescription = QWebSocket::tr("Unhandled http status code: %1.").arg(httpStatusCode);
ok = false;
}
if (!QWebSocketProtocol::isCloseCodeValid(closeCode))
{
closeCode = QWebSocketProtocol::CC_PROTOCOL_ERROR;
- closeReason = QString("Invalid close code %1 detected").arg(closeCode);
+ closeReason = QWebSocket::tr("Invalid close code %1 detected.").arg(closeCode);
}
else
{
if (failed)
{
closeCode = QWebSocketProtocol::CC_WRONG_DATATYPE;
- closeReason = "Invalid UTF-8 code encountered.";
+ closeReason = QWebSocket::tr("Invalid UTF-8 code encountered.");
}
}
}
while (!m_pendingConnections.isEmpty())
{
QWebSocket *pWebSocket = m_pendingConnections.dequeue();
- pWebSocket->close(QWebSocketProtocol::CC_GOING_AWAY, "Server closed.");
+ pWebSocket->close(QWebSocketProtocol::CC_GOING_AWAY, QWebSocketServer::tr("Server closed."));
pWebSocket->deleteLater();
}
m_pTcpServer->deleteLater();
}
else
{
- qDebug() << "QWebSocketServerPrivate::handshakeReceived: Upgrading to WebSocket failed.";
+ //TODO: should set or emit error
+ qDebug() << QWebSocketServer::tr("Upgrading to websocket failed.");
}
}
else
{
- qDebug() << "QWebSocketServerPrivate::handshakeReceived: Cannot upgrade to websocket.";
+ //TODO: should set or emit error
+ qDebug() << QWebSocketServer::tr("Cannot upgrade to websocket.");
}
}
else
{
- qDebug() << "QWebSocketServerPrivate::handshakeReceived: Invalid response. This should not happen!!!";
+ //TODO: should set or emit error
+ qDebug() << QWebSocketServer::tr("Invalid response received.");
}
if (!success)
{
- qDebug() << "QWebSocketServerPrivate::handshakeReceived: Closing socket because of invalid or unsupported request";
+ //TODO: should set or emit error
+ qDebug() << QWebSocketServer::tr("Closing socket because of invalid or unsupported request.");
pTcpSocket->close();
}
}
else
{
- qDebug() << "WebSocketServerPrivate::handshakeReceived: Sender socket is NULL. This should not happen!!!";
+ qWarning() << "Sender socket is NULL. This should not happen, otherwise it is a Qt bug!!!";
}
}