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#ifdef Q_COMPILER_RVALUE_REFS
93 QNetworkProxyQuery &operator=(QNetworkProxyQuery &&other) Q_DECL_NOTHROW { swap(other); return *this; }
94#endif
95 QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other);
96 ~QNetworkProxyQuery();
97
98 void swap(QNetworkProxyQuery &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
99
100 bool operator==(const QNetworkProxyQuery &other) const;
101 inline bool operator!=(const QNetworkProxyQuery &other) const
102 { return !(*this == other); }
103
104 QueryType queryType() const;
105 void setQueryType(QueryType type);
106
107 int peerPort() const;
108 void setPeerPort(int port);
109
110 QString peerHostName() const;
111 void setPeerHostName(const QString &hostname);
112
113 int localPort() const;
114 void setLocalPort(int port);
115
116 QString protocolTag() const;
117 void setProtocolTag(const QString &protocolTag);
118
119 QUrl url() const;
120 void setUrl(const QUrl &url);
121
122#if !defined(QT_NO_BEARERMANAGEMENT) && QT_DEPRECATED_SINCE(5, 10)
123 Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
124 QNetworkConfiguration networkConfiguration() const;
125 Q_DECL_DEPRECATED_X("QNetworkConfiguration support in QNetworkProxy is deprecated")
126 void setNetworkConfiguration(const QNetworkConfiguration &networkConfiguration);
127#endif
128
129private:
130 QSharedDataPointer<QNetworkProxyQueryPrivate> d;
131};
132
133Q_DECLARE_SHARED(QNetworkProxyQuery)
134
135class QNetworkProxyPrivate;
136
137class Q_NETWORK_EXPORT QNetworkProxy
138{
139public:
140 enum ProxyType {
141 DefaultProxy,
142 Socks5Proxy,
143 NoProxy,
144 HttpProxy,
145 HttpCachingProxy,
146 FtpCachingProxy
147 };
148
149 enum Capability {
150 TunnelingCapability = 0x0001,
151 ListeningCapability = 0x0002,
152 UdpTunnelingCapability = 0x0004,
153 CachingCapability = 0x0008,
154 HostNameLookupCapability = 0x0010,
155 SctpTunnelingCapability = 0x00020,
156 SctpListeningCapability = 0x00040
157 };
158 Q_DECLARE_FLAGS(Capabilities, Capability)
159
160 QNetworkProxy();
161 QNetworkProxy(ProxyType type, const QString &hostName = QString(), quint16 port = 0,
162 const QString &user = QString(), const QString &password = QString());
163 QNetworkProxy(const QNetworkProxy &other);
164#ifdef Q_COMPILER_RVALUE_REFS
165 QNetworkProxy &operator=(QNetworkProxy &&other) Q_DECL_NOTHROW { swap(other); return *this; }
166#endif
167 QNetworkProxy &operator=(const QNetworkProxy &other);
168 ~QNetworkProxy();
169
170 void swap(QNetworkProxy &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
171
172 bool operator==(const QNetworkProxy &other) const;
173 inline bool operator!=(const QNetworkProxy &other) const
174 { return !(*this == other); }
175
176 void setType(QNetworkProxy::ProxyType type);
177 QNetworkProxy::ProxyType type() const;
178
179 void setCapabilities(Capabilities capab);
180 Capabilities capabilities() const;
181 bool isCachingProxy() const;
182 bool isTransparentProxy() const;
183
184 void setUser(const QString &userName);
185 QString user() const;
186
187 void setPassword(const QString &password);
188 QString password() const;
189
190 void setHostName(const QString &hostName);
191 QString hostName() const;
192
193 void setPort(quint16 port);
194 quint16 port() const;
195
196 static void setApplicationProxy(const QNetworkProxy &proxy);
197 static QNetworkProxy applicationProxy();
198
199 // "cooked" headers
200 QVariant header(QNetworkRequest::KnownHeaders header) const;
201 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
202
203 // raw headers:
204 bool hasRawHeader(const QByteArray &headerName) const;
205 QList<QByteArray> rawHeaderList() const;
206 QByteArray rawHeader(const QByteArray &headerName) const;
207 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
208
209private:
210 QSharedDataPointer<QNetworkProxyPrivate> d;
211};
212
213Q_DECLARE_SHARED(QNetworkProxy)
214Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkProxy::Capabilities)
215
216class Q_NETWORK_EXPORT QNetworkProxyFactory
217{
218public:
219 QNetworkProxyFactory();
220 virtual ~QNetworkProxyFactory();
221
222 virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) = 0;
223
224 static bool usesSystemConfiguration();
225 static void setUseSystemConfiguration(bool enable);
226 static void setApplicationProxyFactory(QNetworkProxyFactory *factory);
227 static QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query);
228 static QList<QNetworkProxy> systemProxyForQuery(const QNetworkProxyQuery &query = QNetworkProxyQuery());
229};
230
231#ifndef QT_NO_DEBUG_STREAM
232Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxy &proxy);
233Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxyQuery &proxyQuery);
234#endif
235
236QT_END_NAMESPACE
237
238Q_DECLARE_METATYPE(QNetworkProxy)
239
240#endif // QT_NO_NETWORKPROXY
241
242#endif // QHOSTINFO_H
243