Read CFNetwork Proxy Results Directly in C++
Use Apple's C proxy lookup APIs from C++ and keep borrowed dictionary values alive without releasing them as owned objects.
CFNetwork's proxy lookup is a C API usable directly from C++; converting everything into Objective-C objects is optional. Ask CFNetworkCopyProxiesForURL with the target CFURL and settings from CFNetworkCopySystemProxySettings to get ordered proxy dictionaries.
| Value | Ownership |
|---|---|
| Objects created or returned by Copy, including routes and settings | Caller-owned; release each non-null owned object |
| Dictionary from the array or hostname from the dictionary through Get | Borrowed; do not release without having retained it |
For valid routes and an in-range index, extraction can be:
CFDictionaryRef proxy = static_cast<CFDictionaryRef>(
CFArrayGetValueAtIndex(routes, index));
CFStringRef hostname = static_cast<CFStringRef>(
CFDictionaryGetValue(proxy, kCFProxyHostNameKey));
Read kCFProxyTypeKey before treating the entry as an endpoint. Direct and automatic-configuration candidates require different handling.
Convert a concrete entry's CFString hostname and CFNumber port while the owner stays alive. Extracted C++ values can then enter the transport's configuration. To retain the CFString itself beyond the result, first retain it and later balance that with CFRelease; otherwise finish before releasing its containing owner.
Release the created/copied target URL, settings dictionary and result array at cleanup, using a scope guard if appropriate. A variable's CFStringRef type alone does not grant ownership over a Get result.