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#ifndef QT_NO_HTTP
19
20#include <QtNetworkAuth/qoauthglobal.h>
21#include <QtNetworkAuth/qoauthhttpserverreplyhandler.h>
22
23#include <private/qobject_p.h>
24
25#include <QtNetwork/qtcpserver.h>
26
27QT_BEGIN_NAMESPACE
28
29class QOAuthHttpServerReplyHandlerPrivate
30{
31 Q_DECLARE_PUBLIC(QOAuthHttpServerReplyHandler)
32
33public:
34 explicit QOAuthHttpServerReplyHandlerPrivate(QOAuthHttpServerReplyHandler *p);
35 ~QOAuthHttpServerReplyHandlerPrivate();
36
37 QTcpServer httpServer;
38 QString text;
39 QHostAddress listenAddress = QHostAddress::LocalHost;
40 QString path;
41
42private:
43 void _q_clientConnected();
44 void _q_readData(QTcpSocket *socket);
45 void _q_answerClient(QTcpSocket *socket, const QUrl &url);
46
47 struct QHttpRequest {
48 quint16 port = 0;
49
50 bool readMethod(QTcpSocket *socket);
51 bool readUrl(QTcpSocket *socket);
52 bool readStatus(QTcpSocket *socket);
53 bool readHeader(QTcpSocket *socket);
54
55 enum class State {
56 ReadingMethod,
57 ReadingUrl,
58 ReadingStatus,
59 ReadingHeader,
60 ReadingBody,
61 AllDone
62 } state = State::ReadingMethod;
63 QByteArray fragment;
64
65 enum class Method {
66 Unknown,
67 Head,
68 Get,
69 Put,
70 Post,
71 Delete,
72 } method = Method::Unknown;
73 QUrl url;
74 QPair<quint8, quint8> version;
75 QMap<QByteArray, QByteArray> headers;
76 };
77
78 QMap<QTcpSocket *, QHttpRequest> clients;
79
80 QOAuthHttpServerReplyHandler *q_ptr;
81};
82
83QT_END_NAMESPACE
84
85#endif // QT_NO_HTTP
86
87#endif // QOAUTHHTTPSERVERREPLYHANDLER_P_H
88

source code of qtnetworkauth/src/oauth/qoauthhttpserverreplyhandler_p.h