kcookiejar.h
/*
This file is part of the KDE File Manager
Copyright (C) 1998 Waldo Bastian (bastian@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
//----------------------------------------------------------------------------
//
// KDE File Manager -- HTTP Cookies
// $Id: kcookiejar.h 465272 2005-09-29 09:47:40Z mueller $
#ifndef KCOOKIEJAR_H
#define KCOOKIEJAR_H
#include <qstring.h>
#include <qstringlist.h>
#include <qdict.h>
#include <qptrlist.h>
#include <time.h>
class KConfig;
class KCookieJar;
class KHttpCookie;
class KHttpCookieList;
typedef KHttpCookie *KHttpCookiePtr;
enum KCookieAdvice
{
KCookieDunno=0,
KCookieAccept,
KCookieReject,
KCookieAsk
};
class KHttpCookie
{
friend class KCookieJar;
friend class KHttpCookieList;
protected:
QString mHost;
QString mDomain;
QString mPath;
QString mName;
QString mValue;
time_t mExpireDate;
int mProtocolVersion;
bool mSecure;
bool mCrossDomain;
bool mHttpOnly;
bool mExplicitPath;
QValueList<long> mWindowIds;
QString cookieStr(bool useDOMFormat);
public:
KHttpCookie(const QString &_host=QString::null,
const QString &_domain=QString::null,
const QString &_path=QString::null,
const QString &_name=QString::null,
const QString &_value=QString::null,
time_t _expireDate=0,
int _protocolVersion=0,
bool _secure = false,
bool _httpOnly = false,
bool _explicitPath = false);
QString domain(void) { return mDomain; }
QString host(void) { return mHost; }
QString path(void) { return mPath; }
QString name(void) { return mName; }
QString value(void) { return mValue; }
QValueList<long> &windowIds(void) { return mWindowIds; }
void fixDomain(const QString &domain) { mDomain = domain; }
time_t expireDate(void) { return mExpireDate; }
int protocolVersion(void) { return mProtocolVersion; }
bool isSecure(void) { return mSecure; }
bool isExpired(time_t currentDate);
bool isCrossDomain(void) { return mCrossDomain; }
bool isHttpOnly(void) { return mHttpOnly; }
bool hasExplicitPath(void) { return mExplicitPath; }
bool match(const QString &fqdn, const QStringList &domainList, const QString &path);
};
class KHttpCookieList : public QPtrList<KHttpCookie>
{
public:
KHttpCookieList() : QPtrList<KHttpCookie>(), advice( KCookieDunno )
{ }
virtual ~KHttpCookieList() { }
virtual int compareItems( void * item1, void * item2);
KCookieAdvice getAdvice(void) { return advice; }
void setAdvice(KCookieAdvice _advice) { advice = _advice; }
private:
KCookieAdvice advice;
};
class KCookieJar
{
public:
KCookieJar();
~KCookieJar();
bool changed() const { return m_cookiesChanged || m_configChanged; }
bool saveCookies(const QString &_filename);
bool loadCookies(const QString &_filename);
void saveConfig(KConfig *_config);
void loadConfig(KConfig *_config, bool reparse = false);
QString findCookies(const QString &_url, bool useDOMFormat, long windowId, KHttpCookieList *pendingCookies=0);
KHttpCookieList makeCookies(const QString &_url, const QCString &cookie_headers, long windowId);
KHttpCookieList makeDOMCookies(const QString &_url, const QCString &cookie_domstr, long windowId);
void addCookie(KHttpCookiePtr &cookiePtr);
KCookieAdvice cookieAdvice(KHttpCookiePtr cookiePtr);
KCookieAdvice getDomainAdvice(const QString &_domain);
void setDomainAdvice(const QString &_domain, KCookieAdvice _advice);
void setDomainAdvice(KHttpCookiePtr _cookie, KCookieAdvice _advice);
KCookieAdvice getGlobalAdvice() { return m_globalAdvice; }
void setGlobalAdvice(KCookieAdvice _advice);
const QStringList& getDomainList();
const KHttpCookieList *getCookieList(const QString & _domain,
const QString& _fqdn );
void eatCookie(KHttpCookiePtr cookiePtr);
void eatCookiesForDomain(const QString &domain);
void eatAllCookies();
void eatSessionCookies( long windowId );
void eatSessionCookies( const QString& fqdn, long windowId, bool isFQDN = true );
static bool parseURL(const QString &_url,
QString &_fqdn,
QString &_path);
void extractDomains(const QString &_fqdn,
QStringList &_domainList);
static QString adviceToStr(KCookieAdvice _advice);
static KCookieAdvice strToAdvice(const QString &_str);
int preferredDefaultPolicy() const { return m_preferredPolicy; }
bool showCookieDetails () const { return m_showCookieDetails; }
void setPreferredDefaultPolicy (int value) { m_preferredPolicy = value; }
void setShowCookieDetails (bool value) { m_showCookieDetails = value; }
protected:
void stripDomain(const QString &_fqdn, QString &_domain);
QString stripDomain( KHttpCookiePtr cookiePtr);
protected:
QStringList m_domainList;
KCookieAdvice m_globalAdvice;
QDict<KHttpCookieList> m_cookieDomains;
QDict<int> m_twoLevelTLD;
bool m_configChanged;
bool m_cookiesChanged;
bool m_showCookieDetails;
bool m_rejectCrossDomainCookies;
bool m_autoAcceptSessionCookies;
bool m_ignoreCookieExpirationDate;
int m_preferredPolicy;
};
#endif

KDE Home | KDE Accessibility Home | Description of Access Keys