Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccessauthenticationmanager.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | - | |||||||||||||
10 | - | |||||||||||||
11 | class QNetworkAuthenticationCache: private QVector<QNetworkAuthenticationCredential>, | - | ||||||||||||
12 | public QNetworkAccessCache::CacheableObject | - | ||||||||||||
13 | { | - | ||||||||||||
14 | public: | - | ||||||||||||
15 | QNetworkAuthenticationCache() | - | ||||||||||||
16 | { | - | ||||||||||||
17 | setExpires(false); | - | ||||||||||||
18 | setShareable(true); | - | ||||||||||||
19 | reserve(1); | - | ||||||||||||
20 | } executed 315 times by 2 tests: end of block Executed by:
| 315 | ||||||||||||
21 | - | |||||||||||||
22 | QNetworkAuthenticationCredential *findClosestMatch(const QString &domain) | - | ||||||||||||
23 | { | - | ||||||||||||
24 | iterator it = std::lower_bound(begin(), end(), domain); | - | ||||||||||||
25 | if (it == end()
| 31-366 | ||||||||||||
26 | -- executed 31 times by 1 test: it;--it; Executed by:
executed 31 times by 1 test: --it; Executed by:
| 31 | ||||||||||||
27 | if (it == end()
| 0-397 | ||||||||||||
28 | return executed 315 times by 2 tests: 0;return 0; Executed by:
executed 315 times by 2 tests: return 0; Executed by:
| 315 | ||||||||||||
29 | return executed 397 times by 1 test: &*it;return &*it; Executed by:
executed 397 times by 1 test: return &*it; Executed by:
| 397 | ||||||||||||
30 | } | - | ||||||||||||
31 | - | |||||||||||||
32 | void insert(const QString &domain, const QString &user, const QString &password) | - | ||||||||||||
33 | { | - | ||||||||||||
34 | QNetworkAuthenticationCredential *closestMatch = findClosestMatch(domain); | - | ||||||||||||
35 | if (closestMatch
| 0-358 | ||||||||||||
36 | - | |||||||||||||
37 | closestMatch->user = user; | - | ||||||||||||
38 | closestMatch->password = password; | - | ||||||||||||
39 | } executed 358 times by 1 test: else {end of block Executed by:
| 358 | ||||||||||||
40 | QNetworkAuthenticationCredential newCredential; | - | ||||||||||||
41 | newCredential.domain = domain; | - | ||||||||||||
42 | newCredential.user = user; | - | ||||||||||||
43 | newCredential.password = password; | - | ||||||||||||
44 | - | |||||||||||||
45 | if (closestMatch
| 0-315 | ||||||||||||
46 | QVector<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential); never executed: QVector<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential); | 0 | ||||||||||||
47 | else | - | ||||||||||||
48 | QVector<QNetworkAuthenticationCredential>::insert(end(), newCredential); executed 315 times by 2 tests: QVector<QNetworkAuthenticationCredential>::insert(end(), newCredential); Executed by:
| 315 | ||||||||||||
49 | } | - | ||||||||||||
50 | } | - | ||||||||||||
51 | - | |||||||||||||
52 | virtual void dispose() override { delete this; } executed 315 times by 2 tests: end of block Executed by:
| 315 | ||||||||||||
53 | }; | - | ||||||||||||
54 | - | |||||||||||||
55 | - | |||||||||||||
56 | static QByteArray proxyAuthenticationKey(const QNetworkProxy &proxy, const QString &realm) | - | ||||||||||||
57 | { | - | ||||||||||||
58 | QUrl key; | - | ||||||||||||
59 | - | |||||||||||||
60 | switch (proxy.type()) { | - | ||||||||||||
61 | case executed 78 times by 2 tests: QNetworkProxy::Socks5Proxy:case QNetworkProxy::Socks5Proxy: Executed by:
executed 78 times by 2 tests: case QNetworkProxy::Socks5Proxy: Executed by:
| 78 | ||||||||||||
62 | key.setScheme(QLatin1String("proxy-socks5")); | - | ||||||||||||
63 | break; executed 78 times by 2 tests: break; Executed by:
| 78 | ||||||||||||
64 | - | |||||||||||||
65 | case executed 104 times by 2 tests: QNetworkProxy::HttpProxy:case QNetworkProxy::HttpProxy: Executed by:
executed 104 times by 2 tests: case QNetworkProxy::HttpProxy: Executed by:
| 104 | ||||||||||||
66 | case executed 21 times by 1 test: QNetworkProxy::HttpCachingProxy:case QNetworkProxy::HttpCachingProxy: Executed by:
executed 21 times by 1 test: case QNetworkProxy::HttpCachingProxy: Executed by:
| 21 | ||||||||||||
67 | key.setScheme(QLatin1String("proxy-http")); | - | ||||||||||||
68 | break; executed 125 times by 2 tests: break; Executed by:
| 125 | ||||||||||||
69 | - | |||||||||||||
70 | case never executed: QNetworkProxy::FtpCachingProxy:case QNetworkProxy::FtpCachingProxy: never executed: case QNetworkProxy::FtpCachingProxy: | 0 | ||||||||||||
71 | key.setScheme(QLatin1String("proxy-ftp")); | - | ||||||||||||
72 | break; never executed: break; | 0 | ||||||||||||
73 | - | |||||||||||||
74 | case never executed: QNetworkProxy::DefaultProxy:case QNetworkProxy::DefaultProxy: never executed: case QNetworkProxy::DefaultProxy: | 0 | ||||||||||||
75 | case never executed: QNetworkProxy::NoProxy:case QNetworkProxy::NoProxy: never executed: case QNetworkProxy::NoProxy: | 0 | ||||||||||||
76 | - | |||||||||||||
77 | return never executed: QByteArray();return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
78 | - | |||||||||||||
79 | - | |||||||||||||
80 | - | |||||||||||||
81 | } | - | ||||||||||||
82 | - | |||||||||||||
83 | if (key.scheme().isEmpty()
| 0-203 | ||||||||||||
84 | - | |||||||||||||
85 | return never executed: QByteArray();return QByteArray(); never executed: return QByteArray(); | 0 | ||||||||||||
86 | - | |||||||||||||
87 | key.setUserName(proxy.user()); | - | ||||||||||||
88 | key.setHost(proxy.hostName()); | - | ||||||||||||
89 | key.setPort(proxy.port()); | - | ||||||||||||
90 | key.setFragment(realm); | - | ||||||||||||
91 | return executed 203 times by 2 tests: "auth:" + key.toEncoded();return "auth:" + key.toEncoded(); Executed by:
executed 203 times by 2 tests: return "auth:" + key.toEncoded(); Executed by:
| 203 | ||||||||||||
92 | } | - | ||||||||||||
93 | - | |||||||||||||
94 | - | |||||||||||||
95 | static inline QByteArray authenticationKey(const QUrl &url, const QString &realm) | - | ||||||||||||
96 | { | - | ||||||||||||
97 | QUrl copy = url; | - | ||||||||||||
98 | copy.setFragment(realm); | - | ||||||||||||
99 | return executed 932 times by 4 tests: "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery);return "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery); Executed by:
executed 932 times by 4 tests: return "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery); Executed by:
| 932 | ||||||||||||
100 | } | - | ||||||||||||
101 | - | |||||||||||||
102 | - | |||||||||||||
103 | - | |||||||||||||
104 | void QNetworkAccessAuthenticationManager::cacheProxyCredentials(const QNetworkProxy &p, | - | ||||||||||||
105 | const QAuthenticator *authenticator) | - | ||||||||||||
106 | { | - | ||||||||||||
107 | ((!(authenticator)) ? qt_assert("authenticator",__FILE__,153) : qt_noop()); | - | ||||||||||||
108 | ((!(p.type() != QNetworkProxy::DefaultProxy)) ? qt_assert("p.type() != QNetworkProxy::DefaultProxy",__FILE__,154) : qt_noop()); | - | ||||||||||||
109 | ((!(p.type() != QNetworkProxy::NoProxy)) ? qt_assert("p.type() != QNetworkProxy::NoProxy",__FILE__,155) : qt_noop()); | - | ||||||||||||
110 | - | |||||||||||||
111 | QMutexLocker mutexLocker(&mutex); | - | ||||||||||||
112 | - | |||||||||||||
113 | QString realm = authenticator->realm(); | - | ||||||||||||
114 | QNetworkProxy proxy = p; | - | ||||||||||||
115 | proxy.setUser(authenticator->user()); | - | ||||||||||||
116 | - | |||||||||||||
117 | - | |||||||||||||
118 | if (authenticator->password().isNull()
| 6-54 | ||||||||||||
119 | return; executed 6 times by 2 tests: return; Executed by:
| 6 | ||||||||||||
120 | - | |||||||||||||
121 | - | |||||||||||||
122 | do { | - | ||||||||||||
123 | - | |||||||||||||
124 | do { | - | ||||||||||||
125 | QByteArray cacheKey = proxyAuthenticationKey(proxy, realm); | - | ||||||||||||
126 | if (cacheKey.isEmpty()
| 0-138 | ||||||||||||
127 | return; never executed: return; | 0 | ||||||||||||
128 | - | |||||||||||||
129 | QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache; | - | ||||||||||||
130 | auth->insert(QString(), authenticator->user(), authenticator->password()); | - | ||||||||||||
131 | authenticationCache.addEntry(cacheKey, auth); | - | ||||||||||||
132 | - | |||||||||||||
133 | if (realm.isEmpty()
| 30-108 | ||||||||||||
134 | break; executed 108 times by 2 tests: break; Executed by:
| 108 | ||||||||||||
135 | } else { | - | ||||||||||||
136 | realm.clear(); | - | ||||||||||||
137 | } executed 30 times by 2 tests: end of block Executed by:
| 30 | ||||||||||||
138 | } while (true); | - | ||||||||||||
139 | - | |||||||||||||
140 | if (proxy.user().isEmpty()
| 54 | ||||||||||||
141 | break; executed 54 times by 2 tests: break; Executed by:
| 54 | ||||||||||||
142 | else | - | ||||||||||||
143 | proxy.setUser(QString()); executed 54 times by 2 tests: proxy.setUser(QString()); Executed by:
| 54 | ||||||||||||
144 | } while (true); | - | ||||||||||||
145 | } executed 54 times by 2 tests: end of block Executed by:
| 54 | ||||||||||||
146 | - | |||||||||||||
147 | QNetworkAuthenticationCredential | - | ||||||||||||
148 | QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials(const QNetworkProxy &p, | - | ||||||||||||
149 | const QAuthenticator *authenticator) | - | ||||||||||||
150 | { | - | ||||||||||||
151 | QNetworkProxy proxy = p; | - | ||||||||||||
152 | if (proxy.type() == QNetworkProxy::DefaultProxy
| 0-65 | ||||||||||||
153 | proxy = QNetworkProxy::applicationProxy(); | - | ||||||||||||
154 | } never executed: end of block | 0 | ||||||||||||
155 | if (!proxy.password().isEmpty()
| 0-65 | ||||||||||||
156 | return never executed: QNetworkAuthenticationCredential();return QNetworkAuthenticationCredential(); never executed: return QNetworkAuthenticationCredential(); | 0 | ||||||||||||
157 | - | |||||||||||||
158 | QString realm; | - | ||||||||||||
159 | if (authenticator
| 1-64 | ||||||||||||
160 | realm = authenticator->realm(); executed 1 time by 1 test: realm = authenticator->realm(); Executed by:
| 1 | ||||||||||||
161 | - | |||||||||||||
162 | QMutexLocker mutexLocker(&mutex); | - | ||||||||||||
163 | QByteArray cacheKey = proxyAuthenticationKey(proxy, realm); | - | ||||||||||||
164 | if (cacheKey.isEmpty()
| 0-65 | ||||||||||||
165 | return never executed: QNetworkAuthenticationCredential();return QNetworkAuthenticationCredential(); never executed: return QNetworkAuthenticationCredential(); | 0 | ||||||||||||
166 | if (!authenticationCache.hasEntry(cacheKey)
| 8-57 | ||||||||||||
167 | return executed 57 times by 2 tests: QNetworkAuthenticationCredential();return QNetworkAuthenticationCredential(); Executed by:
executed 57 times by 2 tests: return QNetworkAuthenticationCredential(); Executed by:
| 57 | ||||||||||||
168 | - | |||||||||||||
169 | QNetworkAuthenticationCache *auth = | - | ||||||||||||
170 | static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey)); | - | ||||||||||||
171 | QNetworkAuthenticationCredential cred = *auth->findClosestMatch(QString()); | - | ||||||||||||
172 | authenticationCache.releaseEntry(cacheKey); | - | ||||||||||||
173 | - | |||||||||||||
174 | - | |||||||||||||
175 | ((!(!cred.isNull())) ? qt_assert_x("QNetworkAccessManager", "Internal inconsistency: found a cache key for a proxy, but it's empty", | - | ||||||||||||
176 | __FILE__ | - | ||||||||||||
177 | , | - | ||||||||||||
178 | 222 | - | ||||||||||||
179 | ) : qt_noop()) | - | ||||||||||||
180 | ; | - | ||||||||||||
181 | return executed 8 times by 1 test: cred;return cred; Executed by:
executed 8 times by 1 test: return cred; Executed by:
| 8 | ||||||||||||
182 | } | - | ||||||||||||
183 | - | |||||||||||||
184 | - | |||||||||||||
185 | - | |||||||||||||
186 | void QNetworkAccessAuthenticationManager::cacheCredentials(const QUrl &url, | - | ||||||||||||
187 | const QAuthenticator *authenticator) | - | ||||||||||||
188 | { | - | ||||||||||||
189 | ((!(authenticator)) ? qt_assert("authenticator",__FILE__,231) : qt_noop()); | - | ||||||||||||
190 | if (authenticator->isNull()
| 3-273 | ||||||||||||
191 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||
192 | QString domain = QString::fromLatin1("/"); | - | ||||||||||||
193 | QString realm = authenticator->realm(); | - | ||||||||||||
194 | - | |||||||||||||
195 | QMutexLocker mutexLocker(&mutex); | - | ||||||||||||
196 | - | |||||||||||||
197 | - | |||||||||||||
198 | QUrl copy = url; | - | ||||||||||||
199 | copy.setUserName(authenticator->user()); | - | ||||||||||||
200 | do { | - | ||||||||||||
201 | QByteArray cacheKey = authenticationKey(copy, realm); | - | ||||||||||||
202 | if (authenticationCache.hasEntry(cacheKey)
| 177-358 | ||||||||||||
203 | QNetworkAuthenticationCache *auth = | - | ||||||||||||
204 | static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey)); | - | ||||||||||||
205 | auth->insert(domain, authenticator->user(), authenticator->password()); | - | ||||||||||||
206 | authenticationCache.releaseEntry(cacheKey); | - | ||||||||||||
207 | } executed 358 times by 1 test: else {end of block Executed by:
| 358 | ||||||||||||
208 | QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache; | - | ||||||||||||
209 | auth->insert(domain, authenticator->user(), authenticator->password()); | - | ||||||||||||
210 | authenticationCache.addEntry(cacheKey, auth); | - | ||||||||||||
211 | } executed 177 times by 1 test: end of block Executed by:
| 177 | ||||||||||||
212 | - | |||||||||||||
213 | if (copy.userName().isEmpty()
| 262-273 | ||||||||||||
214 | break; executed 273 times by 1 test: break; Executed by:
| 273 | ||||||||||||
215 | } else { | - | ||||||||||||
216 | copy.setUserName(QString()); | - | ||||||||||||
217 | } executed 262 times by 1 test: end of block Executed by:
| 262 | ||||||||||||
218 | } while (true); | - | ||||||||||||
219 | } executed 273 times by 1 test: end of block Executed by:
| 273 | ||||||||||||
220 | QNetworkAuthenticationCredential | - | ||||||||||||
221 | QNetworkAccessAuthenticationManager::fetchCachedCredentials(const QUrl &url, | - | ||||||||||||
222 | const QAuthenticator *authentication) | - | ||||||||||||
223 | { | - | ||||||||||||
224 | if (!url.password().isEmpty()
| 16-397 | ||||||||||||
225 | return executed 16 times by 1 test: QNetworkAuthenticationCredential();return QNetworkAuthenticationCredential(); Executed by:
executed 16 times by 1 test: return QNetworkAuthenticationCredential(); Executed by:
| 16 | ||||||||||||
226 | - | |||||||||||||
227 | QString realm; | - | ||||||||||||
228 | if (authentication
| 89-308 | ||||||||||||
229 | realm = authentication->realm(); executed 89 times by 1 test: realm = authentication->realm(); Executed by:
| 89 | ||||||||||||
230 | - | |||||||||||||
231 | QByteArray cacheKey = authenticationKey(url, realm); | - | ||||||||||||
232 | - | |||||||||||||
233 | QMutexLocker mutexLocker(&mutex); | - | ||||||||||||
234 | if (!authenticationCache.hasEntry(cacheKey)
| 31-366 | ||||||||||||
235 | return executed 366 times by 4 tests: QNetworkAuthenticationCredential();return QNetworkAuthenticationCredential(); Executed by:
executed 366 times by 4 tests: return QNetworkAuthenticationCredential(); Executed by:
| 366 | ||||||||||||
236 | - | |||||||||||||
237 | QNetworkAuthenticationCache *auth = | - | ||||||||||||
238 | static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey)); | - | ||||||||||||
239 | QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path()); | - | ||||||||||||
240 | QNetworkAuthenticationCredential ret; | - | ||||||||||||
241 | if (cred
| 0-31 | ||||||||||||
242 | ret = *cred; executed 31 times by 1 test: ret = *cred; Executed by:
| 31 | ||||||||||||
243 | authenticationCache.releaseEntry(cacheKey); | - | ||||||||||||
244 | return executed 31 times by 1 test: ret;return ret; Executed by:
executed 31 times by 1 test: return ret; Executed by:
| 31 | ||||||||||||
245 | } | - | ||||||||||||
246 | - | |||||||||||||
247 | void QNetworkAccessAuthenticationManager::clearCache() | - | ||||||||||||
248 | { | - | ||||||||||||
249 | authenticationCache.clear(); | - | ||||||||||||
250 | } executed 646 times by 2 tests: end of block Executed by:
| 646 | ||||||||||||
251 | - | |||||||||||||
252 | - | |||||||||||||
Switch to Source code | Preprocessed file |