diff --git a/src/core/slavebase.h b/src/core/slavebase.h --- a/src/core/slavebase.h +++ b/src/core/slavebase.h @@ -333,14 +333,26 @@ */ MetaData allMetaData() const; + /** + * Returns a map to query config/meta-data information from. + * + * The application provides the slave with all configuration information + * relevant for the current protocol and host. + * @since 5.64 + */ + QMap mapConfig() const; + /** * Returns a configuration object to query config/meta-data information * from. * * The application provides the slave with all configuration information * relevant for the current protocol and host. + * + * TODO KF6: remove + * @deprecated since 5.64 use mapConfig instead */ - KConfigGroup *config(); + KIOCORE_DEPRECATED KConfigGroup *config(); /** * Returns an object that can translate remote filenames into proper diff --git a/src/core/slavebase.cpp b/src/core/slavebase.cpp --- a/src/core/slavebase.cpp +++ b/src/core/slavebase.cpp @@ -35,12 +35,14 @@ #include #endif +#include #include #include #include #include #include #include +#include #include #include @@ -115,6 +117,7 @@ MetaData configData; KConfig *config; KConfigGroup *configGroup; + QMap mapConfig; QUrl onHoldUrl; QElapsedTimer lastTimeout; @@ -170,19 +173,24 @@ // Reconstructs configGroup from configData and mIncomingMetaData void rebuildConfig() { - configGroup->deleteGroup(KConfigGroup::WriteConfigFlags()); + mapConfig.clear(); // mIncomingMetaData cascades over config, so we write config first, // to let it be overwritten MetaData::ConstIterator end = configData.constEnd(); for (MetaData::ConstIterator it = configData.constBegin(); it != end; ++it) { - configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags()); + mapConfig.insert(it.key(), it->toUtf8()); } end = q->mIncomingMetaData.constEnd(); for (MetaData::ConstIterator it = q->mIncomingMetaData.constBegin(); it != end; ++it) { - configGroup->writeEntry(it.key(), it->toUtf8(), KConfigGroup::WriteConfigFlags()); + mapConfig.insert(it.key(), it->toUtf8()); } + + delete configGroup; + configGroup = nullptr; + delete config; + config = nullptr; } void verifyState(const char *cmdName) @@ -271,9 +279,7 @@ d->slaveid = QString::fromUtf8(protocol) + QString::number(getpid()); d->resume = false; d->needSendCanResume = false; - d->config = new KConfig(QString(), KConfig::SimpleConfig); - // The KConfigGroup needs the KConfig to exist during its whole lifetime. - d->configGroup = new KConfigGroup(d->config, QString()); + d->mapConfig = QMap(); d->onHold = false; d->wasKilled = false; // d->processed_size = 0; @@ -404,8 +410,25 @@ return false; } +QMap SlaveBase::mapConfig() const +{ + return d->mapConfig; +} + KConfigGroup *SlaveBase::config() { + if (!d->config) { + d->config = new KConfig(QString(), KConfig::SimpleConfig); + + d->configGroup = new KConfigGroup(d->config, QString()); + + auto end = d->mapConfig.cend(); + for (auto it = d->mapConfig.cbegin(); it != end; ++it) + { + d->configGroup->writeEntry(it.key(), it->toString().toUtf8(), KConfigGroup::WriteConfigFlags()); + } + } + return d->configGroup; } diff --git a/src/ioslaves/file/file.cpp b/src/ioslaves/file/file.cpp --- a/src/ioslaves/file/file.cpp +++ b/src/ioslaves/file/file.cpp @@ -338,7 +338,7 @@ void FileProtocol::redirect(const QUrl &url) { QUrl redir(url); - redir.setScheme(config()->readEntry("DefaultRemoteProtocol", "smb")); + redir.setScheme(mapConfig().value(QStringLiteral("DefaultRemoteProtocol"), QStringLiteral("smb")).toString()); // if we would redirect into the Windows world, let's also check for the // DavWWWRoot "token" which in the Windows world tells win explorer to access @@ -595,7 +595,7 @@ QT_STATBUF buff_orig; const bool bOrigExists = (QT_LSTAT(QFile::encodeName(dest_orig).constData(), &buff_orig) != -1); bool bPartExists = false; - const bool bMarkPartial = config()->readEntry("MarkPartial", true); + const bool bMarkPartial = mapConfig().value(QStringLiteral("MarkPartial"), true).toBool(); if (bMarkPartial) { QT_STATBUF buff_part; @@ -723,7 +723,7 @@ QT_STATBUF buff; if (QT_STAT(QFile::encodeName(dest).constData(), &buff) == 0) { - int size = config()->readEntry("MinimumKeepSize", DEFAULT_MINIMUM_KEEP_SIZE); + int size = mapConfig().value(QStringLiteral("MinimumKeepSize"), QVariant(DEFAULT_MINIMUM_KEEP_SIZE)).toInt(); if (buff.st_size < size) { QFile::remove(dest); } diff --git a/src/ioslaves/file/file_unix.cpp b/src/ioslaves/file/file_unix.cpp --- a/src/ioslaves/file/file_unix.cpp +++ b/src/ioslaves/file/file_unix.cpp @@ -494,7 +494,7 @@ { if (!isLocalFileSameHost(url)) { QUrl redir(url); - redir.setScheme(config()->readEntry("DefaultRemoteProtocol", "smb")); + redir.setScheme(mapConfig().value(QStringLiteral("DefaultRemoteProtocol"), QStringLiteral("smb")).toString()); redirection(redir); // qDebug() << "redirecting to " << redir; finished(); diff --git a/src/ioslaves/file/file_win.cpp b/src/ioslaves/file/file_win.cpp --- a/src/ioslaves/file/file_win.cpp +++ b/src/ioslaves/file/file_win.cpp @@ -191,7 +191,7 @@ if (!url.isLocalFile()) { QUrl redir(url); - redir.setScheme(config()->readEntry("DefaultRemoteProtocol", "smb")); + redir.setScheme(mapConfig().value(QStringLiteral("DefaultRemoteProtocol"), QStringLiteral("smb")).toString()); redirection(redir); // qDebug() << "redirecting to " << redir; finished(); diff --git a/src/ioslaves/ftp/ftp.cpp b/src/ioslaves/ftp/ftp.cpp --- a/src/ioslaves/ftp/ftp.cpp +++ b/src/ioslaves/ftp/ftp.cpp @@ -327,7 +327,7 @@ qCDebug(KIO_FTP) << _host << "port=" << _port << "user=" << _user; m_proxyURL.clear(); - m_proxyUrls = config()->readEntry("ProxyUrls", QStringList()); + m_proxyUrls = mapConfig().value(QStringLiteral("MarkPartial"), QVariant(QStringList())).toStringList(); qCDebug(KIO_FTP) << "proxy urls:" << m_proxyUrls; if (m_host != _host || m_port != _port || @@ -381,7 +381,7 @@ } } - m_bTextMode = config()->readEntry("textmode", false); + m_bTextMode = mapConfig().value(QStringLiteral("textmode"), false).toBool(); connected(); // Redirected due to credential change... @@ -518,11 +518,11 @@ QString user(m_user); QString pass(m_pass); - if (config()->readEntry("EnableAutoLogin", false)) { - QString au = config()->readEntry("autoLoginUser"); + if (mapConfig().value(QStringLiteral("EnableAutoLogin"), false).toBool()) { + QString au = mapConfig().value(QStringLiteral("autoLoginUser"), QVariant("")).toString(); if (!au.isEmpty()) { user = au; - pass = config()->readEntry("autoLoginPass"); + pass = mapConfig().value(QStringLiteral("autoLoginPass"), QVariant("")).toString(); } } @@ -538,7 +538,7 @@ // Check for cached authentication first and fallback to // anonymous login when no stored credentials are found. - if (!config()->readEntry("TryAnonymousLoginFirst", false) && + if (!mapConfig().value(QStringLiteral("TryAnonymousLoginFirst"), false).toBool() && pass.isEmpty() && checkCachedAuthentication(info)) { user = info.username; pass = info.password; @@ -585,7 +585,7 @@ info.keepPassword = true; // Prompt the user for persistence as well. info.setModified(false); // Default the modified flag since we reuse authinfo. - const bool disablePassDlg = config()->readEntry("DisablePassDlg", false); + const bool disablePassDlg = mapConfig().value(QStringLiteral("DisablePassDlg"), false).toBool(); if (disablePassDlg) { error(ERR_USER_CANCELED, m_host); return false; @@ -686,7 +686,7 @@ qCWarning(KIO_FTP) << "SYST failed"; } - if (config()->readEntry("EnableAutoLoginMacro", false)) { + if (mapConfig().value(QStringLiteral("EnableAutoLoginMacro"), false).toBool()) { ftpAutoLoginMacro(); } @@ -954,15 +954,15 @@ int iErrCodePASV = 0; // Remember error code from PASV // First try passive (EPSV & PASV) modes - if (!config()->readEntry("DisablePassiveMode", false)) { + if (!mapConfig().value(QStringLiteral("DisablePassiveMode"), false).toBool()) { iErrCode = ftpOpenPASVDataConnection(); if (iErrCode == 0) { return 0; // success } iErrCodePASV = iErrCode; ftpCloseDataConnection(); - if (!config()->readEntry("DisableEPSV", false)) { + if (!mapConfig().value(QStringLiteral("DisableEPSV"), false).toBool()) { iErrCode = ftpOpenEPSVDataConnection(); if (iErrCode == 0) { return 0; // success @@ -2095,7 +2095,7 @@ if (m_user.isEmpty() || m_user == QLatin1String(FTP_LOGIN)) { bMarkPartial = false; } else { - bMarkPartial = config()->readEntry("MarkPartial", true); + bMarkPartial = mapConfig().value(QStringLiteral("ProxyUrls"), true).toBool(); } QString dest_orig = dest_url.path(); @@ -2207,7 +2207,7 @@ if (bMarkPartial) { // Remove if smaller than minimum size if (ftpSize(dest, 'I') && - (processed_size < config()->readEntry("MinimumKeepSize", DEFAULT_MINIMUM_KEEP_SIZE))) { + (processed_size < mapConfig().value(QStringLiteral("MinimumKeepSize"), QVariant(DEFAULT_MINIMUM_KEEP_SIZE)).toInt())) { const QByteArray cmd = "DELE " + remoteEncoding()->encode(dest); (void) ftpSendCmd(cmd); } @@ -2432,7 +2432,7 @@ bool bResume = false; QFileInfo sPartInfo(sPart); const bool bPartExists = sPartInfo.exists(); - const bool bMarkPartial = config()->readEntry("MarkPartial", true); + const bool bMarkPartial = mapConfig().value(QStringLiteral("MarkPartial"), true).toBool(); const QString dest = bMarkPartial ? sPart : sCopyFile; if (bMarkPartial && bPartExists && sPartInfo.size() > 0) { // must not be a folder! please fix a similar bug in kio_file!! @@ -2505,7 +2505,7 @@ } else { sPartInfo.refresh(); if (sPartInfo.exists()) { // should a very small ".part" be deleted? - int size = config()->readEntry("MinimumKeepSize", DEFAULT_MINIMUM_KEEP_SIZE); + int size = mapConfig().value(QStringLiteral("MinimumKeepSize"), QVariant(DEFAULT_MINIMUM_KEEP_SIZE)).toInt(); if (sPartInfo.size() < size) { QFile::remove(sPart); } diff --git a/src/ioslaves/http/http.cpp b/src/ioslaves/http/http.cpp --- a/src/ioslaves/http/http.cpp +++ b/src/ioslaves/http/http.cpp @@ -443,15 +443,15 @@ m_request.keepAliveTimeout = 0; m_request.redirectUrl = QUrl(); - m_request.useCookieJar = config()->readEntry("Cookies", false); - m_request.cacheTag.useCache = config()->readEntry("UseCache", true); - m_request.preferErrorPage = config()->readEntry("errorPage", true); - const bool noAuth = config()->readEntry("no-auth", false); - m_request.doNotWWWAuthenticate = config()->readEntry("no-www-auth", noAuth); - m_request.doNotProxyAuthenticate = config()->readEntry("no-proxy-auth", noAuth); - m_strCacheDir = config()->readPathEntry("CacheDir", QString()); - m_maxCacheAge = config()->readEntry("MaxCacheAge", DEFAULT_MAX_CACHE_AGE); - m_request.windowId = config()->readEntry("window-id"); + m_request.useCookieJar = mapConfig().value(QStringLiteral("Cookies"), false).toBool(); + m_request.cacheTag.useCache = mapConfig().value(QStringLiteral("UseCache"), true).toBool(); + m_request.preferErrorPage = mapConfig().value(QStringLiteral("errorPage"), true).toBool(); + const bool noAuth = mapConfig().value(QStringLiteral("no-auth"), false).toBool(); + m_request.doNotWWWAuthenticate = mapConfig().value(QStringLiteral("no-www-auth"), noAuth).toBool(); + m_request.doNotProxyAuthenticate = mapConfig().value(QStringLiteral("no-proxy-auth"), noAuth).toBool(); + m_strCacheDir = config()->readPathEntry(QStringLiteral("CacheDir"), QString()); + m_maxCacheAge = mapConfig().value(QStringLiteral("MaxCacheAge"), DEFAULT_MAX_CACHE_AGE).toInt(); + m_request.windowId = mapConfig().value(QStringLiteral("window-id")).toString(); m_request.methodStringOverride = metaData(QStringLiteral("CustomHTTPMethod")); m_request.sentMethodString.clear(); @@ -462,7 +462,7 @@ m_request.referrer.clear(); // RFC 2616: do not send the referrer if the referrer page was served using SSL and // the current page does not use SSL. - if (config()->readEntry("SendReferrer", true) && + if (mapConfig().value(QStringLiteral("SendReferrer"), true).toBool() && (isEncryptedHttpVariety(m_protocol) || metaData(QStringLiteral("ssl_was_in_use")) != QLatin1String("TRUE"))) { QUrl refUrl(metaData(QStringLiteral("referrer"))); if (refUrl.isValid()) { @@ -479,12 +479,12 @@ } } - if (config()->readEntry("SendLanguageSettings", true)) { - m_request.charsets = config()->readEntry("Charsets", DEFAULT_PARTIAL_CHARSET_HEADER); + if (mapConfig().value(QStringLiteral("SendLanguageSettings"), true).toBool()) { + m_request.charsets = mapConfig().value(QStringLiteral("Charsets"), QStringLiteral(DEFAULT_PARTIAL_CHARSET_HEADER)).toString(); if (!m_request.charsets.contains(QLatin1String("*;"), Qt::CaseInsensitive)) { m_request.charsets += QLatin1String(",*;q=0.5"); } - m_request.languages = config()->readEntry("Languages", DEFAULT_LANGUAGE_HEADER); + m_request.languages = mapConfig().value(QStringLiteral("Languages"), QStringLiteral(DEFAULT_LANGUAGE_HEADER)).toString(); } else { m_request.charsets.clear(); m_request.languages.clear(); @@ -511,12 +511,12 @@ m_request.endoffset = 0; } - m_request.disablePassDialog = config()->readEntry("DisablePassDlg", false); - m_request.allowTransferCompression = config()->readEntry("AllowCompressedPage", true); + m_request.disablePassDialog = mapConfig().value(QStringLiteral("DisablePassDlg"), false).toBool(); + m_request.allowTransferCompression = mapConfig().value(QStringLiteral("AllowCompressedPage"), true).toBool(); m_request.id = metaData(QStringLiteral("request-id")); // Store user agent for this host. - if (config()->readEntry("SendUserAgent", true)) { + if (mapConfig().value(QStringLiteral("SendUserAgent"), true).toBool()) { m_request.userAgent = metaData(QStringLiteral("UserAgent")); } else { m_request.userAgent.clear(); @@ -2160,7 +2160,7 @@ // Get proxy information... if (m_request.proxyUrls.isEmpty()) { - m_request.proxyUrls = config()->readEntry("ProxyUrls", QStringList()); + m_request.proxyUrls = mapConfig().value(QStringLiteral("ProxyUrls")).toStringList(); qCDebug(KIO_HTTP) << "Proxy URLs:" << m_request.proxyUrls; } @@ -2582,7 +2582,7 @@ } // DoNotTrack feature... - if (config()->readEntry("DoNotTrack", false)) { + if (mapConfig().value(QStringLiteral("DoNotTrack"), false).toBool()) { header += QLatin1String("DNT: 1\r\n"); } @@ -2662,7 +2662,7 @@ void HTTPProtocol::forwardHttpResponseHeader(bool forwardImmediately) { // Send the response header if it was requested... - if (!config()->readEntry("PropagateHttpHeader", false)) { + if (!mapConfig().value(QStringLiteral("PropagateHttpHeader"), false).toBool()) { return; } @@ -3391,7 +3391,7 @@ if (!cookieStr.isEmpty()) { if ((m_request.cookieMode == HTTPRequest::CookiesAuto) && m_request.useCookieJar) { // Give cookies to the cookiejar. - const QString domain = config()->readEntry("cross-domain"); + const QString domain = mapConfig().value(QStringLiteral("cross-domain")).toString(); if (!domain.isEmpty() && isCrossDomainRequest(m_request.url.host(), domain)) { cookieStr = "Cross-Domain\n" + cookieStr; } @@ -3511,7 +3511,7 @@ return parseHeaderFromCache(); } - if (config()->readEntry("PropagateHttpHeader", false) || + if (mapConfig().value(QStringLiteral("PropagateHttpHeader"), false).toBool() || m_request.cacheTag.ioMode == WriteToCache) { // store header lines if they will be used; note that the tokenizer removing // line continuation special cases is probably more good than bad. @@ -3771,7 +3771,7 @@ if (!cacheFileOpenWrite()) { qCDebug(KIO_HTTP) << "Error creating cache entry for" << m_request.url << "!"; } - m_maxCacheSize = config()->readEntry("MaxCacheSize", DEFAULT_MAX_CACHE_SIZE); + m_maxCacheSize = mapConfig().value(QStringLiteral("MaxCacheSize"), DEFAULT_MAX_CACHE_SIZE).toInt(); } else if (m_request.responseCode == 304 && m_request.cacheTag.file) { if (!mayCache) { qCDebug(KIO_HTTP) << "This webserver is confused about the cacheability of the data it sends."; @@ -5118,17 +5118,17 @@ // If the internal meta-data "cached-www-auth" is set, then check for cached // authentication data and preemptively send the authentication header if a // matching one is found. - if (!m_wwwAuth && config()->readEntry("cached-www-auth", false)) { + if (!m_wwwAuth && mapConfig().value(QStringLiteral("cached-www-auth"), false).toBool()) { KIO::AuthInfo authinfo; authinfo.url = m_request.url; - authinfo.realmValue = config()->readEntry("www-auth-realm", QString()); + authinfo.realmValue = mapConfig().value(QStringLiteral("www-auth-realm"), QString()).toString(); // If no realm metadata, then make sure path matching is turned on. authinfo.verifyPath = (authinfo.realmValue.isEmpty()); - const bool useCachedAuth = (m_request.responseCode == 401 || !config()->readEntry("no-preemptive-auth-reuse", false)); + const bool useCachedAuth = (m_request.responseCode == 401 || !mapConfig().value(QStringLiteral("no-preemptive-auth-reuse"), false).toBool()); if (useCachedAuth && checkCachedAuthentication(authinfo)) { - const QByteArray cachedChallenge = config()->readEntry("www-auth-challenge", QByteArray()); + const QByteArray cachedChallenge = mapConfig().value(QStringLiteral("www-auth-challenge"), QByteArray()).toByteArray(); if (!cachedChallenge.isEmpty()) { m_wwwAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); if (m_wwwAuth) { @@ -5143,15 +5143,15 @@ // If the internal meta-data "cached-proxy-auth" is set, then check for cached // authentication data and preemptively send the authentication header if a // matching one is found. - if (!m_proxyAuth && config()->readEntry("cached-proxy-auth", false)) { + if (!m_proxyAuth && mapConfig().value(QStringLiteral("cached-proxy-auth"), false).toBool()) { KIO::AuthInfo authinfo; authinfo.url = m_request.proxyUrl; - authinfo.realmValue = config()->readEntry("proxy-auth-realm", QString()); + authinfo.realmValue = mapConfig().value(QStringLiteral("proxy-auth-realm"), QString()).toString(); // If no realm metadata, then make sure path matching is turned on. authinfo.verifyPath = (authinfo.realmValue.isEmpty()); if (checkCachedAuthentication(authinfo)) { - const QByteArray cachedChallenge = config()->readEntry("proxy-auth-challenge", QByteArray()); + const QByteArray cachedChallenge = mapConfig().value(QStringLiteral("proxy-auth-challenge"), QByteArray()).toByteArray(); if (!cachedChallenge.isEmpty()) { m_proxyAuth = KAbstractHttpAuthentication::newAuth(cachedChallenge, config()); if (m_proxyAuth) { @@ -5282,11 +5282,11 @@ switch (m_request.prevResponseCode) { case 401: auth = m_wwwAuth; - alreadyCached = config()->readEntry("cached-www-auth", false); + alreadyCached = mapConfig().value(QStringLiteral("cached-www-auth"), false).toBool(); break; case 407: auth = m_proxyAuth; - alreadyCached = config()->readEntry("cached-proxy-auth", false); + alreadyCached = mapConfig().value(QStringLiteral("cached-proxy-auth"), false).toBool(); break; default: Q_ASSERT(false); // should never happen! diff --git a/src/kcms/kio/smbrodlg.cpp b/src/kcms/kio/smbrodlg.cpp --- a/src/kcms/kio/smbrodlg.cpp +++ b/src/kcms/kio/smbrodlg.cpp @@ -103,7 +103,7 @@ KConfigGroup group = cfg->group("Browser Settings/SMBro" ); m_userLe->setText(group.readEntry("User")); // m_workgroupLe->setText(group.readEntry("Workgroup")); -// m_showHiddenShares->setChecked(group.readEntry("ShowHiddenShares", QVariant(false)).toBool()); +// m_showHiddenShares->setChecked(group.readEntry("ShowHiddenShares", false).toBool()); //QStringList _strList = KCharsets::charsets()->availableEncodingNames(); //QString m_encoding = QTextCodec::codecForLocale()->name();