QNetworkReply * Pillow::ElasticNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData) { // Find the first available child QNetworkAccessManager. QNetworkAccessManager* nam = NULL; foreach (QObject* child, children()) { if ((nam = qobject_cast<QNetworkAccessManager*>(child))) { if (nam->children().size() < 6) break; // Found an available one. else nam = NULL; // This one is not available. } } if (nam == NULL) { // Did not find an available manager. Spawn a new one. nam = new QNetworkAccessManager(this); if (cookieJar()) { nam->setCookieJar(cookieJar()); cookieJar()->setParent(0); } } return static_cast<NamOpener*>(nam)->doCreateRequest(op, request, outgoingData); }
QNetworkReply* KVNetworkAccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData) { QNetworkRequest request = req; request.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0"); if(op == PostOperation) { //qDebug() << "POST" << request.url().path(); // If the request addressed to API - translate this request if(request.url().host() != "localhost" && request.url().host() != "127.0.0.1" && !request.url().host().contains(".dmm.com")) { QNetworkReply *r = QNetworkAccessManager::createRequest(op, request, outgoingData); KVNetworkReply *reply = new KVNetworkReply(r->parent(), r, this, translation); return reply; } } else if(op == GetOperation) { // If the request addressed to DMM - create hacked cookies if(request.url().host().contains(".dmm.com")) { QNetworkCookie languageCookie; languageCookie.setDomain(".dmm.com"); languageCookie.setPath("/"); languageCookie.setName("cklg"); languageCookie.setValue("ja"); languageCookie.setExpirationDate(QDateTime::currentDateTime().addYears(1)); QNetworkCookie locationCookie; locationCookie.setDomain(".dmm.com"); locationCookie.setPath("/"); locationCookie.setName("ckcy"); locationCookie.setValue("1"); locationCookie.setExpirationDate(QDateTime::currentDateTime().addYears(1)); if(cookieHack) { cookieJar()->insertCookie(languageCookie); cookieJar()->insertCookie(locationCookie); } else { cookieJar()->deleteCookie(languageCookie); cookieJar()->deleteCookie(locationCookie); } } } QNetworkReply *reply = QNetworkAccessManager::createRequest(op, request, outgoingData); // If the request if for an SWF or MP3 file, track it and report progress if(req.url().path().endsWith(".swf") || req.url().path().endsWith(".mp3")) { connect(reply, SIGNAL(metaDataChanged()), this, SLOT(trackedGETMetaDataChanged())); connect(reply, SIGNAL(readyRead()), this, SLOT(trackedGETReadyRead())); connect(reply, SIGNAL(finished()), this, SLOT(trackedGETFinished())); } return reply; }
CookieJar* CookieJar::clone(QObject *parent) { CookieJar *cookieJar(new CookieJar(m_isPrivate, parent)); cookieJar->setAllCookies(allCookies()); return cookieJar; }
String cookies(const Document* document, const KURL& url) { QUrl u(url); #if QT_VERSION >= 0x040400 QNetworkCookieJar* jar = cookieJar(document); if (!jar) return String(); QList<QNetworkCookie> cookies = jar->cookiesForUrl(u); if (cookies.isEmpty()) return String(); QStringList resultCookies; foreach (QNetworkCookie networkCookie, cookies) { #if QT_VERSION >= 0x040500 if (networkCookie.isHttpOnly()) continue; #endif resultCookies.append(QString::fromAscii( networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData())); } return resultCookies.join(QLatin1String("; ")); #else QString cookies = QCookieJar::cookieJar()->cookies(u); int idx = cookies.indexOf(QLatin1Char(';')); if (idx > 0) cookies = cookies.left(idx); return cookies; #endif }
String CookieManager::getCookie(const KURL& url, CookieFilter filter) const { // If the database hasn't been sync-ed at this point, force a sync load if (!m_syncedWithDatabase && !m_privateMode) m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar()); Vector<RefPtr<ParsedCookie> > rawCookies; rawCookies.reserveInitialCapacity(s_maxCookieCountPerHost); // Retrieve cookies related to this url getRawCookies(rawCookies, url, filter); CookieLog("CookieManager - there are %d cookies in raw cookies\n", rawCookies.size()); // Generate the cookie header string using the retrieved cookies StringBuilder cookieStringBuilder; cookieStringBuilder.reserveCapacity(512); size_t cookieSize = rawCookies.size(); for (size_t i = 0; i < cookieSize; i++) { cookieStringBuilder.append(rawCookies[i]->toNameValuePair()); if (i != cookieSize-1) cookieStringBuilder.append("; "); } CookieLog("CookieManager - cookieString is - %s\n", cookieStringBuilder.toString().utf8().data()); return cookieStringBuilder.toString(); }
boost::shared_ptr<HootNetworkCookieJar> NetworkIoUtils::getUserSessionCookie( const QString userName, const QString accessToken, const QString accessTokenSecret, const QString url) { LOG_VART(userName); LOG_VART(accessToken); LOG_VART(url); HootApiDb db; LOG_VART(HootApiDb::getBaseUrl()); //hoot db requires a layer to open, but we don't need one here...so put anything in QUrl dbUrl(HootApiDb::getBaseUrl().toString() + "/blah"); db.open(dbUrl); const QString sessionId = db.getSessionIdByAccessTokens(userName, accessToken, accessTokenSecret); LOG_VART(sessionId); db.close(); if (sessionId.isEmpty()) { throw HootException("User: "******" has not been authenticated."); } boost::shared_ptr<HootNetworkCookieJar> cookieJar(new HootNetworkCookieJar()); QList<QNetworkCookie> cookies; QNetworkCookie sessionCookie(QString("SESSION").toUtf8(), sessionId.toUtf8()); cookies.append(sessionCookie); cookieJar->setCookiesFromUrl(cookies, url); LOG_VART(cookieJar->size()); LOG_VART(cookieJar->toString()); return cookieJar; }
bool cookiesEnabled(const Document* document) { #if QT_VERSION >= 0x040400 QNetworkCookieJar* jar = cookieJar(document); return (jar != 0); #else return QCookieJar::cookieJar()->isEnabled(); #endif }
CookieManager::CookieManager() : m_count(0) { m_cookieJarFileName = pathByAppendingComponent(OWB_DATA, "cookieCollection.db"); // We force the cookie backing store to be open with the cookie jar to avoid // calling cookieManager() again and recursively calling this constructor. cookieBackingStore().open(cookieJar()); getBackingStoreCookies(); }
void AccessManager::setRawCookie(const QByteArray &rawCookie, const QUrl &url) { QNetworkCookie cookie(rawCookie.left(rawCookie.indexOf('=')), rawCookie.mid(rawCookie.indexOf('=')+1)); qDebug() << Q_FUNC_INFO << cookie.name() << cookie.value(); QList<QNetworkCookie> cookieList; cookieList.append(cookie); QNetworkCookieJar *jar = cookieJar(); jar->setCookiesFromUrl(cookieList, url); }
bool thirdPartyCookiePolicyPermitsForFrame(QObject* originatingFrame, const QUrl& url, const QUrl& firstPartyUrl) { #if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) QNetworkCookieJar* jar = cookieJar(originatingFrame); if (!jar) return true; return thirdPartyCookiePolicyPermits(jar, url, firstPartyUrl); #else return true; #endif }
void CookieManager::setCookies(const KURL& url, const Vector<String>& cookies, CookieFilter filter) { // If the database hasn't been sync-ed at this point, force a sync load if (!m_syncedWithDatabase && !m_privateMode) m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar()); CookieLog("CookieManager - Setting cookies"); CookieParser parser(url); for (size_t i = 0; i < cookies.size(); ++i) { BackingStoreRemovalPolicy treatment = m_privateMode ? DoNotRemoveFromBackingStore : RemoveFromBackingStore; if (RefPtr<ParsedCookie> parsedCookie = parser.parseOneCookie(cookies[i])) checkAndTreatCookie(parsedCookie, treatment, filter); } }
void setCookies(Document* document, const KURL& url, const KURL& policyURL, const String& value) { QUrl u(url); QUrl p(policyURL); #if QT_VERSION >= 0x040400 QNetworkCookieJar* jar = cookieJar(document); if (!jar) return; QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(QString(value).toAscii()); jar->setCookiesFromUrl(cookies, p); #else QCookieJar::cookieJar()->setCookies(u, p, (QString)value); #endif }
String cookieRequestHeaderFieldValue(const Document* document, const KURL &url) { QUrl u(url); QNetworkCookieJar* jar = cookieJar(document); if (!jar) return String(); QList<QNetworkCookie> cookies = jar->cookiesForUrl(u); if (cookies.isEmpty()) return String(); QStringList resultCookies; foreach (QNetworkCookie networkCookie, cookies) { resultCookies.append(QString::fromAscii( networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData())); }
void LegacyUpdate::lwjglFinished(QNetworkReply *reply) { if (m_reply.get() != reply) { return; } if (reply->error() != QNetworkReply::NoError) { emitFailed("Failed to download: " + reply->errorString() + "\nSometimes you have to wait a bit if you download many LWJGL versions in " "a row. YMMV"); return; } auto worker = MMC->qnam(); // Here i check if there is a cookie for me in the reply and extract it QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie>>(reply->header(QNetworkRequest::SetCookieHeader)); if (cookies.count() != 0) { // you must tell which cookie goes with which url worker->cookieJar()->setCookiesFromUrl(cookies, QUrl("sourceforge.net")); } // here you can check for the 302 or whatever other header i need QVariant newLoc = reply->header(QNetworkRequest::LocationHeader); if (newLoc.isValid()) { QString redirectedTo = reply->header(QNetworkRequest::LocationHeader).toString(); QUrl realUrl(redirectedTo); QString hostname = realUrl.host(); QNetworkRequest req(redirectedTo); req.setRawHeader("Host", hostname.toLatin1()); req.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Cached)"); QNetworkReply *rep = worker->get(req); connect(rep, SIGNAL(downloadProgress(qint64, qint64)), SIGNAL(progress(qint64, qint64))); m_reply = std::shared_ptr<QNetworkReply>(rep); return; } QFile saveMe("lwjgl.zip"); saveMe.open(QIODevice::WriteOnly); saveMe.write(m_reply->readAll()); saveMe.close(); setStatus(tr("Installing new LWJGL...")); extractLwjgl(); jarStart(); }
void NetworkAccessManagerProxy::setPrimaryNetworkAccessManager(NetworkAccessManagerProxy *manager) { Q_ASSERT(manager); m_primaryManager = manager; setCookieJar(m_primaryManager->cookieJar()); // Do not steal ownership! cookieJar()->setParent(manager); connect(this, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), m_primaryManager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*))); connect(this, SIGNAL(finished(QNetworkReply *)), m_primaryManager, SIGNAL(finished(QNetworkReply *))); connect(this, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), m_primaryManager, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); #ifndef QT_NO_OPENSSL connect(this, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), m_primaryManager, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&))); #endif }
int ZnsHelper::processLoginReply(QNetworkReply* reply) { if (parseReply(reply) != 0){ return -1; } int returnValue = -1; QVariant cookiesContainer = reply->header(QNetworkRequest::SetCookieHeader); QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(cookiesContainer); if (m_replyData.endsWith("submitted=true")) { cookieJar()->setCookiesFromUrl(cookies, m_apiBaseUrl); m_isLogged = true; returnValue = 0; } else { if (checkRPCResultStatus()) { returnValue = 0; } } return returnValue; }
String cookies(const Document* document, const KURL& url) { QUrl u(url); QNetworkCookieJar* jar = cookieJar(document); if (!jar) return String(); QList<QNetworkCookie> cookies = jar->cookiesForUrl(u); if (cookies.isEmpty()) return String(); QStringList resultCookies; foreach (QNetworkCookie networkCookie, cookies) { if (networkCookie.isHttpOnly()) continue; resultCookies.append(QString::fromAscii( networkCookie.toRawForm(QNetworkCookie::NameAndValueOnly).constData())); } return resultCookies.join(QLatin1String("; ")); }
String CookieManager::generateHtmlFragmentForCookies() { // If the database hasn't been sync-ed at this point, force a sync load if (!m_syncedWithDatabase && !m_privateMode) m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar()); CookieLog("CookieManager - generateHtmlFragmentForCookies\n"); Vector<RefPtr<ParsedCookie> > cookieCandidates; for (HashMap<String, CookieMap*>::iterator it = m_managerMap.begin(); it != m_managerMap.end(); ++it) it->value->getAllChildCookies(&cookieCandidates); String result; RefPtr<ParsedCookie> cookie = 0; result.append(String("<table style=\"word-wrap:break-word\" cellSpacing=\"0\" cellPadding=\"0\" border=\"1\"><tr><th>Domain</th><th>Path</th><th>Protocol</th><th>Name</th><th>Value</th><th>Secure</th><th>HttpOnly</th><th>Session</th></tr>")); for (size_t i = 0; i < cookieCandidates.size(); ++i) { cookie = cookieCandidates[i]; result.append(String("<tr><td align=\"center\">")); result.append(cookie->domain()); result.append(String("<td align=\"center\">")); result.append(cookie->path()); result.append(String("<td align=\"center\">")); result.append(cookie->protocol()); result.append(String("<td align=\"center\">")); result.append(cookie->name()); result.append(String("<td align=\"center\" style= \"word-break:break-all\">")); result.append(cookie->value()); result.append(String("<td align=\"center\">")); result.append(String(cookie->isSecure() ? "Yes" : "No")); result.append(String("<td align=\"center\">")); result.append(String(cookie->isHttpOnly() ? "Yes" : "No")); result.append(String("<td align=\"center\">")); result.append(String(cookie->isSession() ? "Yes" : "No")); result.append(String("</td></tr>")); } result.append(String("</table>")); return result; }
void setCookies(Document* document, const KURL& url, const KURL& policyURL, const String& value) { QUrl u(url); QUrl p(policyURL); #if QT_VERSION >= 0x040400 QNetworkCookieJar* jar = cookieJar(document); if (!jar) return; QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(QString(value).toAscii()); #if QT_VERSION >= 0x040500 QList<QNetworkCookie>::Iterator it = cookies.begin(); while (it != cookies.end()) { if (it->isHttpOnly()) it = cookies.erase(it); else ++it; } #endif jar->setCookiesFromUrl(cookies, p); #else QCookieJar::cookieJar()->setCookies(u, p, (QString)value); #endif }
Pillow::ElasticNetworkAccessManager::~ElasticNetworkAccessManager() { if (cookieJar()) cookieJar()->setParent(this); }
void CookieManager::getRawCookies(Vector<RefPtr<ParsedCookie> > &stackOfCookies, const KURL& requestURL, CookieFilter filter) const { // Force a sync load of the database if (!m_syncedWithDatabase && !m_privateMode) m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar()); CookieLog("CookieManager - getRawCookies - processing url with domain - %s & protocol: %s & path: %s\n", requestURL.host().utf8().data(), requestURL.protocol().utf8().data(), requestURL.path().utf8().data()); const bool invalidScheme = shouldIgnoreScheme(requestURL.protocol()); const bool specialCaseForWebWorks = invalidScheme && m_shouldDumpAllCookies; const bool isConnectionSecure = requestURL.protocolIs("https") || requestURL.protocolIs("wss") || specialCaseForWebWorks; Vector<RefPtr<ParsedCookie> > cookieCandidates; Vector<CookieMap*> protocolsToSearch; // Special Case: If a server sets a "secure" cookie over a non-secure channel and tries to access the cookie // over a secure channel, it will not succeed because the secure protocol isn't mapped to the insecure protocol yet. // Set the map to the non-secure version, so it'll search the mapping for a secure cookie. CookieMap* targetMap = m_managerMap.get(requestURL.protocol()); if (!targetMap && isConnectionSecure) { CookieLog("CookieManager - special case: secure protocol are not linked yet."); if (requestURL.protocolIs("https")) targetMap = m_managerMap.get("http"); else if (requestURL.protocolIs("wss")) targetMap = m_managerMap.get("ws"); } // Decide which scheme tree we should look at. // Return on invalid schemes. cookies are currently disabled on file and local. // We only want to enable them for WebWorks that enabled a special flag. if (specialCaseForWebWorks) copyValuesToVector(m_managerMap, protocolsToSearch); else if (invalidScheme) return; else { protocolsToSearch.append(targetMap); // FIXME: this is a hack for webworks apps; RFC 6265 says "Cookies do not provide isolation by scheme" // so we should not be checking protocols at all. See PR 135595 if (m_shouldDumpAllCookies) { protocolsToSearch.append(m_managerMap.get("file")); protocolsToSearch.append(m_managerMap.get("local")); } } Vector<String> delimitedHost; // IP addresses are stored in a particular format (due to ipv6). Reduce the ip address so we can match // it with the one in memory. BlackBerry::Platform::String canonicalIP = BlackBerry::Platform::getCanonicalIPFormat(requestURL.host()); if (!canonicalIP.empty()) delimitedHost.append(String(canonicalIP.c_str())); else requestURL.host().lower().split(".", true, delimitedHost); // Go through all the protocol trees that we need to search for // and get all cookies that are valid for this domain for (size_t k = 0; k < protocolsToSearch.size(); k++) { CookieMap* currentMap = protocolsToSearch[k]; // if no cookies exist for this protocol, break right away if (!currentMap) continue; CookieLog("CookieManager - looking at protocol map %s \n", currentMap->getName().utf8().data()); // Special case for local and files - because WebApps expect to get ALL cookies from the backing-store on local protocol if (specialCaseForWebWorks) { CookieLog("CookieManager - special case find in protocol map - %s\n", currentMap->getName().utf8().data()); currentMap->getAllChildCookies(&cookieCandidates); } else { // Get cookies from the null domain map currentMap->getAllCookies(&cookieCandidates); // Get cookies from Host-only cookies if (canonicalIP.empty()) { CookieLog("CookieManager - looking for host-only cookies for host - %s", requestURL.host().utf8().data()); CookieMap* hostMap = currentMap->getSubdomainMap(requestURL.host()); if (hostMap) hostMap->getAllCookies(&cookieCandidates); } // Get cookies from the valid domain maps int i = delimitedHost.size() - 1; while (i >= 0) { CookieLog("CookieManager - finding %s in currentmap\n", delimitedHost[i].utf8().data()); currentMap = currentMap->getSubdomainMap(delimitedHost[i]); // if this subdomain/domain does not exist in our mapping then we simply exit if (!currentMap) { CookieLog("CookieManager - cannot find next map exiting the while loop.\n"); break; } CookieLog("CookieManager - found the map, grabbing cookies from this map\n"); currentMap->getAllCookies(&cookieCandidates); i--; } } } CookieLog("CookieManager - there are %d cookies in candidate\n", cookieCandidates.size()); for (size_t i = 0; i < cookieCandidates.size(); ++i) { RefPtr<ParsedCookie> cookie = cookieCandidates[i]; // According to the path-matches rules in RFC6265, section 5.1.4, // we should add a '/' at the end of cookie-path for comparison if the cookie-path is not end with '/'. String path = cookie->path(); CookieLog("CookieManager - comparing cookie path %s (len %d) to request path %s (len %d)", path.utf8().data(), path.length(), requestURL.path().utf8().data(), path.length()); if (!equalIgnoringCase(path, requestURL.path()) && !path.endsWith("/", false)) path = path + "/"; // Only secure connections have access to secure cookies. Unless specialCaseForWebWorks is true. // Get the cookies filtering out HttpOnly cookies if requested. if (requestURL.path().startsWith(path, false) && (isConnectionSecure || !cookie->isSecure()) && (filter == WithHttpOnlyCookies || !cookie->isHttpOnly())) { CookieLog("CookieManager - cookie chosen - %s\n", cookie->toString().utf8().data()); cookie->setLastAccessed(currentTime()); stackOfCookies.append(cookie); } } std::stable_sort(stackOfCookies.begin(), stackOfCookies.end(), cookieSorter); }
void SoupNetworkSession::setCookieJar(SoupCookieJar* jar) { if (SoupCookieJar* currentJar = cookieJar()) soup_session_remove_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(currentJar)); soup_session_add_feature(m_soupSession.get(), SOUP_SESSION_FEATURE(jar)); }
NetworkCookieJar *NetworkAccessManager::GetNetworkCookieJar() const { return static_cast<NetworkCookieJar*>(cookieJar()); }