| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Network Auth module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:GPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU |
| 19 | ** General Public License version 3 or (at your option) any later version |
| 20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
| 21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
| 22 | ** included in the packaging of this file. Please review the following |
| 23 | ** information to ensure the GNU General Public License requirements will |
| 24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
| 25 | ** |
| 26 | ** $QT_END_LICENSE$ |
| 27 | ** |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | // |
| 31 | // W A R N I N G |
| 32 | // ------------- |
| 33 | // |
| 34 | // This file is not part of the Qt API. It exists for the convenience |
| 35 | // of the Network Access API. This header file may change from |
| 36 | // version to version without notice, or even be removed. |
| 37 | // |
| 38 | // We mean it. |
| 39 | // |
| 40 | |
| 41 | #ifndef QOAUTHHTTPSERVERREPLYHANDLER_P_H |
| 42 | #define QOAUTHHTTPSERVERREPLYHANDLER_P_H |
| 43 | |
| 44 | #ifndef QT_NO_HTTP |
| 45 | |
| 46 | #include <QtNetworkAuth/qoauthglobal.h> |
| 47 | #include <QtNetworkAuth/qoauthhttpserverreplyhandler.h> |
| 48 | |
| 49 | #include <private/qobject_p.h> |
| 50 | |
| 51 | #include <QtNetwork/qtcpserver.h> |
| 52 | |
| 53 | QT_BEGIN_NAMESPACE |
| 54 | |
| 55 | class QOAuthHttpServerReplyHandlerPrivate |
| 56 | { |
| 57 | Q_DECLARE_PUBLIC(QOAuthHttpServerReplyHandler) |
| 58 | |
| 59 | public: |
| 60 | explicit QOAuthHttpServerReplyHandlerPrivate(QOAuthHttpServerReplyHandler *p); |
| 61 | ~QOAuthHttpServerReplyHandlerPrivate(); |
| 62 | |
| 63 | QTcpServer httpServer; |
| 64 | QString text; |
| 65 | QHostAddress listenAddress = QHostAddress::LocalHost; |
| 66 | QString path; |
| 67 | |
| 68 | private: |
| 69 | void _q_clientConnected(); |
| 70 | void _q_readData(QTcpSocket *socket); |
| 71 | void _q_answerClient(QTcpSocket *socket, const QUrl &url); |
| 72 | |
| 73 | struct QHttpRequest { |
| 74 | quint16 port = 0; |
| 75 | |
| 76 | bool readMethod(QTcpSocket *socket); |
| 77 | bool readUrl(QTcpSocket *socket); |
| 78 | bool readStatus(QTcpSocket *socket); |
| 79 | bool readHeader(QTcpSocket *socket); |
| 80 | |
| 81 | enum class State { |
| 82 | ReadingMethod, |
| 83 | ReadingUrl, |
| 84 | ReadingStatus, |
| 85 | ReadingHeader, |
| 86 | ReadingBody, |
| 87 | AllDone |
| 88 | } state = State::ReadingMethod; |
| 89 | QByteArray fragment; |
| 90 | |
| 91 | enum class Method { |
| 92 | Unknown, |
| 93 | Head, |
| 94 | Get, |
| 95 | Put, |
| 96 | Post, |
| 97 | Delete, |
| 98 | } method = Method::Unknown; |
| 99 | QUrl url; |
| 100 | QPair<quint8, quint8> version; |
| 101 | QMap<QByteArray, QByteArray> headers; |
| 102 | }; |
| 103 | |
| 104 | QMap<QTcpSocket *, QHttpRequest> clients; |
| 105 | |
| 106 | QOAuthHttpServerReplyHandler *q_ptr; |
| 107 | }; |
| 108 | |
| 109 | QT_END_NAMESPACE |
| 110 | |
| 111 | #endif // QT_NO_HTTP |
| 112 | |
| 113 | #endif // QOAUTHHTTPSERVERREPLYHANDLER_P_H |
| 114 | |