| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
#include <SystemConfiguration/SystemConfiguration.h> |
| 21 |
|
| 22 |
struct ProxyDict |
| 23 |
{ |
| 24 |
ProxyDict(); |
| 25 |
|
| 26 |
int port; |
| 27 |
QString host; |
| 28 |
|
| 29 |
bool isProxyEnabled() const { return port > 0 && host.size(); } |
| 30 |
}; |
| 31 |
|
| 32 |
|
| 33 |
inline ProxyDict::ProxyDict() : port( 0 ) |
| 34 |
{ |
| 35 |
|
| 36 |
CFDictionaryRef proxyDict = SCDynamicStoreCopyProxies( NULL ); |
| 37 |
bool result = (proxyDict != NULL); |
| 38 |
|
| 39 |
|
| 40 |
CFNumberRef enableNum; |
| 41 |
int enable; |
| 42 |
if (result) { |
| 43 |
enableNum = (CFNumberRef) CFDictionaryGetValue( proxyDict, kSCPropNetProxiesHTTPEnable ); |
| 44 |
result = (enableNum != NULL) && (CFGetTypeID(enableNum) == CFNumberGetTypeID()); |
| 45 |
} |
| 46 |
if (result) |
| 47 |
result = CFNumberGetValue( enableNum, kCFNumberIntType, &enable ) && (enable != 0); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
CFStringRef hostStr; |
| 54 |
if (result) { |
| 55 |
hostStr = (CFStringRef) CFDictionaryGetValue( proxyDict, kSCPropNetProxiesHTTPProxy ); |
| 56 |
result = (hostStr != NULL) && (CFGetTypeID(hostStr) == CFStringGetTypeID()); |
| 57 |
} |
| 58 |
if (result) |
| 59 |
host = lastfm::CFStringToQString( hostStr ); |
| 60 |
|
| 61 |
|
| 62 |
CFNumberRef portNum; |
| 63 |
|
| 64 |
if (result) { |
| 65 |
portNum = (CFNumberRef) CFDictionaryGetValue( proxyDict, kSCPropNetProxiesHTTPPort ); |
| 66 |
result = (portNum != NULL) && (CFGetTypeID(portNum) == CFNumberGetTypeID()); |
| 67 |
} |
| 68 |
if (result) |
| 69 |
result = CFNumberGetValue( portNum, kCFNumberIntType, &port ); |
| 70 |
|
| 71 |
|
| 72 |
if (proxyDict != NULL) |
| 73 |
CFRelease( proxyDict ); |
| 74 |
} |