| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QNETWORKPROXY_H |
| 5 | #define QNETWORKPROXY_H |
| 6 | |
| 7 | #include <QtNetwork/qtnetworkglobal.h> |
| 8 | #include <QtNetwork/qhostaddress.h> |
| 9 | #include <QtNetwork/qnetworkrequest.h> |
| 10 | #include <QtCore/qshareddata.h> |
| 11 | |
| 12 | #ifndef QT_NO_NETWORKPROXY |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | |
| 17 | class QUrl; |
| 18 | |
| 19 | class QNetworkProxyQueryPrivate; |
| 20 | class Q_NETWORK_EXPORT QNetworkProxyQuery |
| 21 | { |
| 22 | Q_GADGET |
| 23 | |
| 24 | public: |
| 25 | enum QueryType { |
| 26 | TcpSocket, |
| 27 | UdpSocket, |
| 28 | SctpSocket, |
| 29 | TcpServer = 100, |
| 30 | UrlRequest, |
| 31 | SctpServer |
| 32 | }; |
| 33 | Q_ENUM(QueryType) |
| 34 | |
| 35 | QNetworkProxyQuery(); |
| 36 | explicit QNetworkProxyQuery(const QUrl &requestUrl, QueryType queryType = UrlRequest); |
| 37 | QNetworkProxyQuery(const QString &hostname, int port, const QString &protocolTag = QString(), |
| 38 | QueryType queryType = TcpSocket); |
| 39 | explicit QNetworkProxyQuery(quint16 bindPort, const QString &protocolTag = QString(), |
| 40 | QueryType queryType = TcpServer); |
| 41 | QNetworkProxyQuery(const QNetworkProxyQuery &other); |
| 42 | QNetworkProxyQuery &operator=(QNetworkProxyQuery &&other) noexcept { swap(other); return *this; } |
| 43 | QNetworkProxyQuery &operator=(const QNetworkProxyQuery &other); |
| 44 | ~QNetworkProxyQuery(); |
| 45 | |
| 46 | void swap(QNetworkProxyQuery &other) noexcept { d.swap(other&: other.d); } |
| 47 | |
| 48 | bool operator==(const QNetworkProxyQuery &other) const; |
| 49 | inline bool operator!=(const QNetworkProxyQuery &other) const |
| 50 | { return !(*this == other); } |
| 51 | |
| 52 | QueryType queryType() const; |
| 53 | void setQueryType(QueryType type); |
| 54 | |
| 55 | int peerPort() const; |
| 56 | void setPeerPort(int port); |
| 57 | |
| 58 | QString peerHostName() const; |
| 59 | void setPeerHostName(const QString &hostname); |
| 60 | |
| 61 | int localPort() const; |
| 62 | void setLocalPort(int port); |
| 63 | |
| 64 | QString protocolTag() const; |
| 65 | void setProtocolTag(const QString &protocolTag); |
| 66 | |
| 67 | QUrl url() const; |
| 68 | void setUrl(const QUrl &url); |
| 69 | |
| 70 | private: |
| 71 | QSharedDataPointer<QNetworkProxyQueryPrivate> d; |
| 72 | }; |
| 73 | |
| 74 | Q_DECLARE_SHARED(QNetworkProxyQuery) |
| 75 | |
| 76 | class QNetworkProxyPrivate; |
| 77 | |
| 78 | class Q_NETWORK_EXPORT QNetworkProxy |
| 79 | { |
| 80 | Q_GADGET |
| 81 | public: |
| 82 | enum ProxyType { |
| 83 | DefaultProxy, |
| 84 | Socks5Proxy, |
| 85 | NoProxy, |
| 86 | HttpProxy, |
| 87 | HttpCachingProxy, |
| 88 | FtpCachingProxy |
| 89 | }; |
| 90 | |
| 91 | enum Capability { |
| 92 | TunnelingCapability = 0x0001, |
| 93 | ListeningCapability = 0x0002, |
| 94 | UdpTunnelingCapability = 0x0004, |
| 95 | CachingCapability = 0x0008, |
| 96 | HostNameLookupCapability = 0x0010, |
| 97 | SctpTunnelingCapability = 0x00020, |
| 98 | SctpListeningCapability = 0x00040 |
| 99 | }; |
| 100 | Q_DECLARE_FLAGS(Capabilities, Capability) |
| 101 | |
| 102 | QNetworkProxy(); |
| 103 | QNetworkProxy(ProxyType type, const QString &hostName = QString(), quint16 port = 0, |
| 104 | const QString &user = QString(), const QString &password = QString()); |
| 105 | QNetworkProxy(const QNetworkProxy &other); |
| 106 | QNetworkProxy &operator=(QNetworkProxy &&other) noexcept { swap(other); return *this; } |
| 107 | QNetworkProxy &operator=(const QNetworkProxy &other); |
| 108 | ~QNetworkProxy(); |
| 109 | |
| 110 | void swap(QNetworkProxy &other) noexcept { d.swap(other&: other.d); } |
| 111 | |
| 112 | bool operator==(const QNetworkProxy &other) const; |
| 113 | inline bool operator!=(const QNetworkProxy &other) const |
| 114 | { return !(*this == other); } |
| 115 | |
| 116 | void setType(QNetworkProxy::ProxyType type); |
| 117 | QNetworkProxy::ProxyType type() const; |
| 118 | |
| 119 | void setCapabilities(Capabilities capab); |
| 120 | Capabilities capabilities() const; |
| 121 | bool isCachingProxy() const; |
| 122 | bool isTransparentProxy() const; |
| 123 | |
| 124 | void setUser(const QString &userName); |
| 125 | QString user() const; |
| 126 | |
| 127 | void setPassword(const QString &password); |
| 128 | QString password() const; |
| 129 | |
| 130 | void setHostName(const QString &hostName); |
| 131 | QString hostName() const; |
| 132 | |
| 133 | void setPort(quint16 port); |
| 134 | quint16 port() const; |
| 135 | |
| 136 | static void setApplicationProxy(const QNetworkProxy &proxy); |
| 137 | static QNetworkProxy applicationProxy(); |
| 138 | |
| 139 | QHttpHeaders () const; |
| 140 | void (const QHttpHeaders &); |
| 141 | void (QHttpHeaders &&); |
| 142 | |
| 143 | // "cooked" headers |
| 144 | QVariant (QNetworkRequest::KnownHeaders ) const; |
| 145 | void (QNetworkRequest::KnownHeaders , const QVariant &value); |
| 146 | |
| 147 | // raw headers: |
| 148 | bool (const QByteArray &) const; |
| 149 | QList<QByteArray> () const; |
| 150 | QByteArray (const QByteArray &) const; |
| 151 | void (const QByteArray &, const QByteArray &value); |
| 152 | |
| 153 | private: |
| 154 | QSharedDataPointer<QNetworkProxyPrivate> d; |
| 155 | }; |
| 156 | |
| 157 | Q_DECLARE_SHARED(QNetworkProxy) |
| 158 | Q_DECLARE_OPERATORS_FOR_FLAGS(QNetworkProxy::Capabilities) |
| 159 | |
| 160 | class Q_NETWORK_EXPORT QNetworkProxyFactory |
| 161 | { |
| 162 | public: |
| 163 | QNetworkProxyFactory(); |
| 164 | virtual ~QNetworkProxyFactory(); |
| 165 | |
| 166 | virtual QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query = QNetworkProxyQuery()) = 0; |
| 167 | |
| 168 | static bool usesSystemConfiguration(); |
| 169 | static void setUseSystemConfiguration(bool enable); |
| 170 | static void setApplicationProxyFactory(QNetworkProxyFactory *factory); |
| 171 | static QList<QNetworkProxy> proxyForQuery(const QNetworkProxyQuery &query); |
| 172 | static QList<QNetworkProxy> systemProxyForQuery(const QNetworkProxyQuery &query = QNetworkProxyQuery()); |
| 173 | }; |
| 174 | |
| 175 | #ifndef QT_NO_DEBUG_STREAM |
| 176 | Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxy &proxy); |
| 177 | Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxyQuery &proxyQuery); |
| 178 | #endif |
| 179 | |
| 180 | QT_END_NAMESPACE |
| 181 | |
| 182 | QT_DECL_METATYPE_EXTERN(QNetworkProxy, Q_NETWORK_EXPORT) |
| 183 | |
| 184 | #endif // QT_NO_NETWORKPROXY |
| 185 | |
| 186 | #endif // QHOSTINFO_H |
| 187 | |