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