void KCookieServer::addCookies(const QString &url, const QCString &cookieHeader, long windowId, bool useDOMFormat) { KHttpCookieList cookieList; if(useDOMFormat) cookieList = mCookieJar->makeDOMCookies(url, cookieHeader, windowId); else cookieList = mCookieJar->makeCookies(url, cookieHeader, windowId); checkCookies(&cookieList); for(KHttpCookiePtr cookie = cookieList.first(); cookie; cookie = cookieList.first()) mPendingCookies->append(cookieList.take()); if(!mAdvicePending) { mAdvicePending = true; while(!mPendingCookies->isEmpty()) { checkCookies(0); } mAdvicePending = false; } }
void KCookieServer::checkCookies(KHttpCookieList *cookieList) { KHttpCookieList *list; if(cookieList) list = cookieList; else list = mPendingCookies; KHttpCookiePtr cookie = list->first(); while(cookie) { kdDebug(7104) << "checkCookies: Asking cookie advice for " << cookie->host() << endl; KCookieAdvice advice = mCookieJar->cookieAdvice(cookie); switch(advice) { case KCookieAccept: list->take(); mCookieJar->addCookie(cookie); cookie = list->current(); break; case KCookieReject: list->take(); delete cookie; cookie = list->current(); break; default: cookie = list->next(); break; } } if(cookieList || list->isEmpty()) return; KHttpCookiePtr currentCookie = mPendingCookies->first(); KHttpCookieList currentList; currentList.append(currentCookie); QString currentHost = currentCookie->host(); cookie = mPendingCookies->next(); while(cookie) { if(cookie->host() == currentHost) { currentList.append(cookie); } cookie = mPendingCookies->next(); } KCookieWin *kw = new KCookieWin(0L, currentList, mCookieJar->preferredDefaultPolicy(), mCookieJar->showCookieDetails()); KCookieAdvice userAdvice = kw->advice(mCookieJar, currentCookie); delete kw; // Save the cookie config if it has changed mCookieJar->saveConfig(mConfig); // Apply the user's choice to all cookies that are currently // queued for this host. cookie = mPendingCookies->first(); while(cookie) { if(cookie->host() == currentHost) { switch(userAdvice) { case KCookieAccept: mPendingCookies->take(); mCookieJar->addCookie(cookie); cookie = mPendingCookies->current(); break; case KCookieReject: mPendingCookies->take(); delete cookie; cookie = mPendingCookies->current(); break; default: qWarning(__FILE__ ":%d Problem!", __LINE__); cookie = mPendingCookies->next(); break; } } else { cookie = mPendingCookies->next(); } } // Check if we can handle any request for(CookieRequest *request = mRequestList->first(); request;) { if(!cookiesPending(request->url)) { QCString replyType; QByteArray replyData; QString res = mCookieJar->findCookies(request->url, request->DOM, request->windowId); QDataStream stream2(replyData, IO_WriteOnly); stream2 << res; replyType = "QString"; request->client->endTransaction(request->transaction, replyType, replyData); CookieRequest *tmp = request; request = mRequestList->next(); mRequestList->removeRef(tmp); delete tmp; } else { request = mRequestList->next(); } } if(mCookieJar->changed()) saveCookieJar(); }