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
4#ifndef QNETWORKPROXY_H
5#define QNETWORKPROXY_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtNetwork/qhostaddress.h>
9#include <QtNetwork/qnetworkrequest.h>
10#include <QtCore/qshareddata.h>
11
12#ifndef QT_NO_NETWORKPROXY
13
14QT_BEGIN_NAMESPACE
15
16
17class QUrl;
18
19class QNetworkProxyQueryPrivate;
20class Q_NETWORK_EXPORT QNetworkProxyQuery
21{
22 Q_GADGET
23
24public:
25 enum QueryType {
26 TcpSocket,
27 UdpSocket,
28 SctpSocket,
29 TcpServer = 100,
30 UrlRequest,
31 SctpServer
32 };
33 Q_ENUM(QueryType)
34
35 QNetworkProxyQuery();
36 explicit QNetworkProxyQuery(const QUrl &requestUrl, QueryType queryType = UrlRequest);
37 QNetworkProxyQuery(const QString &hostname, int port, const QString &protocolTag = QString(),
38 QueryType queryType = TcpSocket);
39 explicit QNetworkProxyQuery(quint16 bindPort, const QString &protocolTag = QString(),
40 QueryType queryType = TcpServer);
41 QNetworkProxyQuery(const QNetworkProxyQuery &other);
42 QNetworkProxyQuery &operator=(QNetworkProxyQuery &&other) noexcept { swap(other); return *this; }
43 QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other);
44 ~QNetworkProxyQuery();
45
46 void swap(QNetworkProxyQuery &other) noexcept { d.swap(other&: other.d); }
47
48 bool operator==(const QNetworkProxyQuery &other) const;
49 inline bool operator!=(const QNetworkProxyQuery &other) const
50 { return !(*this == other); }
51
52 QueryType queryType() const;
53 void setQueryType(QueryType type);
54
55 int peerPort() const;
56 void setPeerPort(int port);
57
58 QString peerHostName() const;
59 void setPeerHostName(const QString &hostname);
60
61 int localPort() const;
62 void setLocalPort(int port);
63
64 QString protocolTag() const;
65 void setProtocolTag(const QString &protocolTag);
66
67 QUrl url() const;
68 void setUrl(const QUrl &url);
69
70private:
71 QSharedDataPointer<QNetworkProxyQueryPrivate> d;
72};
73
74Q_DECLARE_SHARED(QNetworkProxyQuery)
75
76class QNetworkProxyPrivate;
77
78class Q_NETWORK_EXPORT QNetworkProxy
79{
80public:
81 enum ProxyType {
82 DefaultProxy,
83 Socks5Proxy,
84 NoProxy,
85 HttpProxy,
86 HttpCachingProxy,
87 FtpCachingProxy
88 };
89
90 enum Capability {
91 TunnelingCapability = 0x0001,
92 ListeningCapability = 0x0002,
93 UdpTunnelingCapability = 0x0004,
94 CachingCapability = 0x0008,
95 HostNameLookupCapability = 0x0010,
96 SctpTunnelingCapability = 0x00020,
97 SctpListeningCapability = 0x00040
98 };
99 Q_DECLARE_FLAGS(Capabilities, Capability)
100
101 QNetworkProxy();
102 QNetworkProxy(ProxyType type, const QString &hostName = QString(), quint16 port = 0,
103 const QString &user = QString(), const QString &password = QString());
104 QNetworkProxy(const QNetworkProxy &other);
105 QNetworkProxy &operator=(QNetworkProxy &&other) noexcept { swap(other); return *this; }
106 QNetworkProxy &operator=(const QNetworkProxy &other);
107 ~QNetworkProxy();
108
109 void swap(QNetworkProxy &other) noexcept { d.swap(other&: other.d); }
110
111 bool operator==(const QNetworkProxy &other) const;
112 inline bool operator!=(const QNetworkProxy &other) const
113 { return !(*this == other); }
114
115 void setType(QNetworkProxy::ProxyType type);
116 QNetworkProxy::ProxyType type() const;
117
118 void setCapabilities(Capabilities capab);
119 Capabilities capabilities() const;
120 bool isCachingProxy() const;
121 bool isTransparentProxy() const;
122
123 void setUser(const QString &userName);
124 QString user() const;
125
126 void setPassword(const QString &password);
127 QString password() const;
128
129 void setHostName(const QString &hostName);
130 QString hostName() const;
131
132 void setPort(quint16 port);
133 quint16 port() const;
134
135 static void setApplicationProxy(const QNetworkProxy &proxy);
136 static QNetworkProxy applicationProxy();
137
138 // "cooked" headers
139 QVariant header(QNetworkRequest::KnownHeaders header) const;
140 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
141
142 // raw headers:
143 bool hasRawHeader(const QByteArray &headerName) const;
144 QList<QByteArray> rawHeaderList() const;
145 QByteArray rawHeader(const QByteArray &headerName) const;
146 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
147
148private:
149 QSharedDataPointer<QNetworkProxyPrivate> d;
150};
151
152Q_DECLARE_SHARED(QNetworkProxy)
153Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkProxy::Capabilities)
154
155class Q_NETWORK_EXPORT QNetworkProxyFactory
156{
157public:
158 QNetworkProxyFactory();
159 virtual ~QNetworkProxyFactory();
160
161 virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) = 0;
162
163 static bool usesSystemConfiguration();
164 static void setUseSystemConfiguration(bool enable);
165 static void setApplicationProxyFactory(QNetworkProxyFactory *factory);
166 static QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query);
167 static QList<QNetworkProxy> systemProxyForQuery(const QNetworkProxyQuery &query = QNetworkProxyQuery());
168};
169
170#ifndef QT_NO_DEBUG_STREAM
171Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxy &proxy);
172Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxyQuery &proxyQuery);
173#endif
174
175QT_END_NAMESPACE
176
177QT_DECL_METATYPE_EXTERN(QNetworkProxy, Q_NETWORK_EXPORT)
178
179#endif // QT_NO_NETWORKPROXY
180
181#endif // QHOSTINFO_H
182

source code of qtbase/src/network/kernel/qnetworkproxy.h