author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtNetwork module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include "qnetworkproxy.h" |
|
43 |
||
44 |
#ifndef QT_NO_NETWORKPROXY |
|
45 |
||
46 |
#include <qmutex.h> |
|
47 |
#include <qstringlist.h> |
|
48 |
#include <qregexp.h> |
|
49 |
#include <qurl.h> |
|
50 |
||
51 |
#include <string.h> |
|
52 |
#include <qt_windows.h> |
|
53 |
#include <wininet.h> |
|
54 |
||
55 |
/* |
|
56 |
* Information on the WinHTTP DLL: |
|
57 |
* http://msdn.microsoft.com/en-us/library/aa384122(VS.85).aspx example for WPAD |
|
58 |
* |
|
59 |
* http://msdn.microsoft.com/en-us/library/aa384097(VS.85).aspx WinHttpGetProxyForUrl |
|
60 |
* http://msdn.microsoft.com/en-us/library/aa384096(VS.85).aspx WinHttpGetIEProxyConfigForCurrentUs |
|
61 |
* http://msdn.microsoft.com/en-us/library/aa384095(VS.85).aspx WinHttpGetDefaultProxyConfiguration |
|
62 |
*/ |
|
63 |
||
64 |
// We don't want to include winhttp.h because that's not |
|
65 |
// present in some Windows SDKs (I don't know why) |
|
66 |
// So, instead, copy the definitions here |
|
67 |
||
68 |
typedef struct { |
|
69 |
DWORD dwFlags; |
|
70 |
DWORD dwAutoDetectFlags; |
|
71 |
LPCWSTR lpszAutoConfigUrl; |
|
72 |
LPVOID lpvReserved; |
|
73 |
DWORD dwReserved; |
|
74 |
BOOL fAutoLogonIfChallenged; |
|
75 |
} WINHTTP_AUTOPROXY_OPTIONS; |
|
76 |
||
77 |
typedef struct { |
|
78 |
DWORD dwAccessType; |
|
79 |
LPWSTR lpszProxy; |
|
80 |
LPWSTR lpszProxyBypass; |
|
81 |
} WINHTTP_PROXY_INFO; |
|
82 |
||
83 |
typedef struct { |
|
84 |
BOOL fAutoDetect; |
|
85 |
LPWSTR lpszAutoConfigUrl; |
|
86 |
LPWSTR lpszProxy; |
|
87 |
LPWSTR lpszProxyBypass; |
|
88 |
} WINHTTP_CURRENT_USER_IE_PROXY_CONFIG; |
|
89 |
||
90 |
#define WINHTTP_AUTOPROXY_AUTO_DETECT 0x00000001 |
|
91 |
#define WINHTTP_AUTOPROXY_CONFIG_URL 0x00000002 |
|
92 |
||
93 |
#define WINHTTP_AUTO_DETECT_TYPE_DHCP 0x00000001 |
|
94 |
#define WINHTTP_AUTO_DETECT_TYPE_DNS_A 0x00000002 |
|
95 |
||
96 |
#define WINHTTP_ACCESS_TYPE_DEFAULT_PROXY 0 |
|
97 |
#define WINHTTP_ACCESS_TYPE_NO_PROXY 1 |
|
98 |
#define WINHTTP_ACCESS_TYPE_NAMED_PROXY 3 |
|
99 |
||
100 |
#define WINHTTP_NO_PROXY_NAME NULL |
|
101 |
#define WINHTTP_NO_PROXY_BYPASS NULL |
|
102 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
103 |
#define WINHTTP_ERROR_BASE 12000 |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
104 |
#define ERROR_WINHTTP_LOGIN_FAILURE (WINHTTP_ERROR_BASE + 15) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
105 |
#define ERROR_WINHTTP_AUTODETECTION_FAILED (WINHTTP_ERROR_BASE + 180) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
106 |
|
0 | 107 |
QT_BEGIN_NAMESPACE |
108 |
||
109 |
typedef BOOL (WINAPI * PtrWinHttpGetProxyForUrl)(HINTERNET, LPCWSTR, WINHTTP_AUTOPROXY_OPTIONS*, WINHTTP_PROXY_INFO*); |
|
110 |
typedef HINTERNET (WINAPI * PtrWinHttpOpen)(LPCWSTR, DWORD, LPCWSTR, LPCWSTR,DWORD); |
|
111 |
typedef BOOL (WINAPI * PtrWinHttpGetDefaultProxyConfiguration)(WINHTTP_PROXY_INFO*); |
|
112 |
typedef BOOL (WINAPI * PtrWinHttpGetIEProxyConfigForCurrentUser)(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG*); |
|
113 |
typedef BOOL (WINAPI * PtrWinHttpCloseHandle)(HINTERNET); |
|
114 |
static PtrWinHttpGetProxyForUrl ptrWinHttpGetProxyForUrl = 0; |
|
115 |
static PtrWinHttpOpen ptrWinHttpOpen = 0; |
|
116 |
static PtrWinHttpGetDefaultProxyConfiguration ptrWinHttpGetDefaultProxyConfiguration = 0; |
|
117 |
static PtrWinHttpGetIEProxyConfigForCurrentUser ptrWinHttpGetIEProxyConfigForCurrentUser = 0; |
|
118 |
static PtrWinHttpCloseHandle ptrWinHttpCloseHandle = 0; |
|
119 |
||
120 |
||
121 |
static QStringList splitSpaceSemicolon(const QString &source) |
|
122 |
{ |
|
123 |
QStringList list; |
|
124 |
int start = 0; |
|
125 |
int end; |
|
126 |
while (true) { |
|
127 |
int space = source.indexOf(QLatin1Char(' '), start); |
|
128 |
int semicolon = source.indexOf(QLatin1Char(';'), start); |
|
129 |
end = space; |
|
130 |
if (semicolon != -1 && (end == -1 || semicolon < end)) |
|
131 |
end = semicolon; |
|
132 |
||
133 |
if (end == -1) { |
|
134 |
if (start != source.length()) |
|
135 |
list.append(source.mid(start)); |
|
136 |
return list; |
|
137 |
} |
|
138 |
if (start != end) |
|
139 |
list.append(source.mid(start, end - start)); |
|
140 |
start = end + 1; |
|
141 |
} |
|
142 |
return list; |
|
143 |
} |
|
144 |
||
145 |
static bool isBypassed(const QString &host, const QStringList &bypassList) |
|
146 |
{ |
|
147 |
if (host.isEmpty()) |
|
148 |
return true; |
|
149 |
||
150 |
bool isSimple = !host.contains(QLatin1Char('.')) && !host.contains(QLatin1Char(':')); |
|
151 |
||
152 |
QHostAddress ipAddress; |
|
153 |
bool isIpAddress = ipAddress.setAddress(host); |
|
154 |
||
155 |
// does it match the list of exclusions? |
|
156 |
foreach (const QString &entry, bypassList) { |
|
157 |
if (isSimple && entry == QLatin1String("<local>")) |
|
158 |
return true; |
|
159 |
if (isIpAddress && ipAddress.isInSubnet(QHostAddress::parseSubnet(entry))) { |
|
160 |
return true; // excluded |
|
161 |
} else { |
|
162 |
// do wildcard matching |
|
163 |
QRegExp rx(entry, Qt::CaseInsensitive, QRegExp::Wildcard); |
|
164 |
if (rx.exactMatch(host)) |
|
165 |
return true; |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
// host was not excluded |
|
170 |
return false; |
|
171 |
} |
|
172 |
||
173 |
static QList<QNetworkProxy> parseServerList(const QNetworkProxyQuery &query, const QStringList &proxyList) |
|
174 |
{ |
|
175 |
// Reference documentation from Microsoft: |
|
176 |
// http://msdn.microsoft.com/en-us/library/aa383912(VS.85).aspx |
|
177 |
// |
|
178 |
// According to the website, the proxy server list is |
|
179 |
// one or more of the space- or semicolon-separated strings in the format: |
|
180 |
// ([<scheme>=][<scheme>"://"]<server>[":"<port>]) |
|
181 |
||
182 |
QList<QNetworkProxy> result; |
|
183 |
foreach (const QString &entry, proxyList) { |
|
184 |
int server = 0; |
|
185 |
||
186 |
int pos = entry.indexOf(QLatin1Char('=')); |
|
187 |
if (pos != -1) { |
|
188 |
QStringRef scheme = entry.leftRef(pos); |
|
189 |
if (scheme != query.protocolTag()) |
|
190 |
continue; |
|
191 |
||
192 |
server = pos + 1; |
|
193 |
} |
|
194 |
||
195 |
QNetworkProxy::ProxyType proxyType = QNetworkProxy::HttpProxy; |
|
196 |
quint16 port = 8080; |
|
197 |
||
198 |
pos = entry.indexOf(QLatin1String("://"), server); |
|
199 |
if (pos != -1) { |
|
200 |
QStringRef scheme = entry.midRef(server, pos - server); |
|
201 |
if (scheme == QLatin1String("http") || scheme == QLatin1String("https")) { |
|
202 |
// no-op |
|
203 |
// defaults are above |
|
204 |
} else if (scheme == QLatin1String("socks") || scheme == QLatin1String("socks5")) { |
|
205 |
proxyType = QNetworkProxy::Socks5Proxy; |
|
206 |
port = 1080; |
|
207 |
} else { |
|
208 |
// unknown proxy type |
|
209 |
continue; |
|
210 |
} |
|
211 |
||
212 |
server = pos + 3; |
|
213 |
} |
|
214 |
||
215 |
pos = entry.indexOf(QLatin1Char(':'), server); |
|
216 |
if (pos != -1) { |
|
217 |
bool ok; |
|
218 |
uint value = entry.mid(pos + 1).toUInt(&ok); |
|
219 |
if (!ok || value > 65535) |
|
220 |
continue; // invalid port number |
|
221 |
||
222 |
port = value; |
|
223 |
} else { |
|
224 |
pos = entry.length(); |
|
225 |
} |
|
226 |
||
227 |
result << QNetworkProxy(proxyType, entry.mid(server, pos - server), port); |
|
228 |
} |
|
229 |
||
230 |
return result; |
|
231 |
} |
|
232 |
||
233 |
class QWindowsSystemProxy |
|
234 |
{ |
|
235 |
public: |
|
236 |
QWindowsSystemProxy(); |
|
237 |
~QWindowsSystemProxy(); |
|
238 |
void init(); |
|
239 |
||
240 |
QMutex mutex; |
|
241 |
||
242 |
HINTERNET hHttpSession; |
|
243 |
WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions; |
|
244 |
||
245 |
QString autoConfigUrl; |
|
246 |
QStringList proxyServerList; |
|
247 |
QStringList proxyBypass; |
|
248 |
QList<QNetworkProxy> defaultResult; |
|
249 |
||
250 |
bool initialized; |
|
251 |
bool functional; |
|
252 |
bool isAutoConfig; |
|
253 |
}; |
|
254 |
||
255 |
Q_GLOBAL_STATIC(QWindowsSystemProxy, systemProxy) |
|
256 |
||
257 |
QWindowsSystemProxy::QWindowsSystemProxy() |
|
258 |
: initialized(false), functional(false), isAutoConfig(false) |
|
259 |
{ |
|
260 |
defaultResult << QNetworkProxy::NoProxy; |
|
261 |
} |
|
262 |
||
263 |
QWindowsSystemProxy::~QWindowsSystemProxy() |
|
264 |
{ |
|
265 |
if (hHttpSession) |
|
266 |
ptrWinHttpCloseHandle(hHttpSession); |
|
267 |
} |
|
268 |
||
269 |
void QWindowsSystemProxy::init() |
|
270 |
{ |
|
271 |
if (initialized) |
|
272 |
return; |
|
273 |
initialized = true; |
|
274 |
||
275 |
#ifdef Q_OS_WINCE |
|
276 |
// Windows CE does not have any of the following API |
|
277 |
return; |
|
278 |
#else |
|
279 |
// load the winhttp.dll library |
|
280 |
HINSTANCE winhttpHnd = LoadLibrary(L"winhttp"); |
|
281 |
if (!winhttpHnd) |
|
282 |
return; // failed to load |
|
283 |
||
284 |
ptrWinHttpOpen = (PtrWinHttpOpen)GetProcAddress(winhttpHnd, "WinHttpOpen"); |
|
285 |
ptrWinHttpCloseHandle = (PtrWinHttpCloseHandle)GetProcAddress(winhttpHnd, "WinHttpCloseHandle"); |
|
286 |
ptrWinHttpGetProxyForUrl = (PtrWinHttpGetProxyForUrl)GetProcAddress(winhttpHnd, "WinHttpGetProxyForUrl"); |
|
287 |
ptrWinHttpGetDefaultProxyConfiguration = (PtrWinHttpGetDefaultProxyConfiguration)GetProcAddress(winhttpHnd, "WinHttpGetDefaultProxyConfiguration"); |
|
288 |
ptrWinHttpGetIEProxyConfigForCurrentUser = (PtrWinHttpGetIEProxyConfigForCurrentUser)GetProcAddress(winhttpHnd, "WinHttpGetIEProxyConfigForCurrentUser"); |
|
289 |
||
290 |
// Try to obtain the Internet Explorer configuration. |
|
291 |
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig; |
|
292 |
if (ptrWinHttpGetIEProxyConfigForCurrentUser(&ieProxyConfig)) { |
|
293 |
if (ieProxyConfig.lpszAutoConfigUrl) { |
|
294 |
autoConfigUrl = QString::fromWCharArray(ieProxyConfig.lpszAutoConfigUrl); |
|
295 |
GlobalFree(ieProxyConfig.lpszAutoConfigUrl); |
|
296 |
} |
|
297 |
if (ieProxyConfig.lpszProxy) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
// http://msdn.microsoft.com/en-us/library/aa384250%28VS.85%29.aspx speaks only about a "proxy URL", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
299 |
// not multiple URLs. However we tested this and it can return multiple URLs. So we use splitSpaceSemicolon |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
300 |
// on it. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
301 |
proxyServerList = splitSpaceSemicolon(QString::fromWCharArray(ieProxyConfig.lpszProxy)); |
0 | 302 |
GlobalFree(ieProxyConfig.lpszProxy); |
303 |
} |
|
304 |
if (ieProxyConfig.lpszProxyBypass) { |
|
305 |
proxyBypass = splitSpaceSemicolon(QString::fromWCharArray(ieProxyConfig.lpszProxyBypass)); |
|
306 |
GlobalFree(ieProxyConfig.lpszProxyBypass); |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
hHttpSession = NULL; |
|
311 |
if (ieProxyConfig.fAutoDetect || !autoConfigUrl.isEmpty()) { |
|
312 |
// using proxy autoconfiguration |
|
313 |
proxyServerList.clear(); |
|
314 |
proxyBypass.clear(); |
|
315 |
||
316 |
// open the handle and obtain the options |
|
317 |
hHttpSession = ptrWinHttpOpen(L"Qt System Proxy access/1.0", |
|
318 |
WINHTTP_ACCESS_TYPE_NO_PROXY, |
|
319 |
WINHTTP_NO_PROXY_NAME, |
|
320 |
WINHTTP_NO_PROXY_BYPASS, |
|
321 |
0); |
|
322 |
if (!hHttpSession) |
|
323 |
return; |
|
324 |
||
325 |
isAutoConfig = true; |
|
326 |
memset(&autoProxyOptions, 0, sizeof autoProxyOptions); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
327 |
autoProxyOptions.fAutoLogonIfChallenged = false; |
0 | 328 |
if (ieProxyConfig.fAutoDetect) { |
329 |
autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT; |
|
330 |
autoProxyOptions.dwAutoDetectFlags = WINHTTP_AUTO_DETECT_TYPE_DHCP | |
|
331 |
WINHTTP_AUTO_DETECT_TYPE_DNS_A; |
|
332 |
} else { |
|
333 |
autoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; |
|
334 |
autoProxyOptions.lpszAutoConfigUrl = (LPCWSTR)autoConfigUrl.utf16(); |
|
335 |
} |
|
336 |
} else { |
|
337 |
// not auto-detected |
|
338 |
// attempt to get the static configuration instead |
|
339 |
WINHTTP_PROXY_INFO proxyInfo; |
|
340 |
if (ptrWinHttpGetDefaultProxyConfiguration(&proxyInfo) && |
|
341 |
proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NAMED_PROXY) { |
|
342 |
// we got information from the registry |
|
343 |
// overwrite the IE configuration, if any |
|
344 |
||
345 |
proxyBypass = splitSpaceSemicolon(QString::fromWCharArray(proxyInfo.lpszProxyBypass)); |
|
346 |
proxyServerList = splitSpaceSemicolon(QString::fromWCharArray(proxyInfo.lpszProxy)); |
|
347 |
} |
|
348 |
||
349 |
if (proxyInfo.lpszProxy) |
|
350 |
GlobalFree(proxyInfo.lpszProxy); |
|
351 |
if (proxyInfo.lpszProxyBypass) |
|
352 |
GlobalFree(proxyInfo.lpszProxyBypass); |
|
353 |
} |
|
354 |
||
355 |
functional = isAutoConfig || !proxyServerList.isEmpty(); |
|
356 |
#endif |
|
357 |
} |
|
358 |
||
359 |
QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery(const QNetworkProxyQuery &query) |
|
360 |
{ |
|
361 |
QWindowsSystemProxy *sp = systemProxy(); |
|
362 |
if (!sp) |
|
363 |
return QList<QNetworkProxy>() << QNetworkProxy(); |
|
364 |
||
365 |
QMutexLocker locker(&sp->mutex); |
|
366 |
sp->init(); |
|
367 |
if (!sp->functional) |
|
368 |
return sp->defaultResult; |
|
369 |
||
370 |
if (sp->isAutoConfig) { |
|
371 |
WINHTTP_PROXY_INFO proxyInfo; |
|
372 |
||
373 |
// try to get the proxy config for the URL |
|
374 |
QUrl url = query.url(); |
|
375 |
// url could be empty, e.g. from QNetworkProxy::applicationProxy(), that's fine, |
|
376 |
// we'll still ask for the proxy. |
|
377 |
// But for a file url, we know we don't need one. |
|
378 |
if (url.scheme() == QLatin1String("file") || url.scheme() == QLatin1String("qrc")) |
|
379 |
return sp->defaultResult; |
|
380 |
if (query.queryType() != QNetworkProxyQuery::UrlRequest) { |
|
381 |
// change the scheme to https, maybe it'll work |
|
382 |
url.setScheme(QLatin1String("https")); |
|
383 |
} |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
384 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
385 |
bool getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
386 |
(LPCWSTR)url.toString().utf16(), |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
387 |
&sp->autoProxyOptions, |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
388 |
&proxyInfo); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
389 |
DWORD getProxyError = GetLastError(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
390 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
391 |
if (!getProxySucceeded |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
392 |
&& (ERROR_WINHTTP_LOGIN_FAILURE == getProxyError)) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
393 |
// We first tried without AutoLogon, because this might prevent caching the result. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
394 |
// But now we've to enable it (http://msdn.microsoft.com/en-us/library/aa383153%28v=VS.85%29.aspx) |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
395 |
sp->autoProxyOptions.fAutoLogonIfChallenged = TRUE; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
396 |
getProxySucceeded = ptrWinHttpGetProxyForUrl(sp->hHttpSession, |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
397 |
(LPCWSTR)url.toString().utf16(), |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
398 |
&sp->autoProxyOptions, |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
399 |
&proxyInfo); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
400 |
getProxyError = GetLastError(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
401 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
402 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
403 |
if (getProxySucceeded) { |
0 | 404 |
// yes, we got a config for this URL |
405 |
QString proxyBypass = QString::fromWCharArray(proxyInfo.lpszProxyBypass); |
|
406 |
QStringList proxyServerList = splitSpaceSemicolon(QString::fromWCharArray(proxyInfo.lpszProxy)); |
|
407 |
if (proxyInfo.lpszProxy) |
|
408 |
GlobalFree(proxyInfo.lpszProxy); |
|
409 |
if (proxyInfo.lpszProxyBypass) |
|
410 |
GlobalFree(proxyInfo.lpszProxyBypass); |
|
411 |
||
412 |
if (isBypassed(query.peerHostName(), splitSpaceSemicolon(proxyBypass))) |
|
413 |
return sp->defaultResult; |
|
414 |
return parseServerList(query, proxyServerList); |
|
415 |
} |
|
416 |
||
417 |
// GetProxyForUrl failed |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
418 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
419 |
if (ERROR_WINHTTP_AUTODETECTION_FAILED == getProxyError) { |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
420 |
//No config file could be retrieved on the network. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
421 |
//Don't search for it next time again. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
422 |
sp->isAutoConfig = false; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
423 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
424 |
|
0 | 425 |
return sp->defaultResult; |
426 |
} |
|
427 |
||
428 |
// static configuration |
|
429 |
if (isBypassed(query.peerHostName(), sp->proxyBypass)) |
|
430 |
return sp->defaultResult; |
|
431 |
||
432 |
QList<QNetworkProxy> result = parseServerList(query, sp->proxyServerList); |
|
433 |
// In some cases, this was empty. See SF task 00062670 |
|
434 |
if (result.isEmpty()) |
|
435 |
return sp->defaultResult; |
|
436 |
||
437 |
return result; |
|
438 |
} |
|
439 |
||
440 |
QT_END_NAMESPACE |
|
441 |
||
442 |
#endif |