| 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 | } executed 285 times by 1 test: end of blockExecuted by:
| 285 | ||||||||||||||||||
| 8 | QNetworkCookieJar::~QNetworkCookieJar() | - | ||||||||||||||||||
| 9 | { | - | ||||||||||||||||||
| 10 | } | - | ||||||||||||||||||
| 11 | QList<QNetworkCookie> QNetworkCookieJar::allCookies() const | - | ||||||||||||||||||
| 12 | { | - | ||||||||||||||||||
| 13 | return executed 37 times by 2 tests: d_func()->allCookies;return d_func()->allCookies;Executed by:
executed 37 times by 2 tests: return d_func()->allCookies;Executed by:
| 37 | ||||||||||||||||||
| 14 | } | - | ||||||||||||||||||
| 15 | void QNetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList) | - | ||||||||||||||||||
| 16 | { | - | ||||||||||||||||||
| 17 | QNetworkCookieJarPrivate * const d = d_func(); | - | ||||||||||||||||||
| 18 | d->allCookies = cookieList; | - | ||||||||||||||||||
| 19 | } executed 719 times by 2 tests: end of blockExecuted by:
| 719 | ||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | static inline bool isParentPath(const QString &path, const QString &reference) | - | ||||||||||||||||||
| 22 | { | - | ||||||||||||||||||
| 23 | if (path.startsWith(reference)
| 44-205 | ||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | if (path.length() == reference.length()
| 24-181 | ||||||||||||||||||
| 26 | return executed 24 times by 1 test: true;return true;Executed by:
executed 24 times by 1 test: return true;Executed by:
| 24 | ||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | if (reference.endsWith('/')
| 21-160 | ||||||||||||||||||
| 30 | return executed 160 times by 2 tests: true;return true;Executed by:
executed 160 times by 2 tests: return true;Executed by:
| 160 | ||||||||||||||||||
| 31 | - | |||||||||||||||||||
| 32 | - | |||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | if (path.at(reference.length()) == '/'
| 2-19 | ||||||||||||||||||
| 35 | return executed 19 times by 2 tests: true;return true;Executed by:
executed 19 times by 2 tests: return true;Executed by:
| 19 | ||||||||||||||||||
| 36 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 37 | return executed 46 times by 2 tests: false;return false;Executed by:
executed 46 times by 2 tests: return false;Executed by:
| 46 | ||||||||||||||||||
| 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.midRef(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; | - | ||||||||||||||||||
| 51 | for (QNetworkCookie cookie : 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 blockExecuted 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
| 269-911 | ||||||||||||||||||
| 74 | if (!isParentDomain(url.host(), it->domain())
| 20-249 | ||||||||||||||||||
| 75 | continue; executed 20 times by 2 tests: continue;Executed by:
| 20 | ||||||||||||||||||
| 76 | if (!isParentPath(url.path(), it->path())
| 46-203 | ||||||||||||||||||
| 77 | continue; executed 46 times by 2 tests: continue;Executed by:
| 46 | ||||||||||||||||||
| 78 | if (!(*it).isSessionCookie()
| 0-190 | ||||||||||||||||||
| 79 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 80 | if ((*
| 2-185 | ||||||||||||||||||
| 81 | continue; executed 16 times by 1 test: continue;Executed by:
| 16 | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | QList<QNetworkCookie>::Iterator insertIt = result.begin(); | - | ||||||||||||||||||
| 85 | while (insertIt != result.end()
| 28-177 | ||||||||||||||||||
| 86 | if (insertIt->path().length() < it->path().length()
| 10-18 | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | insertIt = result.insert(insertIt, *it); | - | ||||||||||||||||||
| 89 | break; executed 10 times by 2 tests: break;Executed by:
| 10 | ||||||||||||||||||
| 90 | } else { | - | ||||||||||||||||||
| 91 | ++insertIt; | - | ||||||||||||||||||
| 92 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||||||||||||||
| 93 | } | - | ||||||||||||||||||
| 94 | - | |||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | if (insertIt == result.end()
| 10-177 | ||||||||||||||||||
| 97 | result += *it; executed 177 times by 2 tests: result += *it;Executed by:
| 177 | ||||||||||||||||||
| 98 | } executed 187 times by 2 tests: end of blockExecuted by:
| 187 | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | return executed 911 times by 2 tests: result;return result;Executed by:
executed 911 times by 2 tests: return result;Executed by:
| 911 | ||||||||||||||||||
| 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()
| 28-206 | ||||||||||||||||||
| 107 | cookie.expirationDate() < now
| 12-16 | ||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | deleteCookie(cookie); | - | ||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | if (!isDeletion
| 12-222 | ||||||||||||||||||
| 112 | d->allCookies += cookie; | - | ||||||||||||||||||
| 113 | return executed 222 times by 2 tests: true;return true;Executed by:
executed 222 times by 2 tests: return true;Executed by:
| 222 | ||||||||||||||||||
| 114 | } | - | ||||||||||||||||||
| 115 | return executed 12 times by 1 test: false;return false;Executed by:
executed 12 times by 1 test: return false;Executed by:
| 12 | ||||||||||||||||||
| 116 | } | - | ||||||||||||||||||
| 117 | bool QNetworkCookieJar::updateCookie(const QNetworkCookie &cookie) | - | ||||||||||||||||||
| 118 | { | - | ||||||||||||||||||
| 119 | if (deleteCookie(cookie)
| 0 | ||||||||||||||||||
| 120 | return never executed: insertCookie(cookie);return insertCookie(cookie);never executed: return insertCookie(cookie); | 0 | ||||||||||||||||||
| 121 | return never executed: false;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()
| 45-227 | ||||||||||||||||||
| 128 | if (it->hasSameIdentifier(cookie)
| 7-38 | ||||||||||||||||||
| 129 | d->allCookies.erase(it); | - | ||||||||||||||||||
| 130 | return executed 7 times by 1 test: true;return true;Executed by:
executed 7 times by 1 test: return true;Executed by:
| 7 | ||||||||||||||||||
| 131 | } | - | ||||||||||||||||||
| 132 | } executed 38 times by 2 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||
| 133 | return executed 227 times by 2 tests: false;return false;Executed by:
executed 227 times by 2 tests: return false;Executed by:
| 227 | ||||||||||||||||||
| 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 (!isParentDomain(domain, host)
| 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 |