Line | Source Code | Coverage |
---|
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: } Execution Count:313 | 313 |
21 | | - |
22 | QNetworkAuthenticationCredential *findClosestMatch(const QString &domain) | - |
23 | { | - |
24 | iterator it = std::lower_bound(begin(), end(), domain); | - |
25 | if (it == end() && !isEmpty()) evaluated: it == end() yes Evaluation Count:340 | yes Evaluation Count:348 |
evaluated: !isEmpty() yes Evaluation Count:27 | yes Evaluation Count:313 |
| 27-348 |
26 | --it; executed: --it; Execution Count:27 | 27 |
27 | if (it == end() || !domain.startsWith(it->domain)) evaluated: it == end() yes Evaluation Count:313 | yes Evaluation Count:375 |
partially evaluated: !domain.startsWith(it->domain) no Evaluation Count:0 | yes Evaluation Count:375 |
| 0-375 |
28 | return 0; executed: return 0; Execution Count:313 | 313 |
29 | return &*it; executed: return &*it; Execution Count:375 | 375 |
30 | } | - |
31 | | - |
32 | void insert(const QString &domain, const QString &user, const QString &password) | - |
33 | { | - |
34 | QNetworkAuthenticationCredential *closestMatch = findClosestMatch(domain); | - |
35 | if (closestMatch && closestMatch->domain == domain) { evaluated: closestMatch yes Evaluation Count:344 | yes Evaluation Count:313 |
partially evaluated: closestMatch->domain == domain yes Evaluation Count:344 | no Evaluation Count:0 |
| 0-344 |
36 | | - |
37 | closestMatch->user = user; | - |
38 | closestMatch->password = password; | - |
39 | } else { executed: } Execution Count:344 | 344 |
40 | QNetworkAuthenticationCredential newCredential; | - |
41 | newCredential.domain = domain; | - |
42 | newCredential.user = user; | - |
43 | newCredential.password = password; | - |
44 | | - |
45 | if (closestMatch) partially evaluated: closestMatch no Evaluation Count:0 | yes Evaluation Count:313 |
| 0-313 |
46 | QVector<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential); never executed: QVector<QNetworkAuthenticationCredential>::insert(++closestMatch, newCredential); | 0 |
47 | else | - |
48 | QVector<QNetworkAuthenticationCredential>::insert(end(), newCredential); executed: QVector<QNetworkAuthenticationCredential>::insert(end(), newCredential); Execution Count:313 | 313 |
49 | } | - |
50 | } | - |
51 | | - |
52 | virtual void dispose() { delete this; } executed: } Execution Count:313 | 313 |
53 | }; | - |
54 | | - |
55 | | - |
56 | static QByteArray proxyAuthenticationKey(const QNetworkProxy &proxy, const QString &realm) | - |
57 | { | - |
58 | QUrl key; | - |
59 | | - |
60 | switch (proxy.type()) { | - |
61 | case QNetworkProxy::Socks5Proxy: | - |
62 | key.setScheme(QLatin1String("proxy-socks5")); | - |
63 | break; executed: break; Execution Count:65 | 65 |
64 | | - |
65 | case QNetworkProxy::HttpProxy: | - |
66 | case QNetworkProxy::HttpCachingProxy: | - |
67 | key.setScheme(QLatin1String("proxy-http")); | - |
68 | break; executed: break; Execution Count:128 | 128 |
69 | | - |
70 | case QNetworkProxy::FtpCachingProxy: | - |
71 | key.setScheme(QLatin1String("proxy-ftp")); | - |
72 | break; | 0 |
73 | | - |
74 | case QNetworkProxy::DefaultProxy: | - |
75 | case QNetworkProxy::NoProxy: | - |
76 | | - |
77 | return QByteArray(); never executed: return QByteArray(); | 0 |
78 | | - |
79 | | - |
80 | | - |
81 | } | - |
82 | | - |
83 | if (key.scheme().isEmpty()) partially evaluated: key.scheme().isEmpty() no Evaluation Count:0 | yes Evaluation Count:193 |
| 0-193 |
84 | | - |
85 | 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 "auth:" + key.toEncoded(); executed: return "auth:" + key.toEncoded(); Execution Count:193 | 193 |
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 "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery); executed: return "auth:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery); Execution Count:604 | 604 |
100 | } | - |
101 | | - |
102 | | - |
103 | | - |
104 | void QNetworkAccessAuthenticationManager::cacheProxyCredentials(const QNetworkProxy &p, | - |
105 | const QAuthenticator *authenticator) | - |
106 | { | - |
107 | qt_noop(); | - |
108 | qt_noop(); | - |
109 | 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()) evaluated: authenticator->password().isNull() yes Evaluation Count:5 | yes Evaluation Count:52 |
| 5-52 |
119 | return; executed: return; Execution Count:5 | 5 |
120 | | - |
121 | | - |
122 | do { | - |
123 | | - |
124 | do { | - |
125 | QByteArray cacheKey = proxyAuthenticationKey(proxy, realm); | - |
126 | if (cacheKey.isEmpty()) partially evaluated: cacheKey.isEmpty() no Evaluation Count:0 | yes Evaluation Count:135 |
| 0-135 |
127 | 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()) { evaluated: realm.isEmpty() yes Evaluation Count:104 | yes Evaluation Count:31 |
| 31-104 |
134 | break; executed: break; Execution Count:104 | 104 |
135 | } else { | - |
136 | realm.clear(); | - |
137 | } executed: } Execution Count:31 | 31 |
138 | } while (true); partially evaluated: true yes Evaluation Count:31 | no Evaluation Count:0 |
| 0-31 |
139 | | - |
140 | if (proxy.user().isEmpty()) evaluated: proxy.user().isEmpty() yes Evaluation Count:52 | yes Evaluation Count:52 |
| 52 |
141 | break; executed: break; Execution Count:52 | 52 |
142 | else | - |
143 | proxy.setUser(QString()); executed: proxy.setUser(QString()); Execution Count:52 | 52 |
144 | } while (true); partially evaluated: true yes Evaluation Count:52 | no Evaluation Count:0 |
| 0-52 |
145 | } executed: } Execution Count:52 | 52 |
146 | | - |
147 | QNetworkAuthenticationCredential | - |
148 | QNetworkAccessAuthenticationManager::fetchCachedProxyCredentials(const QNetworkProxy &p, | - |
149 | const QAuthenticator *authenticator) | - |
150 | { | - |
151 | QNetworkProxy proxy = p; | - |
152 | if (proxy.type() == QNetworkProxy::DefaultProxy) { partially evaluated: proxy.type() == QNetworkProxy::DefaultProxy no Evaluation Count:0 | yes Evaluation Count:58 |
| 0-58 |
153 | proxy = QNetworkProxy::applicationProxy(); | - |
154 | } | 0 |
155 | if (!proxy.password().isEmpty()) partially evaluated: !proxy.password().isEmpty() no Evaluation Count:0 | yes Evaluation Count:58 |
| 0-58 |
156 | return QNetworkAuthenticationCredential(); never executed: return QNetworkAuthenticationCredential(); | 0 |
157 | | - |
158 | QString realm; | - |
159 | if (authenticator) evaluated: authenticator yes Evaluation Count:1 | yes Evaluation Count:57 |
| 1-57 |
160 | realm = authenticator->realm(); executed: realm = authenticator->realm(); Execution Count:1 | 1 |
161 | | - |
162 | QMutexLocker mutexLocker(&mutex); | - |
163 | QByteArray cacheKey = proxyAuthenticationKey(proxy, realm); | - |
164 | if (cacheKey.isEmpty()) partially evaluated: cacheKey.isEmpty() no Evaluation Count:0 | yes Evaluation Count:58 |
| 0-58 |
165 | return QNetworkAuthenticationCredential(); never executed: return QNetworkAuthenticationCredential(); | 0 |
166 | if (!authenticationCache.hasEntry(cacheKey)) evaluated: !authenticationCache.hasEntry(cacheKey) yes Evaluation Count:54 | yes Evaluation Count:4 |
| 4-54 |
167 | return QNetworkAuthenticationCredential(); executed: return QNetworkAuthenticationCredential(); Execution Count:54 | 54 |
168 | | - |
169 | QNetworkAuthenticationCache *auth = | - |
170 | static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey)); | - |
171 | QNetworkAuthenticationCredential cred = *auth->findClosestMatch(QString()); | - |
172 | authenticationCache.releaseEntry(cacheKey); | - |
173 | | - |
174 | | - |
175 | qt_noop(); | - |
176 | | - |
177 | return cred; executed: return cred; Execution Count:4 | 4 |
178 | } | - |
179 | | - |
180 | | - |
181 | | - |
182 | void QNetworkAccessAuthenticationManager::cacheCredentials(const QUrl &url, | - |
183 | const QAuthenticator *authenticator) | - |
184 | { | - |
185 | qt_noop(); | - |
186 | QString domain = QString::fromLatin1("/"); | - |
187 | QString realm = authenticator->realm(); | - |
188 | | - |
189 | QMutexLocker mutexLocker(&mutex); | - |
190 | | - |
191 | | - |
192 | QUrl copy = url; | - |
193 | copy.setUserName(authenticator->user()); | - |
194 | do { | - |
195 | QByteArray cacheKey = authenticationKey(copy, realm); | - |
196 | if (authenticationCache.hasEntry(cacheKey)) { evaluated: authenticationCache.hasEntry(cacheKey) yes Evaluation Count:344 | yes Evaluation Count:178 |
| 178-344 |
197 | QNetworkAuthenticationCache *auth = | - |
198 | static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey)); | - |
199 | auth->insert(domain, authenticator->user(), authenticator->password()); | - |
200 | authenticationCache.releaseEntry(cacheKey); | - |
201 | } else { executed: } Execution Count:344 | 344 |
202 | QNetworkAuthenticationCache *auth = new QNetworkAuthenticationCache; | - |
203 | auth->insert(domain, authenticator->user(), authenticator->password()); | - |
204 | authenticationCache.addEntry(cacheKey, auth); | - |
205 | } executed: } Execution Count:178 | 178 |
206 | | - |
207 | if (copy.userName().isEmpty()) { evaluated: copy.userName().isEmpty() yes Evaluation Count:266 | yes Evaluation Count:256 |
| 256-266 |
208 | break; executed: break; Execution Count:266 | 266 |
209 | } else { | - |
210 | copy.setUserName(QString()); | - |
211 | } executed: } Execution Count:256 | 256 |
212 | } while (true); partially evaluated: true yes Evaluation Count:256 | no Evaluation Count:0 |
| 0-256 |
213 | } executed: } Execution Count:266 | 266 |
214 | QNetworkAuthenticationCredential | - |
215 | QNetworkAccessAuthenticationManager::fetchCachedCredentials(const QUrl &url, | - |
216 | const QAuthenticator *authentication) | - |
217 | { | - |
218 | if (!url.password().isEmpty()) evaluated: !url.password().isEmpty() yes Evaluation Count:4 | yes Evaluation Count:82 |
| 4-82 |
219 | return QNetworkAuthenticationCredential(); executed: return QNetworkAuthenticationCredential(); Execution Count:4 | 4 |
220 | | - |
221 | QString realm; | - |
222 | if (authentication) partially evaluated: authentication yes Evaluation Count:82 | no Evaluation Count:0 |
| 0-82 |
223 | realm = authentication->realm(); executed: realm = authentication->realm(); Execution Count:82 | 82 |
224 | | - |
225 | QByteArray cacheKey = authenticationKey(url, realm); | - |
226 | | - |
227 | QMutexLocker mutexLocker(&mutex); | - |
228 | if (!authenticationCache.hasEntry(cacheKey)) evaluated: !authenticationCache.hasEntry(cacheKey) yes Evaluation Count:55 | yes Evaluation Count:27 |
| 27-55 |
229 | return QNetworkAuthenticationCredential(); executed: return QNetworkAuthenticationCredential(); Execution Count:55 | 55 |
230 | | - |
231 | QNetworkAuthenticationCache *auth = | - |
232 | static_cast<QNetworkAuthenticationCache *>(authenticationCache.requestEntryNow(cacheKey)); | - |
233 | QNetworkAuthenticationCredential *cred = auth->findClosestMatch(url.path()); | - |
234 | QNetworkAuthenticationCredential ret; | - |
235 | if (cred) partially evaluated: cred yes Evaluation Count:27 | no Evaluation Count:0 |
| 0-27 |
236 | ret = *cred; executed: ret = *cred; Execution Count:27 | 27 |
237 | authenticationCache.releaseEntry(cacheKey); | - |
238 | return ret; executed: return ret; Execution Count:27 | 27 |
239 | } | - |
240 | | - |
241 | void QNetworkAccessAuthenticationManager::clearCache() | - |
242 | { | - |
243 | authenticationCache.clear(); | - |
244 | } executed: } Execution Count:1176 | 1176 |
245 | | - |
246 | | - |
247 | | - |
| | |