ProxyServerCFNet.cpp [plain text]
#include "config.h"
#include "ProxyServer.h"
#include "KURL.h"
#include <wtf/RetainPtr.h>
#include <CFNetwork/CFNetwork.h>
namespace WebCore {
#ifndef BUILDING_ON_LEOPARD
static void addProxyServersForURL(Vector<ProxyServer>& proxyServers, const KURL& url)
{
RetainPtr<CFDictionaryRef> proxySettings(AdoptCF, CFNetworkCopySystemProxySettings());
if (!proxySettings)
return;
RetainPtr<CFURLRef> cfURL(AdoptCF, url.createCFURL());
RetainPtr<CFArrayRef> proxiesForURL(AdoptCF, CFNetworkCopyProxiesForURL(cfURL.get(), proxySettings.get()));
if (!proxiesForURL)
return;
CFIndex numProxies = CFArrayGetCount(proxiesForURL.get());
for (CFIndex i = 0; i < numProxies; ++i) {
CFDictionaryRef proxyDictionary = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(proxiesForURL.get(), i));
ProxyServer::Type type = ProxyServer::Direct;
CFStringRef typeString = static_cast<CFStringRef>(CFDictionaryGetValue(proxyDictionary, kCFProxyTypeKey));
if (CFEqual(typeString, kCFProxyTypeAutoConfigurationURL)) {
continue;
}
if (CFEqual(typeString, kCFProxyTypeNone)) {
proxyServers.append(ProxyServer(ProxyServer::Direct, String(), -1));
continue;
}
if (CFEqual(typeString, kCFProxyTypeHTTP))
type = ProxyServer::HTTP;
else if (CFEqual(typeString, kCFProxyTypeHTTPS))
type = ProxyServer::HTTPS;
else if (CFEqual(typeString, kCFProxyTypeSOCKS))
type = ProxyServer::SOCKS;
else {
continue;
}
CFStringRef host = static_cast<CFStringRef>(CFDictionaryGetValue(proxyDictionary, kCFProxyHostNameKey));
CFNumberRef port = static_cast<CFNumberRef>(CFDictionaryGetValue(proxyDictionary, kCFProxyPortNumberKey));
SInt32 portValue;
CFNumberGetValue(port, kCFNumberSInt32Type, &portValue);
proxyServers.append(ProxyServer(type, host, portValue));
}
}
Vector<ProxyServer> proxyServersForURL(const KURL& url, const NetworkingContext*)
{
Vector<ProxyServer> proxyServers;
addProxyServersForURL(proxyServers, url);
return proxyServers;
}
#else
Vector<ProxyServer> proxyServersForURL(const KURL&, const NetworkingContext*)
{
return Vector<ProxyServer>();
}
#endif
}