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.

ValueOwnership
Objects created or returned by Copy, including routes and settingsCaller-owned; release each non-null owned object
Dictionary from the array or hostname from the dictionary through GetBorrowed; 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.

متعلقہ مضامین