qnetworkproxy.h 7.7 KB

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