qnetworkcookiejar.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkcookiejar.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4QNetworkCookieJar::QNetworkCookieJar(QObject *parent)-
5 : QObject(*new QNetworkCookieJarPrivate, parent)-
6{-
7}-
8QNetworkCookieJar::~QNetworkCookieJar()-
9{-
10}-
11QList<QNetworkCookie> QNetworkCookieJar::allCookies() const-
12{-
13 return d_func()->allCookies;-
14}-
15void QNetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList)-
16{-
17 QNetworkCookieJarPrivate * const d = d_func();-
18 d->allCookies = cookieList;-
19}-
20-
21static 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-
40static inline bool isParentDomain(const QString &domain, const QString &reference)-
41{-
42 if (!reference.startsWith(QLatin1Char('.'))
!reference.sta...tin1Char('.'))Description
TRUEevaluated 439 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 149 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
)
149-439
43 return
executed 439 times by 2 tests: return domain == reference;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
domain == reference;
executed 439 times by 2 tests: return domain == reference;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
439
44-
45 return
executed 149 times by 2 tests: return domain.endsWith(reference) || domain == reference.midRef(1);
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
domain.endsWith(reference) || domain == reference.midmidRef(1);
executed 149 times by 2 tests: return domain.endsWith(reference) || domain == reference.midRef(1);
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
149
46}-
47bool 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)
validateCookie(cookie, url)Description
TRUEevaluated 234 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 22 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
&& insertCookie(cookie)
insertCookie(cookie)Description
TRUEevaluated 222 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_qnetworkcookiejar - unknown status
)
12-234
54 added = true;
executed 222 times by 2 tests: added = true;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
222
55 }
executed 256 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
256
56 return
executed 254 times by 2 tests: return added;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
added;
executed 254 times by 2 tests: return added;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
254
57}-
58QList<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}-
102bool 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}-
117bool QNetworkCookieJar::updateCookie(const QNetworkCookie &cookie)-
118{-
119 if (deleteCookie(cookie))-
120 return insertCookie(cookie);-
121 return false;-
122}-
123bool 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-
142bool QNetworkCookieJar::validateCookie(const QNetworkCookie &cookie, const QUrl &url) const-
143{-
144 QString domain = cookie.domain();-
145 const QString host = url.host();-
146 if (!((!
!isParentDomain(domain, host)Description
TRUEevaluated 63 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 193 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
isParentDomain(domain, url.host()) ||)
!isParentDomain(domain, host)Description
TRUEevaluated 63 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 193 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
&& !
!isParentDomain(host, domain)Description
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 48 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
isParentDomain(url.host(),, domain))))
!isParentDomain(host, domain)Description
TRUEevaluated 15 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 48 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
)
15-193
147 return
executed 15 times by 2 tests: return false;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
false;
executed 15 times by 2 tests: return false;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
15
148-
149-
150-
151-
152 if (qIsEffectiveTLD(domain.startsWith('.') ? domain.remove(0, 1) : domain)
qIsEffectiveTL..., 1) : domain)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • tst_qnetworkcookiejar - unknown status
FALSEevaluated 234 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
)
7-234
153 return
executed 7 times by 1 test: return false;
Executed by:
  • tst_qnetworkcookiejar - unknown status
false;
executed 7 times by 1 test: return false;
Executed by:
  • tst_qnetworkcookiejar - unknown status
7
154-
155 return
executed 234 times by 2 tests: return true;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
true;
executed 234 times by 2 tests: return true;
Executed by:
  • tst_QNetworkReply
  • tst_qnetworkcookiejar - unknown status
234
156}-
157-
158-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9