Renamed qwebsocket.pri to qwebsockets.pri
[contrib/qtwebsockets.git] / src / dataprocessor_p.h
1 /*
2 QWebSockets implements the WebSocket protocol as defined in RFC 6455.
3 Copyright (C) 2013 Kurt Pattyn (pattyn.kurt@gmail.com)
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20 #ifndef DATAPROCESSOR_P_H
21 #define DATAPROCESSOR_P_H
22
23 //
24 //  W A R N I N G
25 //  -------------
26 //
27 // This file is not part of the Qt API.  It exists purely as an
28 // implementation detail.  This header file may change from version to
29 // version without notice, or even be removed.
30 //
31 // We mean it.
32 //
33
34 #include <QObject>
35 #include <QByteArray>
36 #include <QString>
37 #include <QTextCodec>
38 #include "qwebsocketprotocol.h"
39
40 QT_BEGIN_NAMESPACE
41
42 class QTcpSocket;
43
44 /**
45  * @internal
46  * @brief The DataProcessor class
47  */
48 class DataProcessor: public QObject
49 {
50         Q_OBJECT
51 public:
52         explicit DataProcessor(QObject *parent = 0);
53         virtual ~DataProcessor();
54
55 Q_SIGNALS:
56         void controlFrameReceived(QWebSocketProtocol::OpCode opCode, QByteArray frame);
57         void textFrameReceived(QString frame, bool lastFrame);
58         void binaryFrameReceived(QByteArray frame, bool lastFrame);
59         void textMessageReceived(QString message);
60         void binaryMessageReceived(QByteArray message);
61         void errorEncountered(QWebSocketProtocol::CloseCode code, QString description);
62
63 public Q_SLOTS:
64         void process(QTcpSocket *pSocket);
65         void clear();
66
67 private:
68         Q_DISABLE_COPY(DataProcessor)
69         enum
70         {
71                 PS_READ_HEADER,
72                 PS_READ_PAYLOAD_LENGTH,
73                 PS_READ_BIG_PAYLOAD_LENGTH,
74                 PS_READ_MASK,
75                 PS_READ_PAYLOAD,
76                 PS_DISPATCH_RESULT
77         } m_processingState;
78
79         bool m_isFinalFrame;
80         bool m_isFragmented;
81         QWebSocketProtocol::OpCode m_opCode;
82         bool m_isControlFrame;
83         bool m_hasMask;
84         quint32 m_mask;
85         QByteArray m_binaryMessage;
86         QString m_textMessage;
87         quint64 m_payloadLength;
88         QTextCodec::ConverterState *m_pConverterState;
89         QTextCodec *m_pTextCodec;
90 };
91
92 QT_END_NAMESPACE
93
94 #endif // DATAPROCESSOR_P_H