Qt 4.8
|
The QNetworkProxy class provides a network layer proxy. More...
#include <qnetworkproxy.h>
Public Types | |
enum | Capability { TunnelingCapability = 0x0001, ListeningCapability = 0x0002, UdpTunnelingCapability = 0x0004, CachingCapability = 0x0008, HostNameLookupCapability = 0x0010 } |
These flags indicate the capabilities that a given proxy server supports. More... | |
enum | ProxyType { DefaultProxy, Socks5Proxy, NoProxy, HttpProxy, HttpCachingProxy, FtpCachingProxy } |
This enum describes the types of network proxying provided in Qt. More... | |
Public Functions | |
Capabilities | capabilities () const |
Returns the capabilities of this proxy server. More... | |
QString | hostName () const |
Returns the host name of the proxy host. More... | |
bool | isCachingProxy () const |
Returns true if this proxy supports the QNetworkProxy::CachingCapability capability. More... | |
bool | isTransparentProxy () const |
Returns true if this proxy supports transparent tunneling of TCP connections. More... | |
bool | operator!= (const QNetworkProxy &other) const |
Compares the value of this network proxy to other and returns true if they differ. More... | |
QNetworkProxy & | operator= (const QNetworkProxy &other) |
Assigns the value of the network proxy other to this network proxy. More... | |
bool | operator== (const QNetworkProxy &other) const |
QString | password () const |
Returns the password used for authentication. More... | |
quint16 | port () const |
Returns the port of the proxy host. More... | |
QNetworkProxy () | |
Constructs a QNetworkProxy with DefaultProxy type; the proxy type is determined by applicationProxy(), which defaults to NoProxy. More... | |
QNetworkProxy (ProxyType type, const QString &hostName=QString(), quint16 port=0, const QString &user=QString(), const QString &password=QString()) | |
Constructs a QNetworkProxy with type, hostName, port, user and password. More... | |
QNetworkProxy (const QNetworkProxy &other) | |
Constructs a copy of other. More... | |
void | setCapabilities (Capabilities capab) |
Sets the capabilities of this proxy to capabilities. More... | |
void | setHostName (const QString &hostName) |
Sets the host name of the proxy host to be hostName. More... | |
void | setPassword (const QString &password) |
Sets the password for proxy authentication to be password. More... | |
void | setPort (quint16 port) |
Sets the port of the proxy host to be port. More... | |
void | setType (QNetworkProxy::ProxyType type) |
Sets the proxy type for this instance to be type. More... | |
void | setUser (const QString &userName) |
Sets the user name for proxy authentication to be user. More... | |
QNetworkProxy::ProxyType | type () const |
Returns the proxy type for this instance. More... | |
QString | user () const |
Returns the user name used for authentication. More... | |
~QNetworkProxy () | |
Destroys the QNetworkProxy object. More... | |
Static Public Functions | |
static QNetworkProxy | applicationProxy () |
Returns the application level network proxying. More... | |
static void | setApplicationProxy (const QNetworkProxy &proxy) |
Sets the application level network proxying to be networkProxy. More... | |
Properties | |
QSharedDataPointer< QNetworkProxyPrivate > | d |
The QNetworkProxy class provides a network layer proxy.
QNetworkProxy provides the method for configuring network layer proxy support to the Qt network classes. The currently supported classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer, QNetworkAccessManager and QFtp. The proxy support is designed to be as transparent as possible. This means that existing network-enabled applications that you have written should automatically support network proxy using the following code.
An alternative to setting an application wide proxy is to specify the proxy for individual sockets using QAbstractSocket::setProxy() and QTcpServer::setProxy(). In this way, it is possible to disable the use of a proxy for specific sockets using the following code:
Network proxy is not used if the address used in QAbstractSocket::connectToHost() , QUdpSocket::bind() or QTcpServer::listen() is equivalent to QHostAddress::LocalHost or QHostAddress::LocalHostIPv6.
Each type of proxy support has certain restrictions associated with it. You should read the ProxyType documentation carefully before selecting a proxy type to use.
The SOCKS5 support in Qt 4 is based on RFC 1928 and RFC 1929. The supported authentication methods are no authentication and username/password authentication. Both IPv4 and IPv6 are supported. Domain names are resolved through the SOCKS5 server if the QNetworkProxy::HostNameLookupCapability is enabled, otherwise they are resolved locally and the IP address is sent to the server. There are several things to remember when using SOCKS5 with QUdpSocket and QTcpServer:
With QUdpSocket, a call to QUdpSocket::bind(){bind()} may fail with a timeout error. If a port number other than 0 is passed to QUdpSocket::bind(){bind()}, it is not guaranteed that it is the specified port that will be used. Use localPort() and localAddress() to get the actual address and port number in use. Because proxied UDP goes through two UDP connections, it is more likely that packets will be dropped.
With QTcpServer a call to listen() may fail with a timeout error. If a port number other than 0 is passed to listen(), then it is not guaranteed that it is the specified port that will be used. Use serverPort() and serverAddress() to get the actual address and port used to listen for connections. SOCKS5 only supports one accepted connection per call to listen(), and each call is likely to result in a different serverPort() being used.
Definition at line 123 of file qnetworkproxy.h.
These flags indicate the capabilities that a given proxy server supports.
QNetworkProxy sets different capabilities by default when the object is created (see QNetworkProxy::ProxyType for a list of the defaults). However, it is possible to change the capabitilies after the object has been created with setCapabilities().
The capabilities that QNetworkProxy supports are:
Enumerator | |
---|---|
TunnelingCapability | |
ListeningCapability | |
UdpTunnelingCapability | |
CachingCapability | |
HostNameLookupCapability |
Definition at line 135 of file qnetworkproxy.h.
This enum describes the types of network proxying provided in Qt.
There are two types of proxies that Qt understands: transparent proxies and caching proxies. The first group consists of proxies that can handle any arbitrary data transfer, while the second can only handle specific requests. The caching proxies only make sense for the specific classes where they can be used.
The table below lists different proxy types and their capabilities. Since each proxy type has different capabilities, it is important to understand them before choosing a proxy type.
Proxy type | Description | Default capabilities |
SOCKS 5 | Generic proxy for any kind of connection. Supports TCP, UDP, binding to a port (incoming connections) and authentication. | TunnelingCapability, ListeningCapability, UdpTunnelingCapability, HostNameLookupCapability |
HTTP | Implemented using the "CONNECT" command, supports only outgoing TCP connections; supports authentication. | TunnelingCapability, CachingCapability, HostNameLookupCapability |
Caching-only HTTP | Implemented using normal HTTP commands, it is useful only in the context of HTTP requests (see QNetworkAccessManager) | CachingCapability, HostNameLookupCapability |
Caching FTP | Implemented using an FTP proxy, it is useful only in the context of FTP requests (see QFtp, QNetworkAccessManager) | CachingCapability, HostNameLookupCapability |
Also note that you shouldn't set the application default proxy (setApplicationProxy()) to a proxy that doesn't have the TunnelingCapability capability. If you do, QTcpSocket will not know how to open connections.
Enumerator | |
---|---|
DefaultProxy | |
Socks5Proxy | |
NoProxy | |
HttpProxy | |
HttpCachingProxy | |
FtpCachingProxy |
Definition at line 126 of file qnetworkproxy.h.
QNetworkProxy::QNetworkProxy | ( | ) |
Constructs a QNetworkProxy with DefaultProxy type; the proxy type is determined by applicationProxy(), which defaults to NoProxy.
Definition at line 445 of file qnetworkproxy.cpp.
Referenced by applicationProxy().
QNetworkProxy::QNetworkProxy | ( | ProxyType | type, |
const QString & | hostName = QString() , |
||
quint16 | port = 0 , |
||
const QString & | user = QString() , |
||
const QString & | password = QString() |
||
) |
Constructs a QNetworkProxy with type, hostName, port, user and password.
The default capabilities for proxy type type are set automatically.
Definition at line 462 of file qnetworkproxy.cpp.
QNetworkProxy::QNetworkProxy | ( | const QNetworkProxy & | other | ) |
QNetworkProxy::~QNetworkProxy | ( | ) |
Destroys the QNetworkProxy object.
Definition at line 483 of file qnetworkproxy.cpp.
|
static |
Returns the application level network proxying.
If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy returned by this function is used.
Definition at line 736 of file qnetworkproxy.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), applicationProxy(), QNativeSocketEnginePrivate::checkProxy(), and QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials().
QNetworkProxy::Capabilities QNetworkProxy::capabilities | ( | ) | const |
Returns the capabilities of this proxy server.
Definition at line 576 of file qnetworkproxy.cpp.
Referenced by filterProxyListByCapabilities(), isCachingProxy(), isTransparentProxy(), QNetworkAccessHttpBackend::postRequest(), QAbstractSocketPrivate::resolveProxy(), QTcpServerPrivate::resolveProxy(), and setCapabilities().
QString QNetworkProxy::hostName | ( | ) | const |
Returns the host name of the proxy host.
Definition at line 677 of file qnetworkproxy.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), makeCacheKey(), QNetworkAccessFtpBackend::open(), proxyAuthenticationKey(), QSocks5SocketEnginePrivate::reauthenticate(), removeDuplicateProxies(), and setHostName().
bool QNetworkProxy::isCachingProxy | ( | ) | const |
Returns true if this proxy supports the QNetworkProxy::CachingCapability capability.
In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling setCapabilities().
Definition at line 596 of file qnetworkproxy.cpp.
bool QNetworkProxy::isTransparentProxy | ( | ) | const |
Returns true if this proxy supports transparent tunneling of TCP connections.
This matches the QNetworkProxy::TunnelingCapability capability.
In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling setCapabilities().
Definition at line 617 of file qnetworkproxy.cpp.
Referenced by QNetworkAccessHttpBackend::postRequest().
|
inline |
Compares the value of this network proxy to other and returns true if they differ.
\
Definition at line 151 of file qnetworkproxy.h.
QNetworkProxy & QNetworkProxy::operator= | ( | const QNetworkProxy & | other | ) |
Assigns the value of the network proxy other to this network proxy.
Definition at line 518 of file qnetworkproxy.cpp.
bool QNetworkProxy::operator== | ( | const QNetworkProxy & | other | ) | const |
Compares the value of this network proxy to other and returns true if they are equal (same proxy type, server as well as username and password)
Definition at line 494 of file qnetworkproxy.cpp.
QString QNetworkProxy::password | ( | ) | const |
Returns the password used for authentication.
Definition at line 657 of file qnetworkproxy.cpp.
Referenced by QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials(), QSocks5SocketEnginePrivate::initialize(), QSocks5SocketEnginePrivate::reauthenticate(), setPassword(), QHttpSocketEngine::setProxy(), and QHttpSetProxyRequest::start().
quint16 QNetworkProxy::port | ( | ) | const |
Returns the port of the proxy host.
Definition at line 697 of file qnetworkproxy.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), makeCacheKey(), QNetworkAccessFtpBackend::open(), proxyAuthenticationKey(), QSocks5SocketEnginePrivate::reauthenticate(), removeDuplicateProxies(), and setPort().
|
static |
Sets the application level network proxying to be networkProxy.
If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy set with this function is used. If you want more flexibility in determining which the proxy, use the QNetworkProxyFactory class.
Setting a default proxy value with this function will override the application proxy factory set with QNetworkProxyFactory::setApplicationProxyFactory.
Definition at line 716 of file qnetworkproxy.cpp.
void QNetworkProxy::setCapabilities | ( | Capabilities | capabilities | ) |
Sets the capabilities of this proxy to capabilities.
Definition at line 560 of file qnetworkproxy.cpp.
void QNetworkProxy::setHostName | ( | const QString & | hostName | ) |
Sets the host name of the proxy host to be hostName.
Definition at line 667 of file qnetworkproxy.cpp.
Referenced by Maemo::ProxyConfPrivate::flush(), and QNetworkProxyFactory::systemProxyForQuery().
void QNetworkProxy::setPassword | ( | const QString & | password | ) |
Sets the password for proxy authentication to be password.
Definition at line 647 of file qnetworkproxy.cpp.
Referenced by QSocks5SocketEnginePrivate::reauthenticate(), and QNetworkProxyFactory::systemProxyForQuery().
void QNetworkProxy::setPort | ( | quint16 | port | ) |
Sets the port of the proxy host to be port.
Definition at line 687 of file qnetworkproxy.cpp.
Referenced by Maemo::ProxyConfPrivate::flush(), and QNetworkProxyFactory::systemProxyForQuery().
void QNetworkProxy::setType | ( | QNetworkProxy::ProxyType | type | ) |
Sets the proxy type for this instance to be type.
Note that changing the type of a proxy does not change the set of capabilities this QNetworkProxy object holds if any capabilities have been set with setCapabilities().
Definition at line 533 of file qnetworkproxy.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), Maemo::ProxyConfPrivate::flush(), and QNetworkProxyFactory::systemProxyForQuery().
void QNetworkProxy::setUser | ( | const QString & | user | ) |
Sets the user name for proxy authentication to be user.
Definition at line 627 of file qnetworkproxy.cpp.
Referenced by QNetworkAccessAuthenticationManager::cacheProxyCredentials(), QSocks5SocketEnginePrivate::reauthenticate(), and QNetworkProxyFactory::systemProxyForQuery().
QNetworkProxy::ProxyType QNetworkProxy::type | ( | ) | const |
Returns the proxy type for this instance.
Definition at line 545 of file qnetworkproxy.cpp.
Referenced by QHttpPrivate::_q_slotSendRequest(), QNetworkAccessAuthenticationManager::cacheProxyCredentials(), QNativeSocketEnginePrivate::checkProxy(), QAbstractSocketEngine::createSocketEngine(), QHttpSocketEngineHandler::createSocketEngine(), QSocks5SocketEngineHandler::createSocketEngine(), QHttpNetworkConnectionChannel::ensureConnection(), QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials(), Maemo::ProxyConfPrivate::flush(), macQueryInternal(), makeCacheKey(), QNetworkAccessFtpBackend::open(), parseServerList(), QNetworkAccessHttpBackend::postRequest(), QHttpNetworkConnectionPrivate::prepareRequest(), proxyAuthenticationKey(), QGlobalNetworkProxy::proxyForQuery(), QNetworkAccessManagerPrivate::queryProxy(), removeDuplicateProxies(), QAbstractSocketPrivate::resolveProxy(), QTcpServerPrivate::resolveProxy(), setApplicationProxy(), setType(), and QHttpThreadDelegate::startRequest().
QString QNetworkProxy::user | ( | ) | const |
Returns the user name used for authentication.
Definition at line 637 of file qnetworkproxy.cpp.
Referenced by QNetworkAccessAuthenticationManager::cacheProxyCredentials(), QSocks5SocketEnginePrivate::initialize(), makeCacheKey(), proxyAuthenticationKey(), QSocks5SocketEnginePrivate::reauthenticate(), QHttpSocketEngine::setProxy(), setUser(), and QHttpSetProxyRequest::start().
|
private |
Definition at line 178 of file qnetworkproxy.h.
Referenced by capabilities(), hostName(), operator=(), operator==(), password(), port(), QNetworkProxyQuery::QNetworkProxyQuery(), setCapabilities(), setHostName(), setPassword(), setPort(), setType(), setUser(), type(), and user().