whitesapce updates
[contrib/qtwebsockets.git] / src / websockets / qwebsockethandshakeresponse_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 QWEBSOCKETHANDSHAKERESPONSE_P_H
21 #define QWEBSOCKETHANDSHAKERESPONSE_P_H
22 //
23 //  W A R N I N G
24 //  -------------
25 //
26 // This file is not part of the Qt API.  It exists purely as an
27 // implementation detail.  This header file may change from version to
28 // version without notice, or even be removed.
29 //
30 // We mean it.
31 //
32
33 #include <QObject>
34 #include "qwebsocketprotocol.h"
35
36 QT_BEGIN_NAMESPACE
37
38 class QWebSocketHandshakeRequest;
39 class QString;
40 class QTextStream;
41
42 class QWebSocketHandshakeResponse : public QObject
43 {
44     Q_OBJECT
45     Q_DISABLE_COPY(QWebSocketHandshakeResponse)
46
47 public:
48     QWebSocketHandshakeResponse(const QWebSocketHandshakeRequest &request,
49                       const QString &serverName,
50                       bool isOriginAllowed,
51                       const QList<QWebSocketProtocol::Version> &supportedVersions,
52                       const QList<QString> &supportedProtocols,
53                       const QList<QString> &supportedExtensions);
54
55     virtual ~QWebSocketHandshakeResponse();
56
57     bool isValid() const;
58     bool canUpgrade() const;
59     QString getAcceptedProtocol() const;
60     QString getAcceptedExtension() const;
61     QWebSocketProtocol::Version getAcceptedVersion() const;
62
63 public Q_SLOTS:
64
65 Q_SIGNALS:
66
67 private:
68     bool m_isValid;
69     bool m_canUpgrade;
70     QString m_response;
71     QString m_acceptedProtocol;
72     QString m_acceptedExtension;
73     QWebSocketProtocol::Version m_acceptedVersion;
74
75     QString calculateAcceptKey(const QString &key) const;
76     QString getHandshakeResponse(const QWebSocketHandshakeRequest &request,
77                                  const QString &serverName,
78                                  bool isOriginAllowed,
79                                  const QList<QWebSocketProtocol::Version> &supportedVersions,
80                                  const QList<QString> &supportedProtocols,
81                                  const QList<QString> &supportedExtensions);
82
83     QTextStream &writeToStream(QTextStream &textStream) const;
84     friend QTextStream &operator <<(QTextStream &stream, const QWebSocketHandshakeResponse &response);
85 };
86
87 QT_END_NAMESPACE
88
89 #endif // QWEBSOCKETHANDSHAKERESPONSE_P_H