kioslave
kcookiejar.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef KCOOKIEJAR_H
00026 #define KCOOKIEJAR_H
00027
00028 #include <qstring.h>
00029 #include <qstringlist.h>
00030 #include <qdict.h>
00031 #include <qptrlist.h>
00032 #include <time.h>
00033
00034 class KConfig;
00035 class KCookieJar;
00036 class KHttpCookie;
00037 class KHttpCookieList;
00038
00039 typedef KHttpCookie *KHttpCookiePtr;
00040
00041 enum KCookieAdvice
00042 {
00043 KCookieDunno=0,
00044 KCookieAccept,
00045 KCookieReject,
00046 KCookieAsk
00047 };
00048
00049 class KHttpCookie
00050 {
00051 friend class KCookieJar;
00052 friend class KHttpCookieList;
00053
00054 protected:
00055 QString mHost;
00056 QString mDomain;
00057 QString mPath;
00058 QString mName;
00059 QString mValue;
00060 time_t mExpireDate;
00061 int mProtocolVersion;
00062 bool mSecure;
00063 bool mCrossDomain;
00064 bool mHttpOnly;
00065 bool mExplicitPath;
00066 QValueList<long> mWindowIds;
00067
00068 QString cookieStr(bool useDOMFormat);
00069
00070 public:
00071 KHttpCookie(const QString &_host=QString::null,
00072 const QString &_domain=QString::null,
00073 const QString &_path=QString::null,
00074 const QString &_name=QString::null,
00075 const QString &_value=QString::null,
00076 time_t _expireDate=0,
00077 int _protocolVersion=0,
00078 bool _secure = false,
00079 bool _httpOnly = false,
00080 bool _explicitPath = false);
00081
00082 QString domain(void) { return mDomain; }
00083 QString host(void) { return mHost; }
00084 QString path(void) { return mPath; }
00085 QString name(void) { return mName; }
00086 QString value(void) { return mValue; }
00087 QValueList<long> &windowIds(void) { return mWindowIds; }
00088 void fixDomain(const QString &domain) { mDomain = domain; }
00089 time_t expireDate(void) { return mExpireDate; }
00090 int protocolVersion(void) { return mProtocolVersion; }
00091 bool isSecure(void) { return mSecure; }
00092 bool isExpired(time_t currentDate);
00093 bool isCrossDomain(void) { return mCrossDomain; }
00094 bool isHttpOnly(void) { return mHttpOnly; }
00095 bool hasExplicitPath(void) { return mExplicitPath; }
00096 bool match(const QString &fqdn, const QStringList &domainList, const QString &path);
00097 };
00098
00099 class KHttpCookieList : public QPtrList<KHttpCookie>
00100 {
00101 public:
00102 KHttpCookieList() : QPtrList<KHttpCookie>(), advice( KCookieDunno )
00103 { }
00104 virtual ~KHttpCookieList() { }
00105
00106 virtual int compareItems( void * item1, void * item2);
00107 KCookieAdvice getAdvice(void) { return advice; }
00108 void setAdvice(KCookieAdvice _advice) { advice = _advice; }
00109
00110 private:
00111 KCookieAdvice advice;
00112 };
00113
00114 class KCookieJar
00115 {
00116 public:
00122 KCookieJar();
00123
00129 ~KCookieJar();
00130
00134 bool changed() const { return m_cookiesChanged || m_configChanged; }
00135
00139 bool saveCookies(const QString &_filename);
00140
00144 bool loadCookies(const QString &_filename);
00145
00149 void saveConfig(KConfig *_config);
00150
00154 void loadConfig(KConfig *_config, bool reparse = false);
00155
00167 QString findCookies(const QString &_url, bool useDOMFormat, long windowId, KHttpCookieList *pendingCookies=0);
00168
00177 KHttpCookieList makeCookies(const QString &_url, const QCString &cookie_headers, long windowId);
00178
00187 KHttpCookieList makeDOMCookies(const QString &_url, const QCString &cookie_domstr, long windowId);
00188
00194 void addCookie(KHttpCookiePtr &cookiePtr);
00195
00205 KCookieAdvice cookieAdvice(KHttpCookiePtr cookiePtr);
00206
00216 KCookieAdvice getDomainAdvice(const QString &_domain);
00217
00228 void setDomainAdvice(const QString &_domain, KCookieAdvice _advice);
00229
00240 void setDomainAdvice(KHttpCookiePtr _cookie, KCookieAdvice _advice);
00241
00252 KCookieAdvice getGlobalAdvice() { return m_globalAdvice; }
00253
00264 void setGlobalAdvice(KCookieAdvice _advice);
00265
00272 const QStringList& getDomainList();
00273
00277 const KHttpCookieList *getCookieList(const QString & _domain,
00278 const QString& _fqdn );
00279
00287 void eatCookie(KHttpCookiePtr cookiePtr);
00288
00292 void eatCookiesForDomain(const QString &domain);
00293
00297 void eatAllCookies();
00298
00303 void eatSessionCookies( long windowId );
00304
00309 void eatSessionCookies( const QString& fqdn, long windowId, bool isFQDN = true );
00310
00314 static bool parseURL(const QString &_url,
00315 QString &_fqdn,
00316 QString &_path);
00317
00323 void extractDomains(const QString &_fqdn,
00324 QStringList &_domainList);
00325
00326 static QString adviceToStr(KCookieAdvice _advice);
00327 static KCookieAdvice strToAdvice(const QString &_str);
00328
00330 int preferredDefaultPolicy() const { return m_preferredPolicy; }
00331
00333 bool showCookieDetails () const { return m_showCookieDetails; }
00334
00338 void setPreferredDefaultPolicy (int value) { m_preferredPolicy = value; }
00339
00344 void setShowCookieDetails (bool value) { m_showCookieDetails = value; }
00345
00346 protected:
00347 void stripDomain(const QString &_fqdn, QString &_domain);
00348 QString stripDomain( KHttpCookiePtr cookiePtr);
00349
00350 protected:
00351 QStringList m_domainList;
00352 KCookieAdvice m_globalAdvice;
00353 QDict<KHttpCookieList> m_cookieDomains;
00354 QDict<int> m_twoLevelTLD;
00355
00356 bool m_configChanged;
00357 bool m_cookiesChanged;
00358 bool m_showCookieDetails;
00359 bool m_rejectCrossDomainCookies;
00360 bool m_autoAcceptSessionCookies;
00361 bool m_ignoreCookieExpirationDate;
00362
00363 int m_preferredPolicy;
00364 };
00365 #endif