60 CFNumberRef excludeSimples;
62 (excludeSimples = (CFNumberRef)CFDictionaryGetValue(dict, kCFNetworkProxiesExcludeSimpleHostnames))) {
64 if (CFNumberGetValue(excludeSimples, kCFNumberIntType, &
enabled) &&
enabled)
73 CFArrayRef exclusionList = (CFArrayRef)CFDictionaryGetValue(dict, kCFNetworkProxiesExceptionsList);
77 CFIndex
size = CFArrayGetCount(exclusionList);
78 for (CFIndex
i = 0;
i <
size; ++
i) {
79 CFStringRef cfentry = (CFStringRef)CFArrayGetValueAtIndex(exclusionList,
i);
87 if (
rx.match(host).hasMatch())
99 CFStringRef enableKey, CFStringRef hostKey,
102 CFNumberRef protoEnabled;
103 CFNumberRef protoPort;
104 CFStringRef protoHost;
106 && (protoEnabled = (CFNumberRef)CFDictionaryGetValue(dict, enableKey))
107 && (protoHost = (CFStringRef)CFDictionaryGetValue(dict, hostKey))
108 && (protoPort = (CFNumberRef)CFDictionaryGetValue(dict, portKey))) {
110 if (CFNumberGetValue(protoEnabled, kCFNumberIntType, &
enabled) &&
enabled) {
111 QString host = QString::fromCFString(protoHost);
114 CFNumberGetValue(protoPort, kCFNumberIntType, &
port);
132 CFStringRef cfProxyType = (CFStringRef)CFDictionaryGetValue(dict, kCFProxyTypeKey);
133 if (CFStringCompare(cfProxyType, kCFProxyTypeNone, 0) == kCFCompareEqualTo) {
135 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeFTP, 0) == kCFCompareEqualTo) {
137 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeHTTP, 0) == kCFCompareEqualTo) {
139 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeHTTPS, 0) == kCFCompareEqualTo) {
141 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeSOCKS, 0) == kCFCompareEqualTo) {
145 hostName = QString::fromCFString((CFStringRef)CFDictionaryGetValue(dict, kCFProxyHostNameKey));
146 user = QString::fromCFString((CFStringRef)CFDictionaryGetValue(dict, kCFProxyUsernameKey));
147 password = QString::fromCFString((CFStringRef)CFDictionaryGetValue(dict, kCFProxyPasswordKey));
149 CFNumberRef portNumber = (CFNumberRef)CFDictionaryGetValue(dict, kCFProxyPortNumberKey);
151 CFNumberGetValue(portNumber, kCFNumberSInt16Type, &
port);
220 QList<QNetworkProxy>
result;
223 const QCFType<CFDictionaryRef> dict = CFNetworkCopySystemProxySettings();
225 qWarning(
"QNetworkProxyFactory::systemProxyForQuery: CFNetworkCopySystemProxySettings returned nullptr");
233 CFNumberRef pacEnabled;
234 if ((pacEnabled = (CFNumberRef)CFDictionaryGetValue(dict, kCFNetworkProxiesProxyAutoConfigEnable))) {
236 if (CFNumberGetValue(pacEnabled, kCFNumberIntType, &
enabled) &&
enabled) {
240 CFStringRef pacLocationSetting = (CFStringRef)CFDictionaryGetValue(dict, kCFNetworkProxiesProxyAutoConfigURLString);
241 auto cfPacLocation = stringByAddingPercentEscapes(pacLocationSetting);
242 QCFType<CFDataRef> pacData;
243 QCFType<CFURLRef> pacUrl = CFURLCreateWithString(kCFAllocatorDefault, cfPacLocation, NULL);
250 if (encodedURL.isEmpty()) {
254 QCFType<CFURLRef> targetURL = CFURLCreateWithBytes(kCFAllocatorDefault, (UInt8*)encodedURL.data(), encodedURL.size(), kCFStringEncodingUTF8, NULL);
259 CFStreamClientContext pacCtx;
262 pacCtx.info = &pacInfo;
263 pacCtx.retain = NULL;
264 pacCtx.release = NULL;
265 pacCtx.copyDescription = NULL;
267 static CFStringRef pacRunLoopMode = CFSTR(
"qtPACRunLoopMode");
269 QCFType<CFRunLoopSourceRef> pacRunLoopSource = CFNetworkExecuteProxyAutoConfigurationURL(pacUrl, targetURL, &proxyAutoConfigCallback, &pacCtx);
270 CFRunLoopAddSource(CFRunLoopGetCurrent(), pacRunLoopSource, pacRunLoopMode);
271 while (!pacInfo.done)
272 CFRunLoopRunInMode(pacRunLoopMode, 1000,
true);
274 if (!pacInfo.proxies) {
275 QString pacLocation = QString::fromCFString(cfPacLocation);
276 QCFType<CFStringRef> pacErrorDescription = CFErrorCopyDescription(pacInfo.error);
277 qWarning(
"Execution of PAC script at \"%s\" failed: %s",
qPrintable(pacLocation),
qPrintable(QString::fromCFString(pacErrorDescription)));
281 CFIndex
size = CFArrayGetCount(pacInfo.proxies);
282 for (CFIndex
i = 0;
i <
size; ++
i) {
283 CFDictionaryRef
proxy = (CFDictionaryRef)CFArrayGetValueAtIndex(pacInfo.proxies,
i);
295 protocolSpecificProxy =
297 kCFNetworkProxiesHTTPEnable,
298 kCFNetworkProxiesHTTPProxy,
299 kCFNetworkProxiesHTTPPort);
308 result << protocolSpecificProxy;
314 const auto proxiesForUrl = proxiesForQueryUrl(dict,
query.url());
315 for (
const auto &
proxy : proxiesForUrl) {
320 bool isHttps =
false;
322 protocolSpecificProxy =
324 kCFNetworkProxiesFTPEnable,
325 kCFNetworkProxiesFTPProxy,
326 kCFNetworkProxiesFTPPort);
329 protocolSpecificProxy =
331 kCFNetworkProxiesHTTPSEnable,
332 kCFNetworkProxiesHTTPSProxy,
333 kCFNetworkProxiesHTTPSPort);
337 result << protocolSpecificProxy;
341 kCFNetworkProxiesSOCKSEnable,
342 kCFNetworkProxiesSOCKSProxy,
343 kCFNetworkProxiesSOCKSPort);
352 kCFNetworkProxiesHTTPSEnable,
353 kCFNetworkProxiesHTTPSProxy,
354 kCFNetworkProxiesHTTPSPort);