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;
54
55class QNetworkProxyQueryPrivate;
56class Q_NETWORK_EXPORT QNetworkProxyQuery
57{
58 Q_GADGET
59
60public:
61 enum QueryType {
62 TcpSocket,
63 UdpSocket,
64 SctpSocket,
65 TcpServer = 100,
66 UrlRequest,
67 SctpServer
68 };
69 Q_ENUM(QueryType)
70
71 QNetworkProxyQuery();
72 explicit QNetworkProxyQuery(const QUrl &requestUrl, QueryType queryType = UrlRequest);
73 QNetworkProxyQuery(const QString &hostname, int port, const QString &protocolTag = QString(),
74 QueryType queryType = TcpSocket);
75 explicit QNetworkProxyQuery(quint16 bindPort, const QString &protocolTag = QString(),
76 QueryType queryType = TcpServer);
77 QNetworkProxyQuery(const QNetworkProxyQuery &other);
78 QNetworkProxyQuery &operator=(QNetworkProxyQuery &&other) noexcept { swap(other); return *this; }
79 QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other);
80 ~QNetworkProxyQuery();
81
82 void swap(QNetworkProxyQuery &other) noexcept { qSwap(d, other.d); }
83
84 bool operator==(const QNetworkProxyQuery &other) const;
85 inline bool operator!=(const QNetworkProxyQuery &other) const
86 { return !(*this == other); }
87
88 QueryType queryType() const;
89 void setQueryType(QueryType type);
90
91 int peerPort() const;
92 void setPeerPort(int port);
93
94 QString peerHostName() const;
95 void setPeerHostName(const QString &hostname);
96
97 int localPort() const;
98 void setLocalPort(int port);
99
100 QString protocolTag() const;
101 void setProtocolTag(const QString &protocolTag);
102
103 QUrl url() const;
104 void setUrl(const QUrl &url);
105
106private:
107 QSharedDataPointer<QNetworkProxyQueryPrivate> d;
108};
109
110Q_DECLARE_SHARED(QNetworkProxyQuery)
111
112class QNetworkProxyPrivate;
113
114class Q_NETWORK_EXPORT QNetworkProxy
115{
116public:
117 enum ProxyType {
118 DefaultProxy,
119 Socks5Proxy,
120 NoProxy,
121 HttpProxy,
122 HttpCachingProxy,
123 FtpCachingProxy
124 };
125
126 enum Capability {
127 TunnelingCapability = 0x0001,
128 ListeningCapability = 0x0002,
129 UdpTunnelingCapability = 0x0004,
130 CachingCapability = 0x0008,
131 HostNameLookupCapability = 0x0010,
132 SctpTunnelingCapability = 0x00020,
133 SctpListeningCapability = 0x00040
134 };
135 Q_DECLARE_FLAGS(Capabilities, Capability)
136
137 QNetworkProxy();
138 QNetworkProxy(ProxyType type, const QString &hostName = QString(), quint16 port = 0,
139 const QString &user = QString(), const QString &password = QString());
140 QNetworkProxy(const QNetworkProxy &other);
141 QNetworkProxy &operator=(QNetworkProxy &&other) noexcept { swap(other); return *this; }
142 QNetworkProxy &operator=(const QNetworkProxy &other);
143 ~QNetworkProxy();
144
145 void swap(QNetworkProxy &other) noexcept { qSwap(d, other.d); }
146
147 bool operator==(const QNetworkProxy &other) const;
148 inline bool operator!=(const QNetworkProxy &other) const
149 { return !(*this == other); }
150
151 void setType(QNetworkProxy::ProxyType type);
152 QNetworkProxy::ProxyType type() const;
153
154 void setCapabilities(Capabilities capab);
155 Capabilities capabilities() const;
156 bool isCachingProxy() const;
157 bool isTransparentProxy() const;
158
159 void setUser(const QString &userName);
160 QString user() const;
161
162 void setPassword(const QString &password);
163 QString password() const;
164
165 void setHostName(const QString &hostName);
166 QString hostName() const;
167
168 void setPort(quint16 port);
169 quint16 port() const;
170
171 static void setApplicationProxy(const QNetworkProxy &proxy);
172 static QNetworkProxy applicationProxy();
173
174 // "cooked" headers
175 QVariant header(QNetworkRequest::KnownHeaders header) const;
176 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
177
178 // raw headers:
179 bool hasRawHeader(const QByteArray &headerName) const;
180 QList<QByteArray> rawHeaderList() const;
181 QByteArray rawHeader(const QByteArray &headerName) const;
182 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
183
184private:
185 QSharedDataPointer<QNetworkProxyPrivate> d;
186};
187
188Q_DECLARE_SHARED(QNetworkProxy)
189Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkProxy::Capabilities)
190
191class Q_NETWORK_EXPORT QNetworkProxyFactory
192{
193public:
194 QNetworkProxyFactory();
195 virtual ~QNetworkProxyFactory();
196
197 virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) = 0;
198
199 static bool usesSystemConfiguration();
200 static void setUseSystemConfiguration(bool enable);
201 static void setApplicationProxyFactory(QNetworkProxyFactory *factory);
202 static QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query);
203 static QList<QNetworkProxy> systemProxyForQuery(const QNetworkProxyQuery &query = QNetworkProxyQuery());
204};
205
206#ifndef QT_NO_DEBUG_STREAM
207Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxy &proxy);
208Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxyQuery &proxyQuery);
209#endif
210
211QT_END_NAMESPACE
212
213Q_DECLARE_METATYPE(QNetworkProxy)
214
215#endif // QT_NO_NETWORKPROXY
216
217#endif // QHOSTINFO_H
218