Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | QNetworkCookieJar::QNetworkCookieJar(QObject *parent) | - |
5 | : QObject(*new QNetworkCookieJarPrivate, parent) | - |
6 | { | - |
7 | } executed: } Execution Count:284 | 284 |
8 | QNetworkCookieJar::~QNetworkCookieJar() | - |
9 | { | - |
10 | } | - |
11 | QList<QNetworkCookie> QNetworkCookieJar::allCookies() const | - |
12 | { | - |
13 | return d_func()->allCookies; executed: return d_func()->allCookies; Execution Count:35 | 35 |
14 | } | - |
15 | void QNetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList) | - |
16 | { | - |
17 | QNetworkCookieJarPrivate * const d = d_func(); | - |
18 | d->allCookies = cookieList; | - |
19 | } executed: } Execution Count:1255 | 1255 |
20 | | - |
21 | static inline bool isParentPath(QString path, QString reference) | - |
22 | { | - |
23 | if (path.startsWith(reference)) { evaluated: path.startsWith(reference) yes Evaluation Count:206 | yes Evaluation Count:44 |
| 44-206 |
24 | | - |
25 | if (path.length() == reference.length()) evaluated: path.length() == reference.length() yes Evaluation Count:24 | yes Evaluation Count:182 |
| 24-182 |
26 | return true; executed: return true; Execution Count:24 | 24 |
27 | | - |
28 | | - |
29 | if (reference.endsWith('/')) evaluated: reference.endsWith('/') yes Evaluation Count:161 | yes Evaluation Count:21 |
| 21-161 |
30 | return true; executed: return true; Execution Count:161 | 161 |
31 | | - |
32 | | - |
33 | | - |
34 | if (path.at(reference.length()) == '/') evaluated: path.at(reference.length()) == '/' yes Evaluation Count:19 | yes Evaluation Count:2 |
| 2-19 |
35 | return true; executed: return true; Execution Count:19 | 19 |
36 | } executed: } Execution Count:2 | 2 |
37 | return false; executed: return false; Execution Count:46 | 46 |
38 | } | - |
39 | | - |
40 | static inline bool isParentDomain(QString domain, QString reference) | - |
41 | { | - |
42 | if (!reference.startsWith(QLatin1Char('.'))) evaluated: !reference.startsWith(QLatin1Char('.')) yes Evaluation Count:437 | yes Evaluation Count:148 |
| 148-437 |
43 | return domain == reference; executed: return domain == reference; Execution Count:437 | 437 |
44 | | - |
45 | return domain.endsWith(reference) || domain == reference.mid(1); executed: return domain.endsWith(reference) || domain == reference.mid(1); Execution Count:148 | 148 |
46 | } | - |
47 | bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, | - |
48 | const QUrl &url) | - |
49 | { | - |
50 | bool added = false; | - |
51 | for (QForeachContainer<__typeof__(cookieList)> _container_(cookieList); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (QNetworkCookie cookie = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
52 | cookie.normalize(url); | - |
53 | if (validateCookie(cookie, url) && insertCookie(cookie)) evaluated: validateCookie(cookie, url) yes Evaluation Count:231 | yes Evaluation Count:22 |
evaluated: insertCookie(cookie) yes Evaluation Count:220 | yes Evaluation Count:11 |
| 11-231 |
54 | added = true; executed: added = true; Execution Count:220 | 220 |
55 | } executed: } Execution Count:253 | 253 |
56 | return added; executed: return added; Execution Count:251 | 251 |
57 | } | - |
58 | QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const | - |
59 | { | - |
60 | | - |
61 | | - |
62 | | - |
63 | | - |
64 | | - |
65 | const QNetworkCookieJarPrivate * const d = d_func(); | - |
66 | QDateTime now = QDateTime::currentDateTime(); | - |
67 | QList<QNetworkCookie> result; | - |
68 | bool isEncrypted = url.scheme().toLower() == QLatin1String("https"); | - |
69 | | - |
70 | | - |
71 | QList<QNetworkCookie>::ConstIterator it = d->allCookies.constBegin(), | - |
72 | end = d->allCookies.constEnd(); | - |
73 | for ( ; it != end; ++it) { evaluated: it != end yes Evaluation Count:270 | yes Evaluation Count:854 |
| 270-854 |
74 | if (!isParentDomain(url.host(), it->domain())) evaluated: !isParentDomain(url.host(), it->domain()) yes Evaluation Count:20 | yes Evaluation Count:250 |
| 20-250 |
75 | continue; executed: continue; Execution Count:20 | 20 |
76 | if (!isParentPath(url.path(), it->path())) evaluated: !isParentPath(url.path(), it->path()) yes Evaluation Count:46 | yes Evaluation Count:204 |
| 46-204 |
77 | continue; executed: continue; Execution Count:46 | 46 |
78 | if (!(*it).isSessionCookie() && (*it).expirationDate() < now) evaluated: !(*it).isSessionCookie() yes Evaluation Count:14 | yes Evaluation Count:190 |
partially evaluated: (*it).expirationDate() < now no Evaluation Count:0 | yes Evaluation Count:14 |
| 0-190 |
79 | continue; never executed: continue; | 0 |
80 | if ((*it).isSecure() && !isEncrypted) evaluated: (*it).isSecure() yes Evaluation Count:18 | yes Evaluation Count:186 |
evaluated: !isEncrypted yes Evaluation Count:16 | yes Evaluation Count:2 |
| 2-186 |
81 | continue; executed: continue; Execution Count:16 | 16 |
82 | | - |
83 | | - |
84 | QList<QNetworkCookie>::Iterator insertIt = result.begin(); | - |
85 | while (insertIt != result.end()) { evaluated: insertIt != result.end() yes Evaluation Count:28 | yes Evaluation Count:178 |
| 28-178 |
86 | if (insertIt->path().length() < it->path().length()) { evaluated: insertIt->path().length() < it->path().length() yes Evaluation Count:10 | yes Evaluation Count:18 |
| 10-18 |
87 | | - |
88 | insertIt = result.insert(insertIt, *it); | - |
89 | break; executed: break; Execution Count:10 | 10 |
90 | } else { | - |
91 | ++insertIt; | - |
92 | } executed: } Execution Count:18 | 18 |
93 | } | - |
94 | | - |
95 | | - |
96 | if (insertIt == result.end()) evaluated: insertIt == result.end() yes Evaluation Count:178 | yes Evaluation Count:10 |
| 10-178 |
97 | result += *it; executed: result += *it; Execution Count:178 | 178 |
98 | } executed: } Execution Count:188 | 188 |
99 | | - |
100 | return result; executed: return result; Execution Count:854 | 854 |
101 | } | - |
102 | bool QNetworkCookieJar::insertCookie(const QNetworkCookie &cookie) | - |
103 | { | - |
104 | QNetworkCookieJarPrivate * const d = d_func(); | - |
105 | QDateTime now = QDateTime::currentDateTime(); | - |
106 | bool isDeletion = !cookie.isSessionCookie() && evaluated: !cookie.isSessionCookie() yes Evaluation Count:27 | yes Evaluation Count:204 |
| 27-204 |
107 | cookie.expirationDate() < now; evaluated: cookie.expirationDate() < now yes Evaluation Count:11 | yes Evaluation Count:16 |
| 11-16 |
108 | | - |
109 | deleteCookie(cookie); | - |
110 | | - |
111 | if (!isDeletion) { evaluated: !isDeletion yes Evaluation Count:220 | yes Evaluation Count:11 |
| 11-220 |
112 | d->allCookies += cookie; | - |
113 | return true; executed: return true; Execution Count:220 | 220 |
114 | } | - |
115 | return false; executed: return false; Execution Count:11 | 11 |
116 | } | - |
117 | bool QNetworkCookieJar::updateCookie(const QNetworkCookie &cookie) | - |
118 | { | - |
119 | if (deleteCookie(cookie)) never evaluated: deleteCookie(cookie) | 0 |
120 | return insertCookie(cookie); never executed: return insertCookie(cookie); | 0 |
121 | return false; never executed: return false; | 0 |
122 | } | - |
123 | bool QNetworkCookieJar::deleteCookie(const QNetworkCookie &cookie) | - |
124 | { | - |
125 | QNetworkCookieJarPrivate * const d = d_func(); | - |
126 | QList<QNetworkCookie>::Iterator it; | - |
127 | for (it = d->allCookies.begin(); it != d->allCookies.end(); it++) evaluated: it != d->allCookies.end() yes Evaluation Count:45 | yes Evaluation Count:224 |
| 45-224 |
128 | if (it->hasSameIdentifier(cookie)) { evaluated: it->hasSameIdentifier(cookie) yes Evaluation Count:7 | yes Evaluation Count:38 |
| 7-38 |
129 | d->allCookies.erase(it); | - |
130 | return true; executed: return true; Execution Count:7 | 7 |
131 | } | - |
132 | return false; executed: return false; Execution Count:224 | 224 |
133 | } | - |
134 | | - |
135 | | - |
136 | | - |
137 | | - |
138 | | - |
139 | | - |
140 | | - |
141 | bool QNetworkCookieJar::validateCookie(const QNetworkCookie &cookie, const QUrl &url) const | - |
142 | { | - |
143 | QString domain = cookie.domain(); | - |
144 | if (!(isParentDomain(domain, url.host()) || isParentDomain(url.host(), domain))) evaluated: isParentDomain(domain, url.host()) yes Evaluation Count:191 | yes Evaluation Count:62 |
evaluated: isParentDomain(url.host(), domain) yes Evaluation Count:47 | yes Evaluation Count:15 |
| 15-191 |
145 | return false; executed: return false; Execution Count:15 | 15 |
146 | | - |
147 | | - |
148 | | - |
149 | | - |
150 | if (qIsEffectiveTLD(domain.startsWith('.') ? domain.remove(0, 1) : domain)) evaluated: qIsEffectiveTLD(domain.startsWith('.') ? domain.remove(0, 1) : domain) yes Evaluation Count:7 | yes Evaluation Count:231 |
| 7-231 |
151 | return false; executed: return false; Execution Count:7 | 7 |
152 | | - |
153 | return true; executed: return true; Execution Count:231 | 231 |
154 | } | - |
155 | | - |
156 | | - |
157 | | - |
| | |