1 | // Copyright (C) 2017 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | // |
5 | // W A R N I N G |
6 | // ------------- |
7 | // |
8 | // This file is not part of the Qt API. It exists for the convenience |
9 | // of the Network Access API. This header file may change from |
10 | // version to version without notice, or even be removed. |
11 | // |
12 | // We mean it. |
13 | // |
14 | |
15 | #ifndef QOAUTHHTTPSERVERREPLYHANDLER_P_H |
16 | #define QOAUTHHTTPSERVERREPLYHANDLER_P_H |
17 | |
18 | #include <QtNetworkAuth/qoauthglobal.h> |
19 | #include <QtNetworkAuth/qoauthhttpserverreplyhandler.h> |
20 | |
21 | #include <private/qobject_p.h> |
22 | |
23 | #include <QtNetwork/qhostaddress.h> |
24 | #include <QtNetwork/qtcpserver.h> |
25 | |
26 | #include <utility> |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QOAuthHttpServerReplyHandlerPrivate |
31 | { |
32 | Q_DECLARE_PUBLIC(QOAuthHttpServerReplyHandler) |
33 | |
34 | public: |
35 | explicit QOAuthHttpServerReplyHandlerPrivate(QOAuthHttpServerReplyHandler *p); |
36 | ~QOAuthHttpServerReplyHandlerPrivate(); |
37 | |
38 | QString callback() const; |
39 | QString callbackHost() const; |
40 | |
41 | QTcpServer httpServer; |
42 | QString text; |
43 | QString path; |
44 | QHostAddress callbackAddress; |
45 | quint16 callbackPort = 0; |
46 | |
47 | private: |
48 | void _q_clientConnected(); |
49 | void _q_readData(QTcpSocket *socket); |
50 | void _q_answerClient(QTcpSocket *socket, const QUrl &url); |
51 | |
52 | struct QHttpRequest { |
53 | quint16 port = 0; |
54 | |
55 | bool readMethod(QTcpSocket *socket); |
56 | bool readUrl(QTcpSocket *socket); |
57 | bool readStatus(QTcpSocket *socket); |
58 | bool readHeader(QTcpSocket *socket); |
59 | |
60 | enum class State { |
61 | ReadingMethod, |
62 | ReadingUrl, |
63 | ReadingStatus, |
64 | ReadingHeader, |
65 | ReadingBody, |
66 | AllDone |
67 | } state = State::ReadingMethod; |
68 | QByteArray fragment; |
69 | |
70 | enum class Method { |
71 | Unknown, |
72 | Head, |
73 | Get, |
74 | Put, |
75 | Post, |
76 | Delete, |
77 | } method = Method::Unknown; |
78 | QUrl url; |
79 | std::pair<quint8, quint8> version; |
80 | QMap<QByteArray, QByteArray> headers; |
81 | }; |
82 | |
83 | QMap<QTcpSocket *, QHttpRequest> clients; |
84 | |
85 | QOAuthHttpServerReplyHandler *q_ptr; |
86 | }; |
87 | |
88 | QT_END_NAMESPACE |
89 | |
90 | #endif // QOAUTHHTTPSERVERREPLYHANDLER_P_H |
91 |