There was no '?' between path and query. Bug detected by someone on the internet.
[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 QIODevice;
43 class Frame;
44
45 /*!
46     \internal
47     The DataProcessor class reads and interprets incoming websocket messages, and emits appropriate signals.
48  */
49 class DataProcessor: public QObject
50 {
51     Q_OBJECT
52 public:
53     explicit DataProcessor(QObject *parent = 0);
54     virtual ~DataProcessor();
55
56     static quint64 maxMessageSize();
57     static quint64 maxFrameSize();
58
59 Q_SIGNALS:
60     void pingReceived(QByteArray data);
61     void pongReceived(QByteArray data);
62     void closeReceived(QWebSocketProtocol::CloseCode closeCode, QString closeReason);
63     void textFrameReceived(QString frame, bool lastFrame);
64     void binaryFrameReceived(QByteArray frame, bool lastFrame);
65     void textMessageReceived(QString message);
66     void binaryMessageReceived(QByteArray message);
67     void errorEncountered(QWebSocketProtocol::CloseCode code, QString description);
68
69 public Q_SLOTS:
70     void process(QIODevice *pIoDevice);
71     void clear();
72
73 private:
74     Q_DISABLE_COPY(DataProcessor)
75     enum
76     {
77         PS_READ_HEADER,
78         PS_READ_PAYLOAD_LENGTH,
79         PS_READ_BIG_PAYLOAD_LENGTH,
80         PS_READ_MASK,
81         PS_READ_PAYLOAD,
82         PS_DISPATCH_RESULT
83     } m_processingState;
84
85     bool m_isFinalFrame;
86     bool m_isFragmented;
87     QWebSocketProtocol::OpCode m_opCode;
88     bool m_isControlFrame;
89     bool m_hasMask;
90     quint32 m_mask;
91     QByteArray m_binaryMessage;
92     QString m_textMessage;
93     quint64 m_payloadLength;
94     QTextCodec::ConverterState *m_pConverterState;
95     QTextCodec *m_pTextCodec;
96
97     bool processControlFrame(const Frame &frame);
98 };
99
100 QT_END_NAMESPACE
101
102 #endif // DATAPROCESSOR_P_H