Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhttpsocketengine_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QHTTPSOCKETENGINE_P_H
6#define QHTTPSOCKETENGINE_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20
21#include <QtNetwork/qnetworkproxy.h>
22
24#include "private/qauthenticator_p.h"
25#include "private/qabstractsocketengine_p.h"
26
27QT_REQUIRE_CONFIG(http);
28
29QT_BEGIN_NAMESPACE
30
31#if !defined(QT_NO_NETWORKPROXY)
32
33class QTcpSocket;
34class QHttpNetworkReply;
36
37class Q_AUTOTEST_EXPORT QHttpSocketEngine : public QAbstractSocketEngine
38{
39 Q_OBJECT
40public:
41 enum HttpState {
42 None,
43 ConnectSent,
44 Connected,
45 SendAuthentication,
46 ReadResponseContent,
47 ReadResponseHeader
48 };
49 QHttpSocketEngine(QObject *parent = nullptr);
50 ~QHttpSocketEngine();
51
52 bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol = QAbstractSocket::IPv4Protocol) override;
53 bool initialize(qintptr socketDescriptor, QAbstractSocket::SocketState socketState = QAbstractSocket::ConnectedState) override;
54
55 void setProxy(const QNetworkProxy &networkProxy);
56
57 qintptr socketDescriptor() const override;
58
59 bool isValid() const override;
60
61 bool connectInternal();
62 bool connectToHost(const QHostAddress &address, quint16 port) override;
63 bool connectToHostByName(const QString &name, quint16 port) override;
64 bool bind(const QHostAddress &address, quint16 port) override;
65 bool listen(int backlog) override;
66 qintptr accept() override;
67 void close() override;
68
69 qint64 bytesAvailable() const override;
70
71 qint64 read(char *data, qint64 maxlen) override;
72 qint64 write(const char *data, qint64 len) override;
73
74#ifndef QT_NO_UDPSOCKET
75#ifndef QT_NO_NETWORKINTERFACE
76 bool joinMulticastGroup(const QHostAddress &groupAddress,
77 const QNetworkInterface &iface) override;
78 bool leaveMulticastGroup(const QHostAddress &groupAddress,
79 const QNetworkInterface &iface) override;
80 QNetworkInterface multicastInterface() const override;
81 bool setMulticastInterface(const QNetworkInterface &iface) override;
82#endif // QT_NO_NETWORKINTERFACE
83
84 bool hasPendingDatagrams() const override;
85 qint64 pendingDatagramSize() const override;
86#endif // QT_NO_UDPSOCKET
87
88 qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader *,
89 PacketHeaderOptions) override;
90 qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &) override;
91 qint64 bytesToWrite() const override;
92
93 int option(SocketOption option) const override;
94 bool setOption(SocketOption option, int value) override;
95
96 bool waitForRead(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
97 bool *timedOut = nullptr) override;
98 bool waitForWrite(QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
99 bool *timedOut = nullptr) override;
100 bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
101 bool checkRead, bool checkWrite,
102 QDeadlineTimer deadline = QDeadlineTimer{DefaultTimeout},
103 bool *timedOut = nullptr) override;
104
105 void waitForProtocolHandshake(QDeadlineTimer deadline) const;
106
107 bool isReadNotificationEnabled() const override;
108 void setReadNotificationEnabled(bool enable) override;
109 bool isWriteNotificationEnabled() const override;
110 void setWriteNotificationEnabled(bool enable) override;
111 bool isExceptionNotificationEnabled() const override;
112 void setExceptionNotificationEnabled(bool enable) override;
113
114public slots:
115 void slotSocketConnected();
116 void slotSocketDisconnected();
117 void slotSocketReadNotification();
118 void slotSocketBytesWritten();
119 void slotSocketError(QAbstractSocket::SocketError error);
120 void slotSocketStateChanged(QAbstractSocket::SocketState state);
121
122private slots:
123 void emitPendingReadNotification();
124 void emitPendingWriteNotification();
125 void emitPendingConnectionNotification();
126
127private:
128 void emitReadNotification();
129 void emitWriteNotification();
130 void emitConnectionNotification();
131
132 bool readHttpHeader();
133
134 Q_DECLARE_PRIVATE(QHttpSocketEngine)
135 Q_DISABLE_COPY_MOVE(QHttpSocketEngine)
136
137};
138
139
162
163class Q_AUTOTEST_EXPORT QHttpSocketEngineHandler : public QSocketEngineHandler
164{
165public:
166 virtual QAbstractSocketEngine *createSocketEngine(QAbstractSocket::SocketType socketType,
167 const QNetworkProxy &, QObject *parent) override;
168 virtual QAbstractSocketEngine *createSocketEngine(qintptr socketDescripter, QObject *parent) override;
169};
170#endif
171
172QT_END_NAMESPACE
173
174#endif // QHTTPSOCKETENGINE_H