1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
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 Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QNETWORKPROXY_H
41#define QNETWORKPROXY_H
42
43#include <QtNetwork/qtnetworkglobal.h>
44#include <QtNetwork/qhostaddress.h>
45#include <QtNetwork/qnetworkrequest.h>
46#include <QtCore/qshareddata.h>
47
48#ifndef QT_NO_NETWORKPROXY
49
50QT_BEGIN_NAMESPACE
51
52
53class QUrl;
54class QNetworkConfiguration;
55
56class QNetworkProxyQueryPrivate;
57class Q_NETWORK_EXPORT QNetworkProxyQuery
58{
59 Q_GADGET
60
61public:
62 enum QueryType {
63 TcpSocket,
64 UdpSocket,
65 SctpSocket,
66 TcpServer = 100,
67 UrlRequest,
68 SctpServer
69 };
70 Q_ENUM(QueryType)
71
72 QNetworkProxyQuery();
73 explicit QNetworkProxyQuery(const QUrl &requestUrl, QueryType queryType = UrlRequest);
74 QNetworkProxyQuery(const QString &hostname, int port, const QString &protocolTag = QString(),
75 QueryType queryType = TcpSocket);
76 explicit QNetworkProxyQuery(quint16 bindPort, const QString &protocolTag = QString(),
77 QueryType queryType = TcpServer);
78#if !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
79 Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
80 QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
81 const QUrl &requestUrl, QueryType queryType = UrlRequest);
82 Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
83 QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
84 const QString &hostname, int port, const QString &protocolTag = QString(),
85 QueryType queryType = TcpSocket);
86 Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
87 QNetworkProxyQuery(const QNetworkConfiguration &networkConfiguration,
88 quint16 bindPort, const QString &protocolTag = QString(),
89 QueryType queryType = TcpServer);
90#endif
91 QNetworkProxyQuery(const QNetworkProxyQuery &other);
92 QNetworkProxyQuery &operator=(QNetworkProxyQuery &&other) noexcept { swap(other); return *this; }
93 QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other);
94 ~QNetworkProxyQuery();
95
96 void swap(QNetworkProxyQuery &other) noexcept { qSwap(d, other.d); }
97
98 bool operator==(const QNetworkProxyQuery &other) const;
99 inline bool operator!=(const QNetworkProxyQuery &other) const
100 { return !(*this == other); }
101
102 QueryType queryType() const;
103 void setQueryType(QueryType type);
104
105 int peerPort() const;
106 void setPeerPort(int port);
107
108 QString peerHostName() const;
109 void setPeerHostName(const QString &hostname);
110
111 int localPort() const;
112 void setLocalPort(int port);
113
114 QString protocolTag() const;
115 void setProtocolTag(const QString &protocolTag);
116
117 QUrl url() const;
118 void setUrl(const QUrl &url);
119
120#if !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
121 Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
122 QNetworkConfiguration networkConfiguration() const;
123 Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
124 void setNetworkConfiguration(const QNetworkConfiguration &networkConfiguration);
125#endif
126
127private:
128 QSharedDataPointer<QNetworkProxyQueryPrivate> d;
129};
130
131Q_DECLARE_SHARED(QNetworkProxyQuery)
132
133class QNetworkProxyPrivate;
134
135class Q_NETWORK_EXPORT QNetworkProxy
136{
137public:
138 enum ProxyType {
139 DefaultProxy,
140 Socks5Proxy,
141 NoProxy,
142 HttpProxy,
143 HttpCachingProxy,
144 FtpCachingProxy
145 };
146
147 enum Capability {
148 TunnelingCapability = 0x0001,
149 ListeningCapability = 0x0002,
150 UdpTunnelingCapability = 0x0004,
151 CachingCapability = 0x0008,
152 HostNameLookupCapability = 0x0010,
153 SctpTunnelingCapability = 0x00020,
154 SctpListeningCapability = 0x00040
155 };
156 Q_DECLARE_FLAGS(Capabilities, Capability)
157
158 QNetworkProxy();
159 QNetworkProxy(ProxyType type, const QString &hostName = QString(), quint16 port = 0,
160 const QString &user = QString(), const QString &password = QString());
161 QNetworkProxy(const QNetworkProxy &other);
162 QNetworkProxy &operator=(QNetworkProxy &&other) noexcept { swap(other); return *this; }
163 QNetworkProxy &operator=(const QNetworkProxy &other);
164 ~QNetworkProxy();
165
166 void swap(QNetworkProxy &other) noexcept { qSwap(d, other.d); }
167
168 bool operator==(const QNetworkProxy &other) const;
169 inline bool operator!=(const QNetworkProxy &other) const
170 { return !(*this == other); }
171
172 void setType(QNetworkProxy::ProxyType type);
173 QNetworkProxy::ProxyType type() const;
174
175 void setCapabilities(Capabilities capab);
176 Capabilities capabilities() const;
177 bool isCachingProxy() const;
178 bool isTransparentProxy() const;
179
180 void setUser(const QString &userName);
181 QString user() const;
182
183 void setPassword(const QString &password);
184 QString password() const;
185
186 void setHostName(const QString &hostName);
187 QString hostName() const;
188
189 void setPort(quint16 port);
190 quint16 port() const;
191
192 static void setApplicationProxy(const QNetworkProxy &proxy);
193 static QNetworkProxy applicationProxy();
194
195 // "cooked" headers
196 QVariant header(QNetworkRequest::KnownHeaders header) const;
197 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
198
199 // raw headers:
200 bool hasRawHeader(const QByteArray &headerName) const;
201 QList<QByteArray> rawHeaderList() const;
202 QByteArray rawHeader(const QByteArray &headerName) const;
203 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
204
205private:
206 QSharedDataPointer<QNetworkProxyPrivate> d;
207};
208
209Q_DECLARE_SHARED(QNetworkProxy)
210Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkProxy::Capabilities)
211
212class Q_NETWORK_EXPORT QNetworkProxyFactory
213{
214public:
215 QNetworkProxyFactory();
216 virtual ~QNetworkProxyFactory();
217
218 virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) = 0;
219
220 static bool usesSystemConfiguration();
221 static void setUseSystemConfiguration(bool enable);
222 static void setApplicationProxyFactory(QNetworkProxyFactory *factory);
223 static QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query);
224 static QList<QNetworkProxy> systemProxyForQuery(const QNetworkProxyQuery &query = QNetworkProxyQuery());
225};
226
227#ifndef QT_NO_DEBUG_STREAM
228Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxy &proxy);
229Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxyQuery &proxyQuery);
230#endif
231
232QT_END_NAMESPACE
233
234Q_DECLARE_METATYPE(QNetworkProxy)
235
236#endif // QT_NO_NETWORKPROXY
237
238#endif // QHOSTINFO_H
239