44 #ifndef QT_NO_NETWORKPROXY 46 #include <CoreFoundation/CoreFoundation.h> 47 #include <SystemConfiguration/SystemConfiguration.h> 49 #include <QtCore/QRegExp> 50 #include <QtCore/QStringList> 51 #include <QtCore/QUrl> 52 #include <QtCore/qendian.h> 53 #include <QtCore/qstringlist.h> 54 #include "private/qcore_mac_p.h" 88 CFNumberRef excludeSimples;
90 (excludeSimples = (CFNumberRef)CFDictionaryGetValue(dict, kSCPropNetProxiesExcludeSimpleHostnames))) {
92 if (CFNumberGetValue(excludeSimples, kCFNumberIntType, &enabled) && enabled)
101 CFArrayRef exclusionList = (
CFArrayRef)CFDictionaryGetValue(dict, kSCPropNetProxiesExceptionsList);
105 CFIndex size = CFArrayGetCount(exclusionList);
106 for (CFIndex i = 0; i < size; ++i) {
128 CFNumberRef protoEnabled;
129 CFNumberRef protoPort;
132 && (protoEnabled = (CFNumberRef)CFDictionaryGetValue(dict, enableKey))
133 && (protoHost = (
CFStringRef)CFDictionaryGetValue(dict, hostKey))
134 && (protoPort = (CFNumberRef)CFDictionaryGetValue(dict, portKey))) {
136 if (CFNumberGetValue(protoEnabled, kCFNumberIntType, &enabled) && enabled) {
140 CFNumberGetValue(protoPort, kCFNumberIntType, &port);
160 if (CFStringCompare(cfProxyType, kCFProxyTypeNone, 0) == kCFCompareEqualTo) {
162 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeFTP, 0) == kCFCompareEqualTo) {
164 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeHTTP, 0) == kCFCompareEqualTo) {
166 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeHTTPS, 0) == kCFCompareEqualTo) {
168 }
else if (CFStringCompare(cfProxyType, kCFProxyTypeSOCKS, 0) == kCFCompareEqualTo) {
176 CFNumberRef portNumber = (CFNumberRef)CFDictionaryGetValue(dict, kCFProxyPortNumberKey);
178 CFNumberGetValue(portNumber, kCFNumberSInt16Type, &port);
181 return QNetworkProxy(proxyType, hostName, port, user, password);
187 case kCFURLUnknownError:
188 return "Unknown Error";
189 case kCFURLUnknownSchemeError:
190 return "Unknown Scheme";
191 case kCFURLResourceNotFoundError:
192 return "Resource Not Found";
193 case kCFURLResourceAccessViolationError:
194 return "Resource Access Violation";
195 case kCFURLRemoteHostUnavailableError:
196 return "Remote Host Unavailable";
197 case kCFURLImproperArgumentsError:
198 return "Improper Arguments";
199 case kCFURLUnknownPropertyKeyError:
200 return "Unknown Property Key";
201 case kCFURLPropertyKeyUnavailableError:
202 return "Property Key Unavailable";
203 case kCFURLTimeoutError:
206 return "Really Unknown Error";
215 CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL);
217 qWarning(
"QNetworkProxyFactory::systemProxyForQuery: SCDynamicStoreCopyProxies returned NULL");
227 CFNumberRef pacEnabled;
228 if ((pacEnabled = (CFNumberRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigEnable))) {
230 if (CFNumberGetValue(pacEnabled, kCFNumberIntType, &enabled) && enabled) {
232 CFStringRef cfPacLocation = (
CFStringRef)CFDictionaryGetValue(dict, kSCPropNetProxiesProxyAutoConfigURLString);
234 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) 237 QCFType<CFURLRef> pacUrl = CFURLCreateWithString(kCFAllocatorDefault, cfPacLocation, NULL);
239 if (!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, pacUrl, &pacData, NULL, NULL, &errorCode)) {
245 QCFType<CFStringRef> pacScript = CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, pacData, kCFStringEncodingISOLatin1);
258 QCFType<CFURLRef> targetURL = CFURLCreateWithBytes(kCFAllocatorDefault, (UInt8*)encodedURL.
data(), encodedURL.
size(), kCFStringEncodingUTF8, NULL);
264 QCFType<CFArrayRef> proxies = CFNetworkCopyProxiesForAutoConfigurationScript(pacScript, targetURL, &pacError);
272 CFIndex size = CFArrayGetCount(proxies);
273 for (CFIndex i = 0; i < size; ++i) {
274 CFDictionaryRef proxy = (CFDictionaryRef)CFArrayGetValueAtIndex(proxies, i);
282 qWarning(
"Mac system proxy: PAC script at \"%s\" not handled",
qPrintable(pacLocation));
288 bool isHttps =
false;
294 protocolSpecificProxy =
296 kSCPropNetProxiesFTPEnable,
297 kSCPropNetProxiesFTPProxy,
298 kSCPropNetProxiesFTPPort);
300 protocolSpecificProxy =
302 kSCPropNetProxiesHTTPEnable,
303 kSCPropNetProxiesHTTPProxy,
304 kSCPropNetProxiesHTTPPort);
307 protocolSpecificProxy =
309 kSCPropNetProxiesHTTPSEnable,
310 kSCPropNetProxiesHTTPSProxy,
311 kSCPropNetProxiesHTTPSPort);
314 result << protocolSpecificProxy;
318 kSCPropNetProxiesSOCKSEnable,
319 kSCPropNetProxiesSOCKSProxy,
320 kSCPropNetProxiesSOCKSPort);
328 kSCPropNetProxiesHTTPSEnable,
329 kSCPropNetProxiesHTTPSProxy,
330 kSCPropNetProxiesHTTPSPort);
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
const char * cfurlErrorDescription(SInt32 errorCode)
const struct __CFString * CFStringRef
#define QT_END_NAMESPACE
This macro expands to.
char * data()
Returns a pointer to the data stored in the byte array.
The QRegExp class provides pattern matching using regular expressions.
QString peerHostName() const
Returns the host name or IP address being of the outgoing connection being requested, or an empty string if the remote hostname is not known.
The QByteArray class provides an array of bytes.
static QString toQString(CFStringRef cfstr)
static QList< QNetworkProxy > systemProxyForQuery(const QNetworkProxyQuery &query=QNetworkProxyQuery())
This function takes the query request, query, examines the details of the type of socket or request a...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
The QNetworkProxy class provides a network layer proxy.
#define QT_BEGIN_NAMESPACE
This macro expands to.
QString protocolTag() const
Returns the protocol tag for this QNetworkProxyQuery object, or an empty QString in case the protocol...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QPair< QHostAddress, int > parseSubnet(const QString &subnet)
Parses the IP and subnet information contained in subnet and returns the network prefix for that netw...
Q_CORE_EXPORT void qWarning(const char *,...)
static bool isHostExcluded(CFDictionaryRef dict, const QString &host)
bool isInSubnet(const QHostAddress &subnet, int netmask) const
Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask...
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it's valid; otherwise an empty QByteArray is returne...
void setAddress(quint32 ip4Addr)
Set the IPv4 address specified by ip4Addr.
QList< QNetworkProxy > macQueryInternal(const QNetworkProxyQuery &query)
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
int size() const
Returns the number of bytes in this byte array.
QUrl url() const
Returns the URL component of this QNetworkProxyQuery object in case of a query of type QNetworkProxyQ...
bool exactMatch(const QString &str) const
Returns true if str is matched exactly by this regular expression; otherwise returns false...
static const MacVersion MacintoshVersion
the version of the Macintosh operating system on which the application is run (Mac only)...
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
The QHostAddress class provides an IP address.
static QNetworkProxy proxyFromDictionary(CFDictionaryRef dict, QNetworkProxy::ProxyType type, CFStringRef enableKey, CFStringRef hostKey, CFStringRef portKey)
const struct __CFArray * CFArrayRef
#define qPrintable(string)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
ProxyType
This enum describes the types of network proxying provided in Qt.