File indexing completed on 2024-05-12 05:46:50
0001 /* This file is part of the KDE project 0002 Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Lesser General Public 0006 License (LGPL) as published by the Free Software Foundation; 0007 either version 2 of the License, or (at your option) any 0008 later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public 0016 License along with this library; see the file COPYING.LIB. If not, 0017 write to the Free Software Foundation, Inc., 51 Franklin Street, 0018 Fifth Floor, Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include "sessiondata_p.h" 0022 0023 #include <QDir> 0024 #include <QStandardPaths> 0025 #include <QTextCodec> 0026 0027 #include <kconfiggroup.h> 0028 #include <klocalizedstring.h> 0029 #include <kprotocolmanager.h> 0030 #include <ksharedconfig.h> 0031 0032 #include <kio/slaveconfig.h> 0033 #include "http_slave_defaults.h" 0034 0035 namespace KIO 0036 { 0037 0038 /***************************** SessionData::AuthData ************************/ 0039 #if 0 0040 struct SessionData::AuthData { 0041 0042 public: 0043 AuthData() {} 0044 0045 AuthData(const QByteArray &k, const QByteArray &g, bool p) 0046 { 0047 key = k; 0048 group = g; 0049 persist = p; 0050 } 0051 0052 bool isKeyMatch(const QByteArray &val) const 0053 { 0054 return (val == key); 0055 } 0056 0057 bool isGroupMatch(const QByteArray &val) const 0058 { 0059 return (val == group); 0060 } 0061 0062 QByteArray key; 0063 QByteArray group; 0064 bool persist; 0065 }; 0066 #endif 0067 0068 /********************************* SessionData ****************************/ 0069 0070 class SessionData::SessionDataPrivate 0071 { 0072 public: 0073 SessionDataPrivate() 0074 { 0075 useCookie = true; 0076 initDone = false; 0077 } 0078 0079 bool initDone; 0080 bool useCookie; 0081 QString charsets; 0082 QString language; 0083 }; 0084 0085 SessionData::SessionData() 0086 : d(new SessionDataPrivate) 0087 { 0088 // authData = 0; 0089 } 0090 0091 SessionData::~SessionData() 0092 { 0093 delete d; 0094 } 0095 0096 void SessionData::configDataFor(MetaData &configData, const QString &proto, 0097 const QString &) 0098 { 0099 if ((proto.startsWith(QLatin1String("http"), Qt::CaseInsensitive)) || 0100 (proto.startsWith(QLatin1String("webdav"), Qt::CaseInsensitive))) { 0101 if (!d->initDone) { 0102 reset(); 0103 } 0104 0105 // These might have already been set so check first 0106 // to make sure that we do not trumpt settings sent 0107 // by apps or end-user. 0108 if (configData[QStringLiteral("Cookies")].isEmpty()) { 0109 configData[QStringLiteral("Cookies")] = d->useCookie ? QStringLiteral("true") : QStringLiteral("false"); 0110 } 0111 if (configData[QStringLiteral("Languages")].isEmpty()) { 0112 configData[QStringLiteral("Languages")] = d->language; 0113 } 0114 if (configData[QStringLiteral("Charsets")].isEmpty()) { 0115 configData[QStringLiteral("Charsets")] = d->charsets; 0116 } 0117 if (configData[QStringLiteral("CacheDir")].isEmpty()) { 0118 const QString httpCacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QLatin1String("/kio_http"); 0119 QDir().mkpath(httpCacheDir); 0120 configData[QStringLiteral("CacheDir")] = httpCacheDir; 0121 } 0122 if (configData[QStringLiteral("UserAgent")].isEmpty()) { 0123 configData[QStringLiteral("UserAgent")] = KProtocolManager::defaultUserAgent(); 0124 } 0125 } 0126 } 0127 0128 void SessionData::reset() 0129 { 0130 d->initDone = true; 0131 // Get Cookie settings... 0132 d->useCookie = KSharedConfig::openConfig(QStringLiteral("kcookiejarrc"), KConfig::NoGlobals)-> 0133 group("Cookie Policy"). 0134 readEntry("Cookies", true); 0135 0136 d->language = KProtocolManager::acceptLanguagesHeader(); 0137 d->charsets = QString::fromLatin1(QTextCodec::codecForLocale()->name()).toLower(); 0138 KProtocolManager::reparseConfiguration(); 0139 } 0140 0141 }