Debian Codegraph @

src/mac/ProxyDict.h

raw symbols SCIP
1 /*
2 Copyright 2009 Last.fm Ltd.
3 - Primarily authored by Max Howell, Jono Cole and Doug Mansell
4
5 This file is part of liblastfm.
6
7 liblastfm is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 liblastfm is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
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 // Get the dictionary.
36 CFDictionaryRef proxyDict = SCDynamicStoreCopyProxies( NULL );
37 bool result = (proxyDict != NULL);
38
39 // Get the enable flag. This isn't a CFBoolean, but a CFNumber.
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 // Get the proxy host. DNS names must be in ASCII. If you
50 // put a non-ASCII character in the "Secure Web Proxy"
51 // field in the Network preferences panel, the CFStringGetCString
52 // function will fail and this function will return false.
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 // get the proxy port
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 // clean up.
72 if (proxyDict != NULL)
73 CFRelease( proxyDict );
74 }