diff options
author | Steven Ceuppens <steven.ceuppens@icloud.com> | 2013-09-29 20:41:29 +0200 |
---|---|---|
committer | Steven Ceuppens <steven.ceuppens@icloud.com> | 2013-09-29 20:50:42 +0200 |
commit | 7621610532e94ff1450a09153ab09d38b4cc0db4 (patch) | |
tree | a3fde2e453508f658af389fb3b841f697370206f /src/websockets/qwebsocketframe_p.h | |
parent | 9292fa44f4c8d58aa365b4389be040584a17c893 (diff) | |
download | qtwebsockets-7621610532e94ff1450a09153ab09d38b4cc0db4.tar.gz |
moved class to separate file
As QWebSocketFrame is quite big, i moved it into its own file, for futher implementation:wq
Change-Id: Iadf51323d5e8151c8345057614f4c49f81e626b1
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
Diffstat (limited to 'src/websockets/qwebsocketframe_p.h')
-rw-r--r-- | src/websockets/qwebsocketframe_p.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/websockets/qwebsocketframe_p.h b/src/websockets/qwebsocketframe_p.h new file mode 100644 index 0000000..434fead --- /dev/null +++ b/src/websockets/qwebsocketframe_p.h @@ -0,0 +1,104 @@ +/* +QWebSockets implements the WebSocket protocol as defined in RFC 6455. +Copyright (C) 2013 Kurt Pattyn (pattyn.kurt@gmail.com) + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef QWEBSOCKETFRAME_P_H +#define QWEBSOCKETFRAME_P_H + +#include "qwebsocketprotocol.h" + +#include <QIODevice> + +QT_BEGIN_NAMESPACE + +const quint64 MAX_FRAME_SIZE_IN_BYTES = INT_MAX - 1; +const quint64 MAX_MESSAGE_SIZE_IN_BYTES = INT_MAX - 1; + +/*! + \class Frame + The class Frame is responsible for reading, validating and interpreting frames from a websocket. + It reads data from a QIODevice, validates it against RFC 6455, and parses it into a frame (data, control). + Whenever an error is detected, the isValid() returns false. + + \note The Frame class does not look at valid sequences of frames. It processes frames one at a time. + \note It is the DataProcessor that takes the sequence into account. + + \sa DataProcessor() + \internal + */ +class QWebSocketFrame +{ +public: + QWebSocketFrame(); + QWebSocketFrame(const QWebSocketFrame &other); + + const QWebSocketFrame &operator =(const QWebSocketFrame &other); + + QWebSocketProtocol::CloseCode getCloseCode() const; + QString getCloseReason() const; + bool isFinalFrame() const; + bool isControlFrame() const; + bool isDataFrame() const; + bool isContinuationFrame() const; + bool hasMask() const; + quint32 getMask() const; //returns 0 if no mask + int getRsv1() const; + int getRsv2() const; + int getRsv3() const; + QWebSocketProtocol::OpCode getOpCode() const; + QByteArray getPayload() const; + + void clear(); //resets all member variables, and invalidates the object + + bool isValid() const; + + static QWebSocketFrame readFrame(QIODevice *pIoDevice); + +private: + QWebSocketProtocol::CloseCode m_closeCode; + QString m_closeReason; + bool m_isFinalFrame; + quint32 m_mask; + int m_rsv1; //reserved field 1 + int m_rsv2; //reserved field 2 + int m_rsv3; //reserved field 3 + QWebSocketProtocol::OpCode m_opCode; + + quint8 m_length; //length field as read from the header; this is 1 byte, which when 126 or 127, indicates a large payload + QByteArray m_payload; + + bool m_isValid; + + enum ProcessingState + { + PS_READ_HEADER, + PS_READ_PAYLOAD_LENGTH, + PS_READ_BIG_PAYLOAD_LENGTH, + PS_READ_MASK, + PS_READ_PAYLOAD, + PS_DISPATCH_RESULT, + PS_WAIT_FOR_MORE_DATA + }; + + void setError(QWebSocketProtocol::CloseCode code, QString closeReason); + bool checkValidity(); +}; + +QT_END_NAMESPACE + +#endif // QWEBSOCKETFRAME_P_H |