Add debug stream operator for QNetworkProxy
authorShane Kearns <ext-shane.2.kearns@nokia.com>
Tue, 28 Feb 2012 11:57:12 +0000 (11:57 +0000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 8 Mar 2012 22:52:34 +0000 (23:52 +0100)
Change-Id: Ib8e7ba041ede33dc9c751432e39be2d6a9f4662d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/network/kernel/qnetworkproxy.cpp
src/network/kernel/qnetworkproxy.h

index 0281eaf..feef74e 100644 (file)
 #include "private/qsocks5socketengine_p.h"
 #include "private/qhttpsocketengine_p.h"
 #include "qauthenticator.h"
+#include "qdebug.h"
 #include "qhash.h"
 #include "qmutex.h"
+#include "qstringlist.h"
 #include "qurl.h"
 
 #ifndef QT_NO_BEARERMANAGEMENT
@@ -1508,6 +1510,51 @@ QList<QNetworkProxy> QNetworkProxyFactory::proxyForQuery(const QNetworkProxyQuer
     return globalNetworkProxy()->proxyForQuery(query);
 }
 
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug debug, const QNetworkProxy &proxy)
+{
+    QNetworkProxy::ProxyType type = proxy.type();
+    switch (type) {
+    case QNetworkProxy::NoProxy:
+        debug << "NoProxy ";
+        break;
+    case QNetworkProxy::DefaultProxy:
+        debug << "DefaultProxy ";
+        break;
+    case QNetworkProxy::Socks5Proxy:
+        debug << "Socks5Proxy ";
+        break;
+    case QNetworkProxy::HttpProxy:
+        debug << "HttpProxy ";
+        break;
+    case QNetworkProxy::HttpCachingProxy:
+        debug << "HttpCachingProxy ";
+        break;
+    case QNetworkProxy::FtpCachingProxy:
+        debug << "FtpCachingProxy ";
+        break;
+    default:
+        debug << "Unknown proxy " << int(type);
+        break;
+    }
+    debug << "\"" << proxy.hostName() << ":" << proxy.port() << "\" ";
+    QNetworkProxy::Capabilities caps = proxy.capabilities();
+    QStringList scaps;
+    if (caps & QNetworkProxy::TunnelingCapability)
+        scaps << QStringLiteral("Tunnel");
+    if (caps & QNetworkProxy::ListeningCapability)
+        scaps << QStringLiteral("Listen");
+    if (caps & QNetworkProxy::UdpTunnelingCapability)
+        scaps << QStringLiteral("UDP");
+    if (caps & QNetworkProxy::CachingCapability)
+        scaps << QStringLiteral("Caching");
+    if (caps & QNetworkProxy::HostNameLookupCapability)
+        scaps << QStringLiteral("NameLookup");
+    debug << "[" << scaps.join(QStringLiteral(" ")) << "]";
+    return debug;
+}
+#endif
+
 QT_END_NAMESPACE
 
 #endif // QT_NO_NETWORKPROXY
index 8f961c4..805f5cd 100644 (file)
@@ -203,6 +203,10 @@ public:
     static QList<QNetworkProxy> systemProxyForQuery(const QNetworkProxyQuery &query = QNetworkProxyQuery());
 };
 
+#ifndef QT_NO_DEBUG_STREAM
+Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkProxy &proxy);
+#endif
+
 QT_END_NAMESPACE
 
 QT_END_HEADER