/*!
\internal
*/
+quint64 DataProcessor::maxMessageSize()
+{
+ return MAX_MESSAGE_SIZE_IN_BYTES;
+}
+
+/*!
+ \internal
+ */
+quint64 DataProcessor::maxFrameSize()
+{
+ return MAX_FRAME_SIZE_IN_BYTES;
+}
+
+/*!
+ \internal
+ */
void DataProcessor::process(QIODevice *pIoDevice)
{
bool isDone = false;
quint16 closeCode = QWebSocketProtocol::CC_NORMAL;
QString closeReason;
QByteArray payload = frame.getPayload();
- if (payload.size() > 0) //close frame can have a close code and reason
+ if (payload.size() == 1)
+ {
+ closeCode = QWebSocketProtocol::CC_PROTOCOL_ERROR;
+ closeReason = tr("Payload of close frame is too small.");
+ }
+ else if (payload.size() > 1) //close frame can have a close code and reason
{
closeCode = qFromBigEndian<quint16>(reinterpret_cast<const uchar *>(payload.constData()));
if (!QWebSocketProtocol::isCloseCodeValid(closeCode))
explicit DataProcessor(QObject *parent = 0);
virtual ~DataProcessor();
+ static quint64 maxMessageSize();
+ static quint64 maxFrameSize();
+
Q_SIGNALS:
void pingReceived(QByteArray data);
void pongReceived(QByteArray data);
//only data frames are checked for being too big
//control frames have explicit checking on a maximum payload size of 125, which is tested elsewhere
- //TODO: get maximum framesize from the frame somehow
- //the maximum framesize is currently defined as a constant in the dataprocessor_p.cpp file
- //and is set to MAX_INT; changing that value will make this test fail (which is not good)
- swapped64 = qToBigEndian<quint64>(quint64(INT_MAX + 1));
+ swapped64 = qToBigEndian<quint64>(DataProcessor::maxFrameSize() + 1);
wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped64));
QTest::newRow("Text frame with payload size > INT_MAX")
<< quint8(FIN | QWebSocketProtocol::OC_TEXT)
<< false
<< QWebSocketProtocol::CC_TOO_MUCH_DATA;
- swapped64 = qToBigEndian<quint64>(quint64(INT_MAX + 1));
+ swapped64 = qToBigEndian<quint64>(DataProcessor::maxFrameSize() + 1);
wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped64));
QTest::newRow("Binary frame with payload size > INT_MAX")
<< quint8(FIN | QWebSocketProtocol::OC_BINARY)
<< false
<< QWebSocketProtocol::CC_TOO_MUCH_DATA;
- swapped64 = qToBigEndian<quint64>(quint64(INT_MAX + 1));
+ swapped64 = qToBigEndian<quint64>(DataProcessor::maxFrameSize() + 1);
wireRepresentation = static_cast<const char *>(static_cast<const void *>(&swapped64));
QTest::newRow("Continuation frame with payload size > INT_MAX")
<< quint8(FIN | QWebSocketProtocol::OC_CONTINUE)