Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkcookiejar.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||||||||
2 | - | |||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | QNetworkCookieJar::QNetworkCookieJar(QObject *parent) | - | ||||||||||||||||||||||||
5 | : QObject(*new QNetworkCookieJarPrivate, parent) | - | ||||||||||||||||||||||||
6 | { | - | ||||||||||||||||||||||||
7 | } | - | ||||||||||||||||||||||||
8 | QNetworkCookieJar::~QNetworkCookieJar() | - | ||||||||||||||||||||||||
9 | { | - | ||||||||||||||||||||||||
10 | } | - | ||||||||||||||||||||||||
11 | QList<QNetworkCookie> QNetworkCookieJar::allCookies() const | - | ||||||||||||||||||||||||
12 | { | - | ||||||||||||||||||||||||
13 | return d_func()->allCookies; | - | ||||||||||||||||||||||||
14 | } | - | ||||||||||||||||||||||||
15 | void QNetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList) | - | ||||||||||||||||||||||||
16 | { | - | ||||||||||||||||||||||||
17 | QNetworkCookieJarPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
18 | d->allCookies = cookieList; | - | ||||||||||||||||||||||||
19 | } | - | ||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||
21 | static inline bool isParentPath(const QString &path, const QString &reference) | - | ||||||||||||||||||||||||
22 | { | - | ||||||||||||||||||||||||
23 | if (path.startsWith(reference)) { | - | ||||||||||||||||||||||||
24 | - | |||||||||||||||||||||||||
25 | if (path.length() == reference.length()) | - | ||||||||||||||||||||||||
26 | return true; | - | ||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||
28 | - | |||||||||||||||||||||||||
29 | if (reference.endsWith('/')) | - | ||||||||||||||||||||||||
30 | return true; | - | ||||||||||||||||||||||||
31 | - | |||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | if (path.at(reference.length()) == '/') | - | ||||||||||||||||||||||||
35 | return true; | - | ||||||||||||||||||||||||
36 | } | - | ||||||||||||||||||||||||
37 | return false; | - | ||||||||||||||||||||||||
38 | } | - | ||||||||||||||||||||||||
39 | - | |||||||||||||||||||||||||
40 | static inline bool isParentDomain(const QString &domain, const QString &reference) | - | ||||||||||||||||||||||||
41 | { | - | ||||||||||||||||||||||||
42 | if (!reference.startsWith(QLatin1Char('.'))
| 149-439 | ||||||||||||||||||||||||
43 | return executed 439 times by 2 tests: domain == reference;return domain == reference; Executed by:
executed 439 times by 2 tests: return domain == reference; Executed by:
| 439 | ||||||||||||||||||||||||
44 | - | |||||||||||||||||||||||||
45 | return executed 149 times by 2 tests: domain.endsWith(reference) || domain == reference.midmidRef(1);return domain.endsWith(reference) || domain == reference.midRef(1); Executed by:
executed 149 times by 2 tests: return domain.endsWith(reference) || domain == reference.midRef(1); Executed by:
| 149 | ||||||||||||||||||||||||
46 | } | - | ||||||||||||||||||||||||
47 | bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, | - | ||||||||||||||||||||||||
48 | const QUrl &url) | - | ||||||||||||||||||||||||
49 | { | - | ||||||||||||||||||||||||
50 | bool added = false; | - | ||||||||||||||||||||||||
for (QForeachContainer<typename QtPrivate::remove_reference<decltype(cookieList)>::type> _container_((cookieList)); _container_.control && _container_.i != _container_.e; | ||||||||||||||||||||||||||
51 | ++_container_.i, _container_.control ^= 1)for (QNetworkCookie cookie = *_container_.i; _container_.control; _container_.control = 0: cookieList) { | - | ||||||||||||||||||||||||
52 | cookie.normalize(url); | - | ||||||||||||||||||||||||
53 | if (validateCookie(cookie, url)
| 12-234 | ||||||||||||||||||||||||
54 | added = true; executed 222 times by 2 tests: added = true; Executed by:
| 222 | ||||||||||||||||||||||||
55 | } executed 256 times by 2 tests: end of block Executed by:
| 256 | ||||||||||||||||||||||||
56 | return executed 254 times by 2 tests: added;return added; Executed by:
executed 254 times by 2 tests: return added; Executed by:
| 254 | ||||||||||||||||||||||||
57 | } | - | ||||||||||||||||||||||||
58 | QList<QNetworkCookie> QNetworkCookieJar::cookiesForUrl(const QUrl &url) const | - | ||||||||||||||||||||||||
59 | { | - | ||||||||||||||||||||||||
60 | - | |||||||||||||||||||||||||
61 | - | |||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | - | |||||||||||||||||||||||||
65 | const QNetworkCookieJarPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
66 | const QDateTime now = QDateTime::currentDateTimeUtc(); | - | ||||||||||||||||||||||||
67 | QList<QNetworkCookie> result; | - | ||||||||||||||||||||||||
68 | bool isEncrypted = url.scheme() == QLatin1String("https"); | - | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||
71 | QList<QNetworkCookie>::ConstIterator it = d->allCookies.constBegin(), | - | ||||||||||||||||||||||||
72 | end = d->allCookies.constEnd(); | - | ||||||||||||||||||||||||
73 | for ( ; it != end; ++it) { | - | ||||||||||||||||||||||||
74 | if (!isParentDomain(url.host(), it->domain())) | - | ||||||||||||||||||||||||
75 | continue; | - | ||||||||||||||||||||||||
76 | if (!isParentPath(url.path(), it->path())) | - | ||||||||||||||||||||||||
77 | continue; | - | ||||||||||||||||||||||||
78 | if (!(*it).isSessionCookie() && (*it).expirationDate() < now) | - | ||||||||||||||||||||||||
79 | continue; | - | ||||||||||||||||||||||||
80 | if ((*it).isSecure() && !isEncrypted) | - | ||||||||||||||||||||||||
81 | continue; | - | ||||||||||||||||||||||||
82 | - | |||||||||||||||||||||||||
83 | - | |||||||||||||||||||||||||
84 | QList<QNetworkCookie>::Iterator insertIt = result.begin(); | - | ||||||||||||||||||||||||
85 | while (insertIt != result.end()) { | - | ||||||||||||||||||||||||
86 | if (insertIt->path().length() < it->path().length()) { | - | ||||||||||||||||||||||||
87 | - | |||||||||||||||||||||||||
88 | insertIt = result.insert(insertIt, *it); | - | ||||||||||||||||||||||||
89 | break; | - | ||||||||||||||||||||||||
90 | } else { | - | ||||||||||||||||||||||||
91 | ++insertIt; | - | ||||||||||||||||||||||||
92 | } | - | ||||||||||||||||||||||||
93 | } | - | ||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | if (insertIt == result.end()) | - | ||||||||||||||||||||||||
97 | result += *it; | - | ||||||||||||||||||||||||
98 | } | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | return result; | - | ||||||||||||||||||||||||
101 | } | - | ||||||||||||||||||||||||
102 | bool QNetworkCookieJar::insertCookie(const QNetworkCookie &cookie) | - | ||||||||||||||||||||||||
103 | { | - | ||||||||||||||||||||||||
104 | QNetworkCookieJarPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
105 | const QDateTime now = QDateTime::currentDateTimeUtc(); | - | ||||||||||||||||||||||||
106 | bool isDeletion = !cookie.isSessionCookie() && | - | ||||||||||||||||||||||||
107 | cookie.expirationDate() < now; | - | ||||||||||||||||||||||||
108 | - | |||||||||||||||||||||||||
109 | deleteCookie(cookie); | - | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | if (!isDeletion) { | - | ||||||||||||||||||||||||
112 | d->allCookies += cookie; | - | ||||||||||||||||||||||||
113 | return true; | - | ||||||||||||||||||||||||
114 | } | - | ||||||||||||||||||||||||
115 | return false; | - | ||||||||||||||||||||||||
116 | } | - | ||||||||||||||||||||||||
117 | bool QNetworkCookieJar::updateCookie(const QNetworkCookie &cookie) | - | ||||||||||||||||||||||||
118 | { | - | ||||||||||||||||||||||||
119 | if (deleteCookie(cookie)) | - | ||||||||||||||||||||||||
120 | return insertCookie(cookie); | - | ||||||||||||||||||||||||
121 | return false; | - | ||||||||||||||||||||||||
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) { | - | ||||||||||||||||||||||||
128 | if (it->hasSameIdentifier(cookie)) { | - | ||||||||||||||||||||||||
129 | d->allCookies.erase(it); | - | ||||||||||||||||||||||||
130 | return true; | - | ||||||||||||||||||||||||
131 | } | - | ||||||||||||||||||||||||
132 | } | - | ||||||||||||||||||||||||
133 | return false; | - | ||||||||||||||||||||||||
134 | } | - | ||||||||||||||||||||||||
135 | - | |||||||||||||||||||||||||
136 | - | |||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||
138 | - | |||||||||||||||||||||||||
139 | - | |||||||||||||||||||||||||
140 | - | |||||||||||||||||||||||||
141 | - | |||||||||||||||||||||||||
142 | bool QNetworkCookieJar::validateCookie(const QNetworkCookie &cookie, const QUrl &url) const | - | ||||||||||||||||||||||||
143 | { | - | ||||||||||||||||||||||||
144 | QString domain = cookie.domain(); | - | ||||||||||||||||||||||||
145 | const QString host = url.host(); | - | ||||||||||||||||||||||||
146 | if (!((!
| 15-193 | ||||||||||||||||||||||||
147 | return executed 15 times by 2 tests: false;return false; Executed by:
executed 15 times by 2 tests: return false; Executed by:
| 15 | ||||||||||||||||||||||||
148 | - | |||||||||||||||||||||||||
149 | - | |||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | if (qIsEffectiveTLD(domain.startsWith('.') ? domain.remove(0, 1) : domain)
| 7-234 | ||||||||||||||||||||||||
153 | return executed 7 times by 1 test: false;return false; Executed by:
executed 7 times by 1 test: return false; Executed by:
| 7 | ||||||||||||||||||||||||
154 | - | |||||||||||||||||||||||||
155 | return executed 234 times by 2 tests: true;return true; Executed by:
executed 234 times by 2 tests: return true; Executed by:
| 234 | ||||||||||||||||||||||||
156 | } | - | ||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||
158 | - | |||||||||||||||||||||||||
Switch to Source code | Preprocessed file |