summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/websockets/qwebsocket.h4
-rw-r--r--src/websockets/qwebsocket_p.cpp16
-rw-r--r--src/websockets/qwebsocketdataprocessor.cpp60
-rw-r--r--src/websockets/qwebsocketframe.cpp36
-rw-r--r--src/websockets/qwebsockethandshakeresponse.cpp10
-rw-r--r--src/websockets/qwebsocketprotocol.cpp122
-rw-r--r--src/websockets/qwebsocketprotocol.h46
-rw-r--r--src/websockets/qwebsocketprotocol_p.h40
-rw-r--r--src/websockets/qwebsocketserver.cpp22
-rw-r--r--src/websockets/qwebsocketserver.h4
-rw-r--r--src/websockets/qwebsocketserver_p.cpp16
-rw-r--r--src/websockets/qwebsocketserver_p.h4
12 files changed, 193 insertions, 187 deletions
diff --git a/src/websockets/qwebsocket.h b/src/websockets/qwebsocket.h
index 83fb285..4fba278 100644
--- a/src/websockets/qwebsocket.h
+++ b/src/websockets/qwebsocket.h
@@ -66,7 +66,7 @@ class Q_WEBSOCKETS_EXPORT QWebSocket : public QObject
public:
explicit QWebSocket(const QString &origin = QString(),
- QWebSocketProtocol::Version version = QWebSocketProtocol::V_LATEST,
+ QWebSocketProtocol::Version version = QWebSocketProtocol::VersionLatest,
QObject *parent = Q_NULLPTR);
virtual ~QWebSocket();
@@ -116,7 +116,7 @@ public:
#endif
public Q_SLOTS:
- void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CC_NORMAL,
+ void close(QWebSocketProtocol::CloseCode closeCode = QWebSocketProtocol::CloseCodeNormal,
const QString &reason = QString());
void open(const QUrl &url, bool mask = true);
void ping(const QByteArray &payload = QByteArray());
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp
index 6a027da..d94b175 100644
--- a/src/websockets/qwebsocket_p.cpp
+++ b/src/websockets/qwebsocket_p.cpp
@@ -103,7 +103,7 @@ QWebSocketPrivate::QWebSocketPrivate(const QString &origin, QWebSocketProtocol::
m_mustMask(true),
m_isClosingHandshakeSent(false),
m_isClosingHandshakeReceived(false),
- m_closeCode(QWebSocketProtocol::CC_NORMAL),
+ m_closeCode(QWebSocketProtocol::CloseCodeNormal),
m_closeReason(),
m_pingTimer(),
m_dataProcessor(),
@@ -132,7 +132,7 @@ QWebSocketPrivate::QWebSocketPrivate(QTcpSocket *pTcpSocket, QWebSocketProtocol:
m_mustMask(true),
m_isClosingHandshakeSent(false),
m_isClosingHandshakeReceived(false),
- m_closeCode(QWebSocketProtocol::CC_NORMAL),
+ m_closeCode(QWebSocketProtocol::CloseCodeNormal),
m_closeReason(),
m_pingTimer(),
m_dataProcessor(),
@@ -159,7 +159,7 @@ QWebSocketPrivate::~QWebSocketPrivate()
if (!m_pSocket)
return;
if (state() == QAbstractSocket::ConnectedState)
- close(QWebSocketProtocol::CC_GOING_AWAY, tr("Connection closed"));
+ close(QWebSocketProtocol::CloseCodeGoingAway, tr("Connection closed"));
releaseConnections(m_pSocket.data());
}
@@ -328,7 +328,7 @@ void QWebSocketPrivate::close(QWebSocketProtocol::CloseCode closeCode, QString r
maskingKey = generateMaskingKey();
QWebSocketProtocol::mask(payload.data(), payload.size(), maskingKey);
}
- QByteArray frame = getFrameHeader(QWebSocketProtocol::OC_CLOSE,
+ QByteArray frame = getFrameHeader(QWebSocketProtocol::OpCodeClose,
payload.size(), maskingKey, true);
frame.append(payload);
m_pSocket->write(frame);
@@ -444,7 +444,7 @@ void QWebSocketPrivate::ping(const QByteArray &payload)
{
QByteArray payloadTruncated = payload.left(125);
m_pingTimer.restart();
- QByteArray pingFrame = getFrameHeader(QWebSocketProtocol::OC_PING, payloadTruncated.size(),
+ QByteArray pingFrame = getFrameHeader(QWebSocketProtocol::OpCodePing, payloadTruncated.size(),
0 /*do not mask*/, true);
pingFrame.append(payloadTruncated);
qint64 ret = writeFrame(pingFrame);
@@ -698,7 +698,7 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
Q_Q(QWebSocket);
const QWebSocketProtocol::OpCode firstOpCode = isBinary ?
- QWebSocketProtocol::OC_BINARY : QWebSocketProtocol::OC_TEXT;
+ QWebSocketProtocol::OpCodeBinary : QWebSocketProtocol::OpCodeText;
int numFrames = data.size() / FRAME_SIZE_IN_BYTES;
QByteArray tmpData(data);
@@ -726,7 +726,7 @@ qint64 QWebSocketPrivate::doWriteFrames(const QByteArray &data, bool isBinary)
const quint64 size = qMin(bytesLeft, FRAME_SIZE_IN_BYTES);
const QWebSocketProtocol::OpCode opcode = isFirstFrame ? firstOpCode
- : QWebSocketProtocol::OC_CONTINUE;
+ : QWebSocketProtocol::OpCodeContinue;
//write header
bytesWritten += m_pSocket->write(getFrameHeader(opcode, size, maskingKey, isLastFrame));
@@ -1029,7 +1029,7 @@ void QWebSocketPrivate::processPing(const QByteArray &data)
quint32 maskingKey = 0;
if (m_mustMask)
maskingKey = generateMaskingKey();
- m_pSocket->write(getFrameHeader(QWebSocketProtocol::OC_PONG, data.size(), maskingKey, true));
+ m_pSocket->write(getFrameHeader(QWebSocketProtocol::OpCodePong, data.size(), maskingKey, true));
if (data.size() > 0) {
QByteArray maskedData = data;
if (m_mustMask)
diff --git a/src/websockets/qwebsocketdataprocessor.cpp b/src/websockets/qwebsocketdataprocessor.cpp
index 620f8c4..9f67225 100644
--- a/src/websockets/qwebsocketdataprocessor.cpp
+++ b/src/websockets/qwebsocketdataprocessor.cpp
@@ -78,7 +78,7 @@ QWebSocketDataProcessor::QWebSocketDataProcessor(QObject *parent) :
m_processingState(PS_READ_HEADER),
m_isFinalFrame(false),
m_isFragmented(false),
- m_opCode(QWebSocketProtocol::OC_CLOSE),
+ m_opCode(QWebSocketProtocol::OpCodeClose),
m_isControlFrame(false),
m_hasMask(false),
m_mask(0),
@@ -135,7 +135,7 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice)
//we have a dataframe; opcode can be OC_CONTINUE, OC_TEXT or OC_BINARY
if (Q_UNLIKELY(!m_isFragmented && frame.isContinuationFrame())) {
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeProtocolError,
tr("Received Continuation frame, while there is " \
"nothing to continue."));
return;
@@ -143,7 +143,7 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice)
if (Q_UNLIKELY(m_isFragmented && frame.isDataFrame() &&
!frame.isContinuationFrame())) {
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeProtocolError,
tr("All data frames after the initial data frame " \
"must have opcode 0 (continuation)."));
return;
@@ -152,18 +152,18 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice)
m_opCode = frame.opCode();
m_isFragmented = !frame.isFinalFrame();
}
- quint64 messageLength = (quint64)(m_opCode == QWebSocketProtocol::OC_TEXT)
+ quint64 messageLength = (quint64)(m_opCode == QWebSocketProtocol::OpCodeText)
? m_textMessage.length()
: m_binaryMessage.length();
if (Q_UNLIKELY((messageLength + quint64(frame.payload().length())) >
MAX_MESSAGE_SIZE_IN_BYTES)) {
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_TOO_MUCH_DATA,
+ Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeTooMuchData,
tr("Received message is too big."));
return;
}
- if (m_opCode == QWebSocketProtocol::OC_TEXT) {
+ if (m_opCode == QWebSocketProtocol::OpCodeText) {
QString frameTxt = m_pTextCodec->toUnicode(frame.payload().constData(),
frame.payload().size(),
m_pConverterState);
@@ -171,7 +171,7 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice)
|| (frame.isFinalFrame() && (m_pConverterState->remainingChars != 0));
if (Q_UNLIKELY(failed)) {
clear();
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_WRONG_DATATYPE,
+ Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeWrongDatatype,
tr("Invalid UTF-8 code encountered."));
return;
} else {
@@ -184,7 +184,7 @@ void QWebSocketDataProcessor::process(QIODevice *pIoDevice)
}
if (frame.isFinalFrame()) {
- if (m_opCode == QWebSocketProtocol::OC_TEXT)
+ if (m_opCode == QWebSocketProtocol::OpCodeText)
Q_EMIT textMessageReceived(m_textMessage);
else
Q_EMIT binaryMessageReceived(m_binaryMessage);
@@ -208,7 +208,7 @@ void QWebSocketDataProcessor::clear()
m_processingState = PS_READ_HEADER;
m_isFinalFrame = false;
m_isFragmented = false;
- m_opCode = QWebSocketProtocol::OC_CLOSE;
+ m_opCode = QWebSocketProtocol::OpCodeClose;
m_hasMask = false;
m_mask = 0;
m_binaryMessage.clear();
@@ -232,29 +232,29 @@ bool QWebSocketDataProcessor::processControlFrame(const QWebSocketFrame &frame)
{
bool mustStopProcessing = true; //control frames never expect additional frames to be processed
switch (frame.opCode()) {
- case QWebSocketProtocol::OC_PING:
+ case QWebSocketProtocol::OpCodePing:
Q_EMIT pingReceived(frame.payload());
break;
- case QWebSocketProtocol::OC_PONG:
+ case QWebSocketProtocol::OpCodePong:
Q_EMIT pongReceived(frame.payload());
break;
- case QWebSocketProtocol::OC_CLOSE:
+ case QWebSocketProtocol::OpCodeClose:
{
- quint16 closeCode = QWebSocketProtocol::CC_NORMAL;
+ quint16 closeCode = QWebSocketProtocol::CloseCodeNormal;
QString closeReason;
QByteArray payload = frame.payload();
if (Q_UNLIKELY(payload.size() == 1)) {
//size is either 0 (no close code and no reason)
//or >= 2 (at least a close code of 2 bytes)
- closeCode = QWebSocketProtocol::CC_PROTOCOL_ERROR;
+ closeCode = QWebSocketProtocol::CloseCodeProtocolError;
closeReason = tr("Payload of close frame is too small.");
} else if (Q_LIKELY(payload.size() > 1)) {
//close frame can have a close code and reason
closeCode = qFromBigEndian<quint16>(reinterpret_cast<const uchar *>(payload.constData()));
if (Q_UNLIKELY(!QWebSocketProtocol::isCloseCodeValid(closeCode))) {
- closeCode = QWebSocketProtocol::CC_PROTOCOL_ERROR;
+ closeCode = QWebSocketProtocol::CloseCodeProtocolError;
closeReason = tr("Invalid close code %1 detected.").arg(closeCode);
} else {
if (payload.size() > 2) {
@@ -263,7 +263,7 @@ bool QWebSocketDataProcessor::processControlFrame(const QWebSocketFrame &frame)
closeReason = tc->toUnicode(payload.constData() + 2, payload.size() - 2, &state);
const bool failed = (state.invalidChars != 0) || (state.remainingChars != 0);
if (Q_UNLIKELY(failed)) {
- closeCode = QWebSocketProtocol::CC_WRONG_DATATYPE;
+ closeCode = QWebSocketProtocol::CloseCodeWrongDatatype;
closeReason = tr("Invalid UTF-8 code encountered.");
}
}
@@ -273,25 +273,25 @@ bool QWebSocketDataProcessor::processControlFrame(const QWebSocketFrame &frame)
break;
}
- case QWebSocketProtocol::OC_CONTINUE:
- case QWebSocketProtocol::OC_BINARY:
- case QWebSocketProtocol::OC_TEXT:
- case QWebSocketProtocol::OC_RESERVED_3:
- case QWebSocketProtocol::OC_RESERVED_4:
- case QWebSocketProtocol::OC_RESERVED_5:
- case QWebSocketProtocol::OC_RESERVED_6:
- case QWebSocketProtocol::OC_RESERVED_7:
- case QWebSocketProtocol::OC_RESERVED_C:
- case QWebSocketProtocol::OC_RESERVED_B:
- case QWebSocketProtocol::OC_RESERVED_D:
- case QWebSocketProtocol::OC_RESERVED_E:
- case QWebSocketProtocol::OC_RESERVED_F:
+ case QWebSocketProtocol::OpCodeContinue:
+ case QWebSocketProtocol::OpCodeBinary:
+ case QWebSocketProtocol::OpCodeText:
+ case QWebSocketProtocol::OpCodeReserved3:
+ case QWebSocketProtocol::OpCodeReserved4:
+ case QWebSocketProtocol::OpCodeReserved5:
+ case QWebSocketProtocol::OpCodeReserved6:
+ case QWebSocketProtocol::OpCodeReserved7:
+ case QWebSocketProtocol::OpCodeReservedC:
+ case QWebSocketProtocol::OpCodeReservedB:
+ case QWebSocketProtocol::OpCodeReservedD:
+ case QWebSocketProtocol::OpCodeReservedE:
+ case QWebSocketProtocol::OpCodeReservedF:
//do nothing
//case statements added to make C++ compiler happy
break;
default:
- Q_EMIT errorEncountered(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ Q_EMIT errorEncountered(QWebSocketProtocol::CloseCodeProtocolError,
tr("Invalid opcode detected: %1").arg(int(frame.opCode())));
//do nothing
break;
diff --git a/src/websockets/qwebsocketframe.cpp b/src/websockets/qwebsocketframe.cpp
index 7c50e81..f5a4787 100644
--- a/src/websockets/qwebsocketframe.cpp
+++ b/src/websockets/qwebsocketframe.cpp
@@ -67,14 +67,14 @@ QT_BEGIN_NAMESPACE
\internal
*/
QWebSocketFrame::QWebSocketFrame() :
- m_closeCode(QWebSocketProtocol::CC_NORMAL),
+ m_closeCode(QWebSocketProtocol::CloseCodeNormal),
m_closeReason(),
m_isFinalFrame(true),
m_mask(0),
m_rsv1(0),
m_rsv2(0),
m_rsv3(0),
- m_opCode(QWebSocketProtocol::OC_RESERVED_C),
+ m_opCode(QWebSocketProtocol::OpCodeReservedC),
m_length(0),
m_payload(),
m_isValid(false)
@@ -225,7 +225,7 @@ bool QWebSocketFrame::isDataFrame() const
*/
bool QWebSocketFrame::isContinuationFrame() const
{
- return isDataFrame() && (m_opCode == QWebSocketProtocol::OC_CONTINUE);
+ return isDataFrame() && (m_opCode == QWebSocketProtocol::OpCodeContinue);
}
/*!
@@ -291,14 +291,14 @@ QByteArray QWebSocketFrame::payload() const
*/
void QWebSocketFrame::clear()
{
- m_closeCode = QWebSocketProtocol::CC_NORMAL;
+ m_closeCode = QWebSocketProtocol::CloseCodeNormal;
m_closeReason.clear();
m_isFinalFrame = true;
m_mask = 0;
m_rsv1 = 0;
m_rsv2 = 0;
m_rsv3 = 0;
- m_opCode = QWebSocketProtocol::OC_RESERVED_C;
+ m_opCode = QWebSocketProtocol::OpCodeReservedC;
m_length = 0;
m_payload.clear();
m_isValid = false;
@@ -340,7 +340,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
//the GUI will hang for at most 5 seconds
//maybe, a QStateMachine should be used
if (!pIoDevice->waitForReadyRead(5000)) {
- frame.setError(QWebSocketProtocol::CC_GOING_AWAY,
+ frame.setError(QWebSocketProtocol::CloseCodeGoingAway,
QObject::tr("Timeout when reading data from socket."));
processingState = PS_DISPATCH_RESULT;
} else {
@@ -394,7 +394,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
uchar length[2] = {0};
bytesRead = pIoDevice->read(reinterpret_cast<char *>(length), 2);
if (Q_UNLIKELY(bytesRead == -1)) {
- frame.setError(QWebSocketProtocol::CC_GOING_AWAY,
+ frame.setError(QWebSocketProtocol::CloseCodeGoingAway,
QObject::tr("Error occurred while reading from the network: %1")
.arg(pIoDevice->errorString()));
processingState = PS_DISPATCH_RESULT;
@@ -405,7 +405,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
//"in all cases, the minimal number of bytes MUST be used to encode
//the length, for example, the length of a 124-byte-long string
//can't be encoded as the sequence 126, 0, 124"
- frame.setError(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ frame.setError(QWebSocketProtocol::CloseCodeProtocolError,
QObject::tr("Lengths smaller than 126 " \
"must be expressed as one byte."));
processingState = PS_DISPATCH_RESULT;
@@ -423,7 +423,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
uchar length[8] = {0};
bytesRead = pIoDevice->read(reinterpret_cast<char *>(length), 8);
if (Q_UNLIKELY(bytesRead < 8)) {
- frame.setError(QWebSocketProtocol::CC_ABNORMAL_DISCONNECTION,
+ frame.setError(QWebSocketProtocol::CloseCodeAbnormalDisconnection,
QObject::tr("Something went wrong during "\
"reading from the network."));
processingState = PS_DISPATCH_RESULT;
@@ -432,7 +432,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
//per http://tools.ietf.org/html/rfc6455#section-5.2
payloadLength = qFromBigEndian<quint64>(length);
if (Q_UNLIKELY(payloadLength & (quint64(1) << 63))) {
- frame.setError(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ frame.setError(QWebSocketProtocol::CloseCodeProtocolError,
QObject::tr("Highest bit of payload length is not 0."));
processingState = PS_DISPATCH_RESULT;
} else if (Q_UNLIKELY(payloadLength <= 0xFFFFu)) {
@@ -440,7 +440,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
//"in all cases, the minimal number of bytes MUST be used to encode
//the length, for example, the length of a 124-byte-long string
//can't be encoded as the sequence 126, 0, 124"
- frame.setError(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ frame.setError(QWebSocketProtocol::CloseCodeProtocolError,
QObject::tr("Lengths smaller than 65536 (2^16) " \
"must be expressed as 2 bytes."));
processingState = PS_DISPATCH_RESULT;
@@ -459,7 +459,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
bytesRead = pIoDevice->read(reinterpret_cast<char *>(&frame.m_mask),
sizeof(frame.m_mask));
if (bytesRead == -1) {
- frame.setError(QWebSocketProtocol::CC_GOING_AWAY,
+ frame.setError(QWebSocketProtocol::CloseCodeGoingAway,
QObject::tr("Error while reading from the network: %1.")
.arg(pIoDevice->errorString()));
processingState = PS_DISPATCH_RESULT;
@@ -476,7 +476,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
if (!payloadLength) {
processingState = PS_DISPATCH_RESULT;
} else if (Q_UNLIKELY(payloadLength > MAX_FRAME_SIZE_IN_BYTES)) {
- frame.setError(QWebSocketProtocol::CC_TOO_MUCH_DATA,
+ frame.setError(QWebSocketProtocol::CloseCodeTooMuchData,
QObject::tr("Maximum framesize exceeded."));
processingState = PS_DISPATCH_RESULT;
} else {
@@ -487,7 +487,7 @@ QWebSocketFrame QWebSocketFrame::readFrame(QIODevice *pIoDevice)
//because MAX_FRAME_SIZE_IN_BYTES = MAX_INT
if (Q_UNLIKELY(frame.m_payload.length() != int(payloadLength))) {
//some error occurred; refer to the Qt documentation of QIODevice::read()
- frame.setError(QWebSocketProtocol::CC_ABNORMAL_DISCONNECTION,
+ frame.setError(QWebSocketProtocol::CloseCodeAbnormalDisconnection,
QObject::tr("Some serious error occurred " \
"while reading from the network."));
processingState = PS_DISPATCH_RESULT;
@@ -539,15 +539,15 @@ bool QWebSocketFrame::checkValidity()
if (isValid())
return true;
if (Q_UNLIKELY(m_rsv1 || m_rsv2 || m_rsv3)) {
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QObject::tr("Rsv field is non-zero"));
+ setError(QWebSocketProtocol::CloseCodeProtocolError, QObject::tr("Rsv field is non-zero"));
} else if (Q_UNLIKELY(QWebSocketProtocol::isOpCodeReserved(m_opCode))) {
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, QObject::tr("Used reserved opcode"));
+ setError(QWebSocketProtocol::CloseCodeProtocolError, QObject::tr("Used reserved opcode"));
} else if (isControlFrame()) {
if (Q_UNLIKELY(m_length > 125)) {
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ setError(QWebSocketProtocol::CloseCodeProtocolError,
QObject::tr("Controle frame is larger than 125 bytes"));
} else if (Q_UNLIKELY(!m_isFinalFrame)) {
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR,
+ setError(QWebSocketProtocol::CloseCodeProtocolError,
QObject::tr("Controle frames cannot be fragmented"));
} else {
m_isValid = true;
diff --git a/src/websockets/qwebsockethandshakeresponse.cpp b/src/websockets/qwebsockethandshakeresponse.cpp
index dbf4b6f..3700b21 100644
--- a/src/websockets/qwebsockethandshakeresponse.cpp
+++ b/src/websockets/qwebsockethandshakeresponse.cpp
@@ -72,8 +72,8 @@ QWebSocketHandshakeResponse::QWebSocketHandshakeResponse(
m_response(),
m_acceptedProtocol(),
m_acceptedExtension(),
- m_acceptedVersion(QWebSocketProtocol::V_Unknow),
- m_error(QWebSocketProtocol::CC_NORMAL),
+ m_acceptedVersion(QWebSocketProtocol::VersionUnknown),
+ m_error(QWebSocketProtocol::CloseCodeNormal),
m_errorString()
{
m_response = getHandshakeResponse(request, serverName,
@@ -140,7 +140,7 @@ QString QWebSocketHandshakeResponse::getHandshakeResponse(
if (!isOriginAllowed) {
if (!m_canUpgrade) {
- m_error = QWebSocketProtocol::CC_POLICY_VIOLATED;
+ m_error = QWebSocketProtocol::CloseCodePolicyViolated;
m_errorString = tr("Access forbidden.");
response << QStringLiteral("HTTP/1.1 403 Access Forbidden");
}
@@ -157,7 +157,7 @@ QString QWebSocketHandshakeResponse::getHandshakeResponse(
std::greater<QWebSocketProtocol::Version>()); //sort in descending order
if (Q_UNLIKELY(matchingVersions.isEmpty())) {
- m_error = QWebSocketProtocol::CC_PROTOCOL_ERROR;
+ m_error = QWebSocketProtocol::CloseCodeProtocolError;
m_errorString = tr("Unsupported version requested.");
m_canUpgrade = false;
} else {
@@ -189,7 +189,7 @@ QString QWebSocketHandshakeResponse::getHandshakeResponse(
m_canUpgrade = true;
}
} else {
- m_error = QWebSocketProtocol::CC_PROTOCOL_ERROR;
+ m_error = QWebSocketProtocol::CloseCodeProtocolError;
m_errorString = tr("Bad handshake request received.");
m_canUpgrade = false;
}
diff --git a/src/websockets/qwebsocketprotocol.cpp b/src/websockets/qwebsocketprotocol.cpp
index 3b5c52d..efcc313 100644
--- a/src/websockets/qwebsocketprotocol.cpp
+++ b/src/websockets/qwebsocketprotocol.cpp
@@ -59,19 +59,19 @@ QT_BEGIN_NAMESPACE
The close codes supported by WebSockets V13
- \value CC_NORMAL Normal closure
- \value CC_GOING_AWAY Going away
- \value CC_PROTOCOL_ERROR Protocol error
- \value CC_DATATYPE_NOT_SUPPORTED Unsupported data
- \value CC_RESERVED_1004 Reserved
- \value CC_MISSING_STATUS_CODE No status received
- \value CC_ABNORMAL_DISCONNECTION Abnormal closure
- \value CC_WRONG_DATATYPE Invalid frame payload data
- \value CC_POLICY_VIOLATED Policy violation
- \value CC_TOO_MUCH_DATA Message too big
- \value CC_MISSING_EXTENSION Mandatory extension missing
- \value CC_BAD_OPERATION Internal server error
- \value CC_TLS_HANDSHAKE_FAILED TLS handshake failed
+ \value CloseCodeNormal Normal closure
+ \value CloseCodeGoingAway Going away
+ \value CloseCodeProtocolError Protocol error
+ \value CloseCodeDatatypeNotSupported Unsupported data
+ \value CloseCodeReserved1004 Reserved
+ \value CloseCodeMissingStatusCode No status received
+ \value CloseCodeAbnormalDisconnection Abnormal closure
+ \value CloseCodeWrongDatatype Invalid frame payload data
+ \value CloseCodePolicyViolated Policy violation
+ \value CloseCodeTooMuchData Message too big
+ \value CloseCodeMissingExtension Mandatory extension missing
+ \value CloseCodeBadOperation Internal server error
+ \value CloseCodeHandshakeFailed TLS handshake failed
\sa QWebSocket::close()
*/
@@ -85,33 +85,38 @@ QT_BEGIN_NAMESPACE
For an overview of the differences between the different protocols, see
<http://code.google.com/p/pywebsocket/wiki/WebSocketProtocolSpec>
- \value V_Unknow
- \value V_0 hixie76: http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 &
- hybi-00: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00.
- Works with key1, key2 and a key in the payload.
- Attribute: Sec-WebSocket-Draft value 0.
- \value V_4 hybi-04: http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-04.txt.
- Changed handshake: key1, key2, key3
- ==> Sec-WebSocket-Key, Sec-WebSocket-Nonce, Sec-WebSocket-Accept
- Sec-WebSocket-Draft renamed to Sec-WebSocket-Version
- Sec-WebSocket-Version = 4
- \value V_5 hybi-05: http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-05.txt.
- Sec-WebSocket-Version = 5
- Removed Sec-WebSocket-Nonce
- Added Sec-WebSocket-Accept
- \value V_6 Sec-WebSocket-Version = 6.
- \value V_7 hybi-07: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07.
- Sec-WebSocket-Version = 7
- \value V_8 hybi-8, hybi-9, hybi-10, hybi-11 and hybi-12.
- Status codes 1005 and 1006 are added and all codes are now unsigned
- Internal error results in 1006
- \value V_13 hybi-13, hybi14, hybi-15, hybi-16, hybi-17 and RFC 6455.
- Sec-WebSocket-Version = 13
- Status code 1004 is now reserved
- Added 1008, 1009 and 1010
- Must support TLS
- Clarify multiple version support
- \value V_LATEST Refers to the latest know version to QWebSockets.
+ \value VersionUnknow Unknown or unspecified version.
+ \value Version0 hixie76:
+ http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 &
+ hybi-00:
+ http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00.
+ Works with key1, key2 and a key in the payload.
+ Attribute: Sec-WebSocket-Draft value 0.
+ \value Version4 hybi-04:
+ http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-04.txt.
+ Changed handshake: key1, key2, key3
+ ==> Sec-WebSocket-Key, Sec-WebSocket-Nonce, Sec-WebSocket-Accept
+ Sec-WebSocket-Draft renamed to Sec-WebSocket-Version
+ Sec-WebSocket-Version = 4.
+ \value Version5 hybi-05:
+ http://tools.ietf.org/id/draft-ietf-hybi-thewebsocketprotocol-05.txt.
+ Sec-WebSocket-Version = 5
+ Removed Sec-WebSocket-Nonce
+ Added Sec-WebSocket-Accept.
+ \value Version6 Sec-WebSocket-Version = 6.
+ \value Version7 hybi-07:
+ http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07.
+ Sec-WebSocket-Version = 7.
+ \value Version8 hybi-8, hybi-9, hybi-10, hybi-11 and hybi-12.
+ Status codes 1005 and 1006 are added and all codes are now unsigned
+ Internal error results in 1006.
+ \value Version13 hybi-13, hybi14, hybi-15, hybi-16, hybi-17 and RFC 6455.
+ Sec-WebSocket-Version = 13
+ Status code 1004 is now reserved
+ Added 1008, 1009 and 1010
+ Must support TLS
+ Clarify multiple version suppor.t
+ \value VersionLatest Refers to the latest known version to QtWebSockets.
*/
/*!
@@ -121,22 +126,22 @@ QT_BEGIN_NAMESPACE
The frame opcodes as defined by the WebSockets standard
- \value OC_CONTINUE Continuation frame
- \value OC_TEXT Text frame
- \value OC_BINARY Binary frame
- \value OC_RESERVED_3 Reserved
- \value OC_RESERVED_4 Reserved
- \value OC_RESERVED_5 Reserved
- \value OC_RESERVED_6 Reserved
- \value OC_RESERVED_7 Reserved
- \value OC_CLOSE Close frame
- \value OC_PING Ping frame
- \value OC_PONG Pong frame
- \value OC_RESERVED_B Reserved
- \value OC_RESERVED_C Reserved
- \value OC_RESERVED_D Reserved
- \value OC_RESERVED_E Reserved
- \value OC_RESERVED_F Reserved
+ \value OpCodeContinue Continuation frame
+ \value OpCodeText Text frame
+ \value OpCodeBinary Binary frame
+ \value OpCodeReserved3 Reserved
+ \value OpCodeReserved4 Reserved
+ \value OpCodeReserved5 Reserved
+ \value OpCodeReserved6 Reserved
+ \value OpCodeReserved7 Reserved
+ \value OpCodeClose Close frame
+ \value OpCodePing Ping frame
+ \value OpCodePong Pong frame
+ \value OpCodeReservedB Reserved
+ \value OpCodeReservedC Reserved
+ \value OpCodeReservedD Reserved
+ \value OpCodeReservedE Reserved
+ \value OpCodeReservedF Reserved
\internal
*/
@@ -170,10 +175,11 @@ QT_BEGIN_NAMESPACE
QWebSocketProtocol::Version QWebSocketProtocol::versionFromString(const QString &versionString)
{
bool ok = false;
- Version version = V_Unknow;
+ Version version = VersionUnknown;
const int ver = versionString.toInt(&ok);
QSet<Version> supportedVersions;
- supportedVersions << V_0 << V_4 << V_5 << V_6 << V_7 << V_8 << V_13;
+ supportedVersions << Version0 << Version4 << Version5 << Version6 << Version7 << Version8
+ << Version13;
if (Q_LIKELY(ok) && (supportedVersions.contains(static_cast<Version>(ver))))
version = static_cast<Version>(ver);
return version;
diff --git a/src/websockets/qwebsocketprotocol.h b/src/websockets/qwebsocketprotocol.h
index de62d75..c058937 100644
--- a/src/websockets/qwebsocketprotocol.h
+++ b/src/websockets/qwebsocketprotocol.h
@@ -53,38 +53,38 @@ namespace QWebSocketProtocol
{
enum Version
{
- V_Unknow = -1,
- V_0 = 0,
+ VersionUnknown = -1,
+ Version0 = 0,
//hybi-01, hybi-02 and hybi-03 not supported
- V_4 = 4,
- V_5 = 5,
- V_6 = 6,
- V_7 = 7,
- V_8 = 8,
- V_13 = 13,
- V_LATEST = V_13
+ Version4 = 4,
+ Version5 = 5,
+ Version6 = 6,
+ Version7 = 7,
+ Version8 = 8,
+ Version13 = 13,
+ VersionLatest = Version13
};
Version versionFromString(const QString &versionString);
enum CloseCode
{
- CC_NORMAL = 1000,
- CC_GOING_AWAY = 1001,
- CC_PROTOCOL_ERROR = 1002,
- CC_DATATYPE_NOT_SUPPORTED = 1003,
- CC_RESERVED_1004 = 1004,
- CC_MISSING_STATUS_CODE = 1005,
- CC_ABNORMAL_DISCONNECTION = 1006,
- CC_WRONG_DATATYPE = 1007,
- CC_POLICY_VIOLATED = 1008,
- CC_TOO_MUCH_DATA = 1009,
- CC_MISSING_EXTENSION = 1010,
- CC_BAD_OPERATION = 1011,
- CC_TLS_HANDSHAKE_FAILED = 1015
+ CloseCodeNormal = 1000,
+ CloseCodeGoingAway = 1001,
+ CloseCodeProtocolError = 1002,
+ CloseCodeDatatypeNotSupported = 1003,
+ CloseCodeReserved1004 = 1004,
+ CloseCodeMissingStatusCode = 1005,
+ CloseCodeAbnormalDisconnection = 1006,
+ CloseCodeWrongDatatype = 1007,
+ CloseCodePolicyViolated = 1008,
+ CloseCodeTooMuchData = 1009,
+ CloseCodeMissingExtension = 1010,
+ CloseCodeBadOperation = 1011,
+ CloseCodeTlsHandshakeFailed = 1015
};
-inline Version currentVersion() { return V_LATEST; }
+inline Version currentVersion() { return VersionLatest; }
} //end namespace QWebSocketProtocol
diff --git a/src/websockets/qwebsocketprotocol_p.h b/src/websockets/qwebsocketprotocol_p.h
index 2fcbb4d..e2c883a 100644
--- a/src/websockets/qwebsocketprotocol_p.h
+++ b/src/websockets/qwebsocketprotocol_p.h
@@ -54,35 +54,35 @@ namespace QWebSocketProtocol
{
enum OpCode
{
- OC_CONTINUE = 0x0,
- OC_TEXT = 0x1,
- OC_BINARY = 0x2,
- OC_RESERVED_3 = 0x3,
- OC_RESERVED_4 = 0x4,
- OC_RESERVED_5 = 0x5,
- OC_RESERVED_6 = 0x6,
- OC_RESERVED_7 = 0x7,
- OC_CLOSE = 0x8,
- OC_PING = 0x9,
- OC_PONG = 0xA,
- OC_RESERVED_B = 0xB,
- OC_RESERVED_C = 0xC,
- OC_RESERVED_D = 0xD,
- OC_RESERVED_E = 0xE,
- OC_RESERVED_F = 0xF
+ 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 > OC_BINARY) && (code < OC_CLOSE)) || (code > OC_PONG);
+ return ((code > OpCodeBinary) && (code < OpCodeClose)) || (code > OpCodePong);
}
inline bool isCloseCodeValid(int closeCode)
{
return (closeCode > 999) && (closeCode < 5000) &&
- (closeCode != CC_RESERVED_1004) && //see RFC6455 7.4.1
- (closeCode != CC_MISSING_STATUS_CODE) &&
- (closeCode != CC_ABNORMAL_DISCONNECTION) &&
+ (closeCode != CloseCodeReserved1004) && //see RFC6455 7.4.1
+ (closeCode != CloseCodeMissingStatusCode) &&
+ (closeCode != CloseCodeAbnormalDisconnection) &&
((closeCode >= 3000) || (closeCode < 1012));
}
diff --git a/src/websockets/qwebsocketserver.cpp b/src/websockets/qwebsocketserver.cpp
index ea7144d..dcc4309 100644
--- a/src/websockets/qwebsocketserver.cpp
+++ b/src/websockets/qwebsocketserver.cpp
@@ -182,10 +182,10 @@
/*!
\enum QWebSocketServer::SecureMode
- Indicates whether the server operates over wss (SECURE_MODE) or ws (NON_SECURE_MODE)
+ Indicates whether the server operates over wss (SecureModeSecure) or ws (SecureModeNonSecure)
- \value SECURE_MODE The server operates in secure mode (over wss)
- \value NON_SECURE_MODE The server operates in non-secure mode (over ws)
+ \value SecureModeSecure The server operates in secure mode (over wss)
+ \value SecureModeNonSecure The server operates in non-secure mode (over ws)
*/
#include "qwebsocketprotocol.h"
@@ -216,11 +216,11 @@ QWebSocketServer::QWebSocketServer(const QString &serverName, SecureMode secureM
QObject(parent),
d_ptr(new QWebSocketServerPrivate(serverName,
#ifndef QT_NO_SSL
- (secureMode == SECURE_MODE) ?
- QWebSocketServerPrivate::SECURE_MODE :
- QWebSocketServerPrivate::NON_SECURE_MODE,
+ (secureMode == SecureModeSecure) ?
+ QWebSocketServerPrivate::SecureModeSecure :
+ QWebSocketServerPrivate::SecureModeNonSecure,
#else
- QWebSocketServerPrivate::NON_SECURE_MODE,
+ QWebSocketServerPrivate::SecureModeNonSecure,
#endif
this,
this))
@@ -373,7 +373,7 @@ void QWebSocketServer::setProxy(const QNetworkProxy &networkProxy)
/*!
Sets the SSL configuration for the websocket server to \a sslConfiguration.
This method has no effect if QWebSocketServer runs in non-secure mode
- (QWebSocketServer::NON_SECURE_MODE).
+ (QWebSocketServer::SecureModeNonSecure).
\sa sslConfiguration(), SecureMode
*/
@@ -449,10 +449,10 @@ QWebSocketServer::SecureMode QWebSocketServer::secureMode() const
{
#ifndef QT_NO_SSL
Q_D(const QWebSocketServer);
- return (d->secureMode() == QWebSocketServerPrivate::SECURE_MODE) ?
- QWebSocketServer::SECURE_MODE : QWebSocketServer::NON_SECURE_MODE;
+ return (d->secureMode() == QWebSocketServerPrivate::SecureModeSecure) ?
+ QWebSocketServer::SecureModeSecure : QWebSocketServer::SecureModeNonSecure;
#else
- return QWebSocketServer::NON_SECURE_MODE;
+ return QWebSocketServer::SecureModeNonSecure;
#endif
}
diff --git a/src/websockets/qwebsocketserver.h b/src/websockets/qwebsocketserver.h
index 7e484fb..2267a66 100644
--- a/src/websockets/qwebsocketserver.h
+++ b/src/websockets/qwebsocketserver.h
@@ -71,9 +71,9 @@ class Q_WEBSOCKETS_EXPORT QWebSocketServer : public QObject
public:
enum SecureMode {
#ifndef QT_NO_SSL
- SECURE_MODE,
+ SecureModeSecure,
#endif
- NON_SECURE_MODE
+ SecureModeNonSecure
};
explicit QWebSocketServer(const QString &serverName, SecureMode secureMode,
diff --git a/src/websockets/qwebsocketserver_p.cpp b/src/websockets/qwebsocketserver_p.cpp
index 52955ad..4490826 100644
--- a/src/websockets/qwebsocketserver_p.cpp
+++ b/src/websockets/qwebsocketserver_p.cpp
@@ -70,11 +70,11 @@ QWebSocketServerPrivate::QWebSocketServerPrivate(const QString &serverName,
m_serverName(serverName),
m_secureMode(secureMode),
m_pendingConnections(),
- m_error(QWebSocketProtocol::CC_NORMAL),
+ m_error(QWebSocketProtocol::CloseCodeNormal),
m_errorString()
{
Q_ASSERT(pWebSocketServer);
- if (m_secureMode == NON_SECURE_MODE) {
+ if (m_secureMode == SecureModeSecure) {
m_pTcpServer = new QTcpServer(this);
if (Q_LIKELY(m_pTcpServer))
connect(m_pTcpServer, &QTcpServer::newConnection,
@@ -118,7 +118,7 @@ void QWebSocketServerPrivate::close()
m_pTcpServer->close();
while (!m_pendingConnections.isEmpty()) {
QWebSocket *pWebSocket = m_pendingConnections.dequeue();
- pWebSocket->close(QWebSocketProtocol::CC_GOING_AWAY, tr("Server closed."));
+ pWebSocket->close(QWebSocketProtocol::CloseCodeGoingAway, tr("Server closed."));
pWebSocket->deleteLater();
}
//emit signal via the event queue, so the server gets time
@@ -326,7 +326,7 @@ QWebSocketServerPrivate::SecureMode QWebSocketServerPrivate::secureMode() const
#ifndef QT_NO_SSL
void QWebSocketServerPrivate::setSslConfiguration(const QSslConfiguration &sslConfiguration)
{
- if (m_secureMode == SECURE_MODE)
+ if (m_secureMode == SecureModeSecure)
qobject_cast<QSslServer *>(m_pTcpServer)->setSslConfiguration(sslConfiguration);
else
qWarning() << tr("Cannot set SSL configuration for non-secure server.");
@@ -334,7 +334,7 @@ void QWebSocketServerPrivate::setSslConfiguration(const QSslConfiguration &sslCo
QSslConfiguration QWebSocketServerPrivate::sslConfiguration() const
{
- if (m_secureMode == SECURE_MODE)
+ if (m_secureMode == SecureModeSecure)
return qobject_cast<QSslServer *>(m_pTcpServer)->sslConfiguration();
else
return QSslConfiguration::defaultConfiguration();
@@ -388,7 +388,7 @@ void QWebSocketServerPrivate::handshakeReceived()
pTcpSocket->close();
qWarning() <<
tr("Too many pending connections: new websocket connection not accepted.");
- setError(QWebSocketProtocol::CC_ABNORMAL_DISCONNECTION,
+ setError(QWebSocketProtocol::CloseCodeAbnormalDisconnection,
tr("Too many pending connections."));
return;
}
@@ -423,7 +423,7 @@ void QWebSocketServerPrivate::handshakeReceived()
Q_EMIT q->newConnection();
success = true;
} else {
- setError(QWebSocketProtocol::CC_ABNORMAL_DISCONNECTION,
+ setError(QWebSocketProtocol::CloseCodeAbnormalDisconnection,
tr("Upgrading to websocket failed."));
}
}
@@ -431,7 +431,7 @@ void QWebSocketServerPrivate::handshakeReceived()
setError(response.error(), response.errorString());
}
} else {
- setError(QWebSocketProtocol::CC_PROTOCOL_ERROR, tr("Invalid response received."));
+ setError(QWebSocketProtocol::CloseCodeProtocolError, tr("Invalid response received."));
}
}
if (!success) {
diff --git a/src/websockets/qwebsocketserver_p.h b/src/websockets/qwebsocketserver_p.h
index b7072e0..9a2977e 100644
--- a/src/websockets/qwebsocketserver_p.h
+++ b/src/websockets/qwebsocketserver_p.h
@@ -77,8 +77,8 @@ class QWebSocketServerPrivate : public QObject
public:
enum SecureMode
{
- SECURE_MODE = true,
- NON_SECURE_MODE
+ SecureModeSecure = true,
+ SecureModeNonSecure
};
explicit QWebSocketServerPrivate(const QString &serverName, SecureMode secureMode,