diff --git a/kio/kio/kprotocolmanager.cpp b/kio/kio/kprotocolmanager.cpp index dd27d91cb5..d7800a489f 100644 --- a/kio/kio/kprotocolmanager.cpp +++ b/kio/kio/kprotocolmanager.cpp @@ -1,742 +1,790 @@ /* This file is part of the KDE libraries Copyright (C) 1999 Torben Weis Copyright (C) 2000- Waldo Bastain Copyright (C) 2000- Dawit Alemayehu + Copyright (C) 2008 Jaroslaw Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kprotocolmanager.h" #include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class KProtocolManagerPrivate { public: KProtocolManagerPrivate(); ~KProtocolManagerPrivate(); KSharedConfig::Ptr config; KSharedConfig::Ptr http_config; KUrl url; QString protocol; QString proxy; QString modifiers; QString useragent; }; K_GLOBAL_STATIC(KProtocolManagerPrivate, kProtocolManagerPrivate) KProtocolManagerPrivate::KProtocolManagerPrivate() { // post routine since KConfig::sync() breaks if called too late qAddPostRoutine(kProtocolManagerPrivate.destroy); } KProtocolManagerPrivate::~KProtocolManagerPrivate() { qRemovePostRoutine(kProtocolManagerPrivate.destroy); } // DEFAULT USERAGENT STRING #define CFG_DEFAULT_UAGENT(X) \ QString("Mozilla/5.0 (compatible; Konqueror/%1.%2%3) KHTML/%4.%5.%6 (like Gecko)") \ .arg(KDE_VERSION_MAJOR).arg(KDE_VERSION_MINOR).arg(X).arg(KDE_VERSION_MAJOR).arg(KDE_VERSION_MINOR).arg(KDE_VERSION_RELEASE) #define PRIVATE_DATA \ KProtocolManagerPrivate *d = kProtocolManagerPrivate void KProtocolManager::reparseConfiguration() { PRIVATE_DATA; if (d->http_config) { d->http_config->reparseConfiguration(); } if (d->config) { d->config->reparseConfiguration(); } d->protocol = QString(); d->proxy = QString(); d->modifiers = QString(); d->useragent = QString(); d->url.clear(); // Force the slave config to re-read its config... KIO::SlaveConfig::self()->reset (); } KSharedConfig::Ptr KProtocolManager::config() { PRIVATE_DATA; if (!d->config) { d->config = KSharedConfig::openConfig("kioslaverc", KConfig::NoGlobals); } return d->config; } static KConfigGroup http_config() { PRIVATE_DATA; if (!d->http_config) { d->http_config = KSharedConfig::openConfig("kio_httprc", KConfig::NoGlobals); } return KConfigGroup(d->http_config, QString()); } /*=============================== TIMEOUT SETTINGS ==========================*/ int KProtocolManager::readTimeout() { KConfigGroup cg( config(), QString() ); int val = cg.readEntry( "ReadTimeout", DEFAULT_READ_TIMEOUT ); return qMax(MIN_TIMEOUT_VALUE, val); } int KProtocolManager::connectTimeout() { KConfigGroup cg( config(), QString() ); int val = cg.readEntry( "ConnectTimeout", DEFAULT_CONNECT_TIMEOUT ); return qMax(MIN_TIMEOUT_VALUE, val); } int KProtocolManager::proxyConnectTimeout() { KConfigGroup cg( config(), QString() ); int val = cg.readEntry( "ProxyConnectTimeout", DEFAULT_PROXY_CONNECT_TIMEOUT ); return qMax(MIN_TIMEOUT_VALUE, val); } int KProtocolManager::responseTimeout() { KConfigGroup cg( config(), QString() ); int val = cg.readEntry( "ResponseTimeout", DEFAULT_RESPONSE_TIMEOUT ); return qMax(MIN_TIMEOUT_VALUE, val); } /*========================== PROXY SETTINGS =================================*/ bool KProtocolManager::useProxy() { return proxyType() != NoProxy; } bool KProtocolManager::useReverseProxy() { KConfigGroup cg(config(), "Proxy Settings" ); return cg.readEntry("ReversedException", false); } KProtocolManager::ProxyType KProtocolManager::proxyType() { KConfigGroup cg(config(), "Proxy Settings" ); return static_cast(cg.readEntry( "ProxyType" , 0)); } KProtocolManager::ProxyAuthMode KProtocolManager::proxyAuthMode() { KConfigGroup cg(config(), "Proxy Settings" ); return static_cast(cg.readEntry( "AuthMode" , 0)); } /*========================== CACHING =====================================*/ bool KProtocolManager::useCache() { return http_config().readEntry( "UseCache", true ); } KIO::CacheControl KProtocolManager::cacheControl() { QString tmp = http_config().readEntry("cache"); if (tmp.isEmpty()) return DEFAULT_CACHE_CONTROL; return KIO::parseCacheControl(tmp); } QString KProtocolManager::cacheDir() { return http_config().readPathEntry("CacheDir", KGlobal::dirs()->saveLocation("cache","http")); } int KProtocolManager::maxCacheAge() { return http_config().readEntry( "MaxCacheAge", DEFAULT_MAX_CACHE_AGE ); // 14 days } int KProtocolManager::maxCacheSize() { return http_config().readEntry( "MaxCacheSize", DEFAULT_MAX_CACHE_SIZE ); // 5 MB } QString KProtocolManager::noProxyFor() { KProtocolManager::ProxyType type = proxyType(); QString noProxy = config()->group("Proxy Settings").readEntry( "NoProxyFor" ); if (type == EnvVarProxy) noProxy = QString::fromLocal8Bit(getenv(noProxy.toLocal8Bit())); return noProxy; } QString KProtocolManager::proxyFor( const QString& protocol ) { QString scheme = protocol.toLower(); if (scheme == "webdav") scheme = "http"; else if (scheme == "webdavs") scheme = "https"; return config()->group("Proxy Settings" ).readEntry( scheme + "Proxy", QString() ); } QString KProtocolManager::proxyForUrl( const KUrl &url ) { QString proxy; ProxyType pt = proxyType(); switch (pt) { case PACProxy: case WPADProxy: if (!url.host().isEmpty()) { KUrl u (url); QString p = u.protocol().toLower(); // webdav is a KDE specific protocol. Look up proxy // information using HTTP instead... if ( p == "webdav" ) { p = "http"; u.setProtocol( p ); } else if ( p == "webdavs" ) { p = "https"; u.setProtocol( p ); } if ( p.startsWith("http") || p == "ftp" || p == "gopher" ) { QDBusReply reply = QDBusInterface( "org.kde.kded", "/modules/proxyscout", "org.kde.KPAC.ProxyScout" ) .call( "proxyForURL", u.url() ); proxy = reply; } } break; case EnvVarProxy: proxy = QString::fromLocal8Bit(getenv(proxyFor(url.protocol()).toLocal8Bit())).trimmed(); break; case ManualProxy: proxy = proxyFor( url.protocol() ); break; case NoProxy: default: break; } return (proxy.isEmpty() ? QLatin1String("DIRECT") : proxy); } void KProtocolManager::badProxy( const QString &proxy ) { QDBusInterface( "org.kde.kded", "/modules/proxyscout" ) .call( "blackListProxy", proxy ); } /* Domain suffix match. E.g. return true if host is "cuzco.inka.de" and nplist is "inka.de,hadiko.de" or if host is "localhost" and nplist is "localhost". */ static bool revmatch(const char *host, const char *nplist) { if (host == 0) return false; const char *hptr = host + strlen( host ) - 1; const char *nptr = nplist + strlen( nplist ) - 1; const char *shptr = hptr; while ( nptr >= nplist ) { if ( *hptr != *nptr ) { hptr = shptr; // Try to find another domain or host in the list while(--nptr>=nplist && *nptr!=',' && *nptr!=' ') ; // Strip out multiple spaces and commas while(--nptr>=nplist && (*nptr==',' || *nptr==' ')) ; } else { if ( nptr==nplist || nptr[-1]==',' || nptr[-1]==' ') return true; if ( hptr == host ) // e.g. revmatch("bugs.kde.org","mybugs.kde.org") return false; hptr--; nptr--; } } return false; } QString KProtocolManager::slaveProtocol(const KUrl &url, QString &proxy) { if (url.hasSubUrl()) // We don't want the suburl's protocol { KUrl::List list = KUrl::split(url); KUrl l = list.last(); return slaveProtocol(l, proxy); } PRIVATE_DATA; if (d->url == url) { proxy = d->proxy; return d->protocol; } if (useProxy()) { proxy = proxyForUrl(url); if ((proxy != "DIRECT") && (!proxy.isEmpty())) { bool isRevMatch = false; KProtocolManager::ProxyType type = proxyType(); bool useRevProxy = ((type == ManualProxy) && useReverseProxy()); QString noProxy; // Check no proxy information iff the proxy type is either // manual or environment variable based... if ( (type == ManualProxy) || (type == EnvVarProxy) ) noProxy = noProxyFor(); if (!noProxy.isEmpty()) { QString qhost = url.host().toLower(); QByteArray host = qhost.toLatin1(); QString qno_proxy = noProxy.trimmed().toLower(); const QByteArray no_proxy = qno_proxy.toLatin1(); isRevMatch = revmatch(host, no_proxy); // If no match is found and the request url has a port // number, try the combination of "host:port". This allows // users to enter host:port in the No-proxy-For list. if (!isRevMatch && url.port() > 0) { qhost += ':' + QString::number (url.port()); host = qhost.toLatin1(); isRevMatch = revmatch (host, no_proxy); } // If the hostname does not contain a dot, check if // is part of noProxy. if (!isRevMatch && !host.isEmpty() && (strchr(host, '.') == NULL)) isRevMatch = revmatch("", no_proxy); } if ( (!useRevProxy && !isRevMatch) || (useRevProxy && isRevMatch) ) { d->url = proxy; if ( d->url.isValid() ) { // The idea behind slave protocols is not applicable to http // and webdav protocols. QString protocol = url.protocol().toLower(); if (protocol.startsWith("http") || protocol.startsWith("webdav")) d->protocol = protocol; else { d->protocol = d->url.protocol(); kDebug () << "slaveProtocol: " << d->protocol; } d->url = url; d->proxy = proxy; return d->protocol; } } } } d->url = url; d->proxy = proxy = QString(); d->protocol = url.protocol(); return d->protocol; } /*================================= USER-AGENT SETTINGS =====================*/ QString KProtocolManager::userAgentForHost( const QString& hostname ) { QString sendUserAgent = KIO::SlaveConfig::self()->configData("http", hostname.toLower(), "SendUserAgent").toLower(); if (sendUserAgent == "false") return QString(); QString useragent = KIO::SlaveConfig::self()->configData("http", hostname.toLower(), "UserAgent"); // Return the default user-agent if none is specified // for the requested host. if (useragent.isEmpty()) return defaultUserAgent(); return useragent; } QString KProtocolManager::defaultUserAgent( ) { QString modifiers = KIO::SlaveConfig::self()->configData("http", QString(), "UserAgentKeys"); return defaultUserAgent(modifiers); } QString KProtocolManager::defaultUserAgent( const QString &_modifiers ) { PRIVATE_DATA; QString modifiers = _modifiers.toLower(); if (modifiers.isEmpty()) modifiers = DEFAULT_USER_AGENT_KEYS; if (d->modifiers == modifiers) return d->useragent; - QString supp; - struct utsname nam; - if( uname(&nam) >= 0 ) + QString systemName, systemVersion, machine, supp; + if (getSystemNameVersionAndMachine( systemName, systemVersion, machine )) { if( modifiers.contains('o') ) { - supp += QString("; %1").arg(nam.sysname); + supp += QString("; %1").arg(systemName); if ( modifiers.contains('v') ) - supp += QString(" %1").arg(nam.release); + supp += QString(" %1").arg(systemVersion); } +#ifdef Q_WS_X11 if( modifiers.contains('p') ) { - supp += QLatin1String("; X11"); // TODO: determine this valye instead of hardcoding... + supp += QLatin1String("; X11"); } +#endif if( modifiers.contains('m') ) { - supp += QString("; %1").arg(nam.machine); + supp += QString("; %1").arg(machine); } if( modifiers.contains('l') ) { supp += QString("; %1").arg(acceptLanguagesHeader()); } } d->modifiers = modifiers; d->useragent = CFG_DEFAULT_UAGENT(supp); return d->useragent; } +QString KProtocolManager::userAgentForApplication( const QString &appName, const QString& appVersion, + const QStringList& extraInfo ) +{ + QString systemName, systemVersion, machine; + QStringList info; + if (getSystemNameVersionAndMachine( systemName, systemVersion, machine )) + info += QString::fromLatin1("%1/%2").arg(systemName).arg(systemVersion); + info += QString::fromLatin1("KDE/%1.%2.%3").arg(KDE_VERSION_MAJOR) + .arg(KDE_VERSION_MINOR).arg(KDE_VERSION_RELEASE); + if (!machine.isEmpty()) + info += machine; + info += extraInfo; + return QString::fromLatin1("%1/%2 (%3)").arg(appName).arg(appVersion).arg(info.join("; ")); +} + +bool KProtocolManager::getSystemNameVersionAndMachine( + QString& systemName, QString& systemVersion, QString& machine ) +{ + struct utsname unameBuf; + if ( 0 != uname( &unameBuf ) ) + return false; +#ifdef Q_WS_WIN + // we do not use unameBuf.sysname information constructed in kdewin32 + // because we want to get separate name and version + systemName = QLatin1String( "Windows" ); + OSVERSIONINFOEX versioninfo; + ZeroMemory(&versioninfo, sizeof(OSVERSIONINFOEX)); + // try calling GetVersionEx using the OSVERSIONINFOEX, if that fails, try using the OSVERSIONINFO + versioninfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + bool ok = GetVersionEx( (OSVERSIONINFO *) &versioninfo ); + if ( !ok ) { + versioninfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + ok = GetVersionEx( (OSVERSIONINFO *) &versioninfo ); + } + if ( ok ) + systemVersion = QString::fromLatin1("%1.%2") + .arg(versioninfo.dwMajorVersion).arg(versioninfo.dwMinorVersion); +#else + systemName = unameBuf.sysname; + systemVersion = unameBuf.release; +#endif + machine = unameBuf.machine; + return true; +} + QString KProtocolManager::acceptLanguagesHeader() { static const QString &english = KGlobal::staticQString("en"); // User's desktop language preference. QStringList languageList = KGlobal::locale()->languageList(); // Replace possible "C" in the language list with "en", unless "en" is // already pressent. This is to keep user's priorities in order. // If afterwards "en" is still not present, append it. int idx = languageList.indexOf(QString::fromLatin1("C")); if (idx != -1) { if (languageList.contains(english)) languageList.removeAt(idx); else languageList[idx] = english; } if (!languageList.contains(english)) languageList += english; // Some languages may have web codes different from locale codes, // read them from the config and insert in proper order. KConfig acclangConf("accept-languages.codes", KConfig::NoGlobals); KConfigGroup replacementCodes(&acclangConf, "ReplacementCodes"); QStringList languageListFinal; foreach (const QString &lang, languageList) { QStringList langs = replacementCodes.readEntry(lang, QStringList()); if (langs.isEmpty()) languageListFinal += lang; else languageListFinal += langs; } // The header is composed of comma separated languages. QString header = languageListFinal.join(", "); // Some of the languages may have country specifier delimited by // underscore, or modifier delimited by at-sign. // The header should use dashes instead. header.replace('_', '-'); header.replace('@', '-'); return header; } /*==================================== OTHERS ===============================*/ bool KProtocolManager::markPartial() { return config()->group(QByteArray()).readEntry( "MarkPartial", true ); } int KProtocolManager::minimumKeepSize() { return config()->group(QByteArray()).readEntry( "MinimumKeepSize", DEFAULT_MINIMUM_KEEP_SIZE ); // 5000 byte } bool KProtocolManager::autoResume() { return config()->group(QByteArray()).readEntry( "AutoResume", false ); } bool KProtocolManager::persistentConnections() { return config()->group(QByteArray()).readEntry( "PersistentConnections", true ); } bool KProtocolManager::persistentProxyConnection() { return config()->group(QByteArray()).readEntry( "PersistentProxyConnection", false ); } QString KProtocolManager::proxyConfigScript() { return config()->group("Proxy Settings").readEntry( "Proxy Config Script" ); } /* =========================== PROTOCOL CAPABILITIES ============== */ static KProtocolInfo::Ptr findProtocol(const KUrl &url) { QString protocol = url.protocol(); if ( !KProtocolInfo::proxiedBy( protocol ).isEmpty() ) { QString dummy; protocol = KProtocolManager::slaveProtocol(url, dummy); } return KProtocolInfoFactory::self()->findProtocol(protocol); } KProtocolInfo::Type KProtocolManager::inputType( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return KProtocolInfo::T_NONE; return prot->m_inputType; } KProtocolInfo::Type KProtocolManager::outputType( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return KProtocolInfo::T_NONE; return prot->m_outputType; } bool KProtocolManager::isSourceProtocol( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_isSourceProtocol; } bool KProtocolManager::supportsListing( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsListing; } QStringList KProtocolManager::listing( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return QStringList(); return prot->m_listing; } bool KProtocolManager::supportsReading( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsReading; } bool KProtocolManager::supportsWriting( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsWriting; } bool KProtocolManager::supportsMakeDir( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsMakeDir; } bool KProtocolManager::supportsDeleting( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsDeleting; } bool KProtocolManager::supportsLinking( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsLinking; } bool KProtocolManager::supportsMoving( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsMoving; } bool KProtocolManager::supportsOpening( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_supportsOpening; } bool KProtocolManager::canCopyFromFile( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_canCopyFromFile; } bool KProtocolManager::canCopyToFile( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->m_canCopyToFile; } bool KProtocolManager::canRenameFromFile( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->canRenameFromFile(); } bool KProtocolManager::canRenameToFile( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->canRenameToFile(); } bool KProtocolManager::canDeleteRecursive( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return false; return prot->canDeleteRecursive(); } KProtocolInfo::FileNameUsedForCopying KProtocolManager::fileNameUsedForCopying( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return KProtocolInfo::FromUrl; return prot->fileNameUsedForCopying(); } QString KProtocolManager::defaultMimetype( const KUrl &url ) { KProtocolInfo::Ptr prot = findProtocol(url); if ( !prot ) return QString(); return prot->m_defaultMimetype; } #undef PRIVATE_DATA diff --git a/kio/kio/kprotocolmanager.h b/kio/kio/kprotocolmanager.h index 684b076486..6d50e7ba49 100644 --- a/kio/kio/kprotocolmanager.h +++ b/kio/kio/kprotocolmanager.h @@ -1,613 +1,647 @@ /* This file is part of the KDE libraries Copyright (C) 1999 Torben Weis Copyright (C) 2000- Waldo Bastain Copyright (C) 2000- Dawit Alemayehu + Copyright (C) 2008 Jaroslaw Staniek This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KPROTOCOLMANAGER_H #define KPROTOCOLMANAGER_H #include #include #include "kprotocolinfo.h" class KSharedConfig; template class KSharedPtr; typedef KSharedPtr KSharedConfigPtr; namespace KIO { class SlaveConfigPrivate; } // namespace KIO /** * Provides information about I/O (Internet, etc.) settings chosen/set * by the end user. * * KProtocolManager has a heap of static functions that allows only read * access to KDE's IO related settings. These include proxy, cache, file * transfer resumption, timeout and user-agent related settings. * * The information provided by this class is generic enough to be applicable * to any application that makes use of KDE's IO sub-system. Note that this * mean the proxy, timeout etc. settings are saved in a separate user-specific * config file and not in the config file of the application. * * Original author: * @author Torben Weis * * Revised by: * @author Waldo Bastain * @author Dawit Alemayehu * @see KPAC */ class KIO_EXPORT KProtocolManager { public: /*=========================== USER-AGENT SETTINGS ===========================*/ /** - * Returns the default user-agent string. + * Returns the default user-agent string used for web browsing. * * @return the default user-agent string */ static QString defaultUserAgent(); /** - * Returns the default user-agent value. + * Returns the default user-agent value used for web browsing, for example + * "Mozilla/5.0 (compatible; Konqueror/4.0; Linux; X11; i686; en_US) KHTML/4.0.1 (like Gecko)" * * @param keys can be any of the following: * @li 'o' Show OS * @li 'v' Show OS Version - * @li 'p' Show platform + * @li 'p' Show platform (only for X11) * @li 'm' Show machine architecture * @li 'l' Show language * @return the default user-agent value with the given @p keys */ static QString defaultUserAgent(const QString &keys); /** - * Returns the userAgent string configured for the + * Returns the application's user-agent string. + * Example string is "KMail/1.9.50 (Windows/6.0; KDE/3.97.1; i686; svn-762186; 2008-01-15)", + * where "KMail" is the @p appName parameter, "1.9.50" is the @p appVersion parameter, + * "Windows/6.0; KDE/3.97.1; i686" part is added automatically and "svn-762186; 2008-01-15" + * is provided by @p extraInfo list. + * + * @param appName name of the application + * @param appVersion name of the application + * @param extraInfo a list of elements that will be appended to the string as extra information + * @return the application's user-agent string + * + * @since 4.1 + */ + static QString userAgentForApplication( const QString &appName, const QString& appVersion, + const QStringList& extraInfo = QStringList() ); + + /** + * Returns the user-agent string configured for the * specified host. * * If hostname is not found or is empty (i.e. "" or * QString()) this function will return the default * user agent. * * @param hostname name of the host - * @return specified userAgent string + * @return specified user-agent string */ static QString userAgentForHost( const QString &hostname ); + /* + * Returns system name, version and machine type, for example "Windows", "5.1", "i686". + * This information can be used for constructing custom user-agent strings. + * + * @param systemName system name + * @param systemVersion system version + * @param machine machine type + + * @return true if system name, version and machine type has been provided + * + * @since 4.1 + */ + static bool getSystemNameVersionAndMachine( + QString& systemName, QString& systemVersion, QString& machine ); + /*=========================== TIMEOUT CONFIG ================================*/ /** * Returns the preferred timeout value for reading from * remote connections in seconds. * * @return timeout value for remote connection in secs. */ static int readTimeout(); /** * Returns the preferred timeout value for remote connections * in seconds. * * @return timeout value for remote connection in secs. */ static int connectTimeout(); /** * Returns the preferred timeout value for proxy connections * in seconds. * * @return timeout value for proxy connection in secs. */ static int proxyConnectTimeout(); /** * Returns the preferred response timeout value for * remote connecting in seconds. * * @return timeout value for remote connection in seconds. */ static int responseTimeout(); /*=============================== PROXY CONFIG ==============================*/ /** * Returns whether or not the user specified the * use of proxy server to make connections. * @return true to use a proxy */ static bool useProxy(); /** * Returns whether or not the the proxy server * lookup should be reversed or not. * @return true to use a reversed proxy */ static bool useReverseProxy(); /** * Types of proxy configuration * @li NoProxy - No proxy is used * @li ManualProxy - Proxies are manually configured * @li PACProxy - A Proxy configuration URL has been given * @li WPADProxy - A proxy should be automatically discovered * @li EnvVarProxy - Use the proxy values set through environment variables. */ enum ProxyType { NoProxy, ManualProxy, PACProxy, WPADProxy, EnvVarProxy }; /** * Returns the type of proxy configuration that is used. * @return the proxy type */ static ProxyType proxyType(); /** * Proxy authorization modes. * * @li Prompt - Ask for authorization as needed * @li Automatic - Use auto login as defined in kionetrc files. */ enum ProxyAuthMode { Prompt, Automatic }; /** * Returns the way proxy authorization should be handled. * * @return the proxy authorization mode * @see ProxyAuthMode */ static ProxyAuthMode proxyAuthMode(); /** * Returns the strings for hosts that should contacted * DIRECTLY, bypassing any proxy settings. * @return a list of (comma-separated) hostnames or partial host * names */ static QString noProxyFor(); /** * Returns the proxy server address for a given * protocol. * * @param protocol the protocol whose proxy info is needed * @returns the proxy server address if one is available, * or QString() if not available */ static QString proxyFor( const QString& protocol ); /** * Returns the Proxy server address for a given URL * If automatic proxy configuration is configured, KPAC * is used to determine the proxy server, otherwise the return * value of proxyFor for the URL's protocol is used. * If an empty string is returned, the request is to be aborted, * a return value of "DIRECT" requests a direct connection. * * @param url the URL whose proxy info is needed * @returns the proxy server address if one is available * or QString() otherwise */ static QString proxyForUrl( const KUrl& url ); /** * Marks this proxy as bad (down). It will not be used for the * next 30 minutes. (The script may supply an alternate proxy) * @param proxy the proxy to mark as bad (as URL) */ static void badProxy( const QString & proxy ); /** * Returns the URL of the script for automatic proxy configuration. * @return the proxy configuration script */ static QString proxyConfigScript(); /*========================== CACHE CONFIG ===================================*/ /** * Returns true/false to indicate whether a cache * should be used * * @return true to use the cache, false otherwisea */ static bool useCache(); /** * Returns the maximum age in seconds cached files should be * kept before they are deleted as necessary. * * @return the maximum cache age in seconds */ static int maxCacheAge(); /** * Returns the maximum size that can be used for caching. * * By default this function returns the DEFAULT_MAX_CACHE_SIZE * value as defined in http_slave_defaults.h. Not that the * value returned is in bytes, hence a value of 5120 would mean * 5 Kb. * * @return the maximum cache size in bytes */ static int maxCacheSize(); // Maximum cache size in Kb. /** * The directory which contains the cache files. * @return the directory that contains the cache files */ static QString cacheDir(); /** * Returns the Cache control directive to be used. * @return the cache control value */ static KIO::CacheControl cacheControl(); /*============================ DOWNLOAD CONFIG ==============================*/ /** * Returns true if partial downloads should be * automatically resumed. * @return true to resume partial downloads */ static bool autoResume(); /** * Returns true if partial downloads should be marked * with a ".part" extension. * @return true if partial downloads should get an ".part" extension */ static bool markPartial(); /** * Returns the minimum file size for keeping aborted * downloads. * * Any data downloaded that does not meet this minimum * requirement will simply be discarded. The default size * is 5 KB. * * @return the minimum keep size for aborted downloads in bytes */ static int minimumKeepSize(); /*============================ NETWORK CONNECTIONS ==========================*/ /** * Returns true if proxy connections should be persistent. * @return true if proxy connections should be persistent */ static bool persistentProxyConnection(); /** * Returns true if connections should be persistent * @return true if the connections should be persistent */ static bool persistentConnections(); /*===================== PROTOCOL CAPABILITIES ===============================*/ /** * Returns whether the protocol can list files/objects. * If a protocol supports listing it can be browsed in e.g. file-dialogs * and konqueror. * * Whether a protocol supports listing is determined by the "listing=" * field in the protocol description file. * If the protocol support listing it should list the fields it provides in * this field. If the protocol does not support listing this field should * remain empty (default.) * * @param url the url to check * @return true if the protocol support listing * @see listing() */ static bool supportsListing( const KUrl &url ); /** * Returns whether the protocol can retrieve data from URLs. * * This corresponds to the "reading=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if it is possible to read from the URL */ static bool supportsReading( const KUrl &url ); /** * Returns whether the protocol can store data to URLs. * * This corresponds to the "writing=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol supports writing */ static bool supportsWriting( const KUrl &url ); /** * Returns whether the protocol can create directories/folders. * * This corresponds to the "makedir=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol can create directories */ static bool supportsMakeDir( const KUrl &url ); /** * Returns whether the protocol can delete files/objects. * * This corresponds to the "deleting=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol supports deleting */ static bool supportsDeleting( const KUrl &url ); /** * Returns whether the protocol can create links between files/objects. * * This corresponds to the "linking=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol supports linking */ static bool supportsLinking( const KUrl &url ); /** * Returns whether the protocol can move files/objects between different * locations. * * This corresponds to the "moving=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol supports moving */ static bool supportsMoving( const KUrl &url ); /** * Returns whether the protocol can be opened using KIO::open(const KUrl&). * * This corresponds to the "opening=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol supports opening */ static bool supportsOpening( const KUrl &url ); /** * Returns whether the protocol can copy files/objects directly from the * filesystem itself. If not, the application will read files from the * filesystem using the file-protocol and pass the data on to the destination * protocol. * * This corresponds to the "copyFromFile=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol can copy files from the local file system */ static bool canCopyFromFile( const KUrl &url ); /** * Returns whether the protocol can copy files/objects directly to the * filesystem itself. If not, the application will receive the data from * the source protocol and store it in the filesystem using the * file-protocol. * * This corresponds to the "copyToFile=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol can copy files to the local file system */ static bool canCopyToFile( const KUrl &url ); /** * Returns whether the protocol can rename (i.e. move fast) files/objects * directly from the filesystem itself. If not, the application will read * files from the filesystem using the file-protocol and pass the data on * to the destination protocol. * * This corresponds to the "renameFromFile=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol can rename/move files from the local file system */ static bool canRenameFromFile( const KUrl &url ); /** * Returns whether the protocol can rename (i.e. move fast) files/objects * directly to the filesystem itself. If not, the application will receive * the data from the source protocol and store it in the filesystem using the * file-protocol. * * This corresponds to the "renameToFile=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol can rename files to the local file system */ static bool canRenameToFile( const KUrl &url ); /** * Returns whether the protocol can recursively delete directories by itself. * If not (the usual case) then KIO will list the directory and delete files * and empty directories one by one. * * This corresponds to the "deleteRecursive=" field in the protocol description file. * Valid values for this field are "true" or "false" (default). * * @param url the url to check * @return true if the protocol can delete non-empty directories by itself. */ static bool canDeleteRecursive( const KUrl &url ); /** * This setting defines the strategy to use for generating a filename, when * copying a file or directory to another directory. By default the destination * filename is made out of the filename in the source URL. However if the * ioslave displays names that are different from the filename of the URL * (e.g. kio_fonts shows Arial for arial.ttf, or kio_trash shows foo.txt and * uses some internal URL), using Name means that the display name (UDS_NAME) * will be used to as the filename in the destination directory. * * This corresponds to the "fileNameUsedForCopying=" field in the protocol description file. * Valid values for this field are "Name" or "FromURL" (default). * * @param url the url to check * @return how to generate the filename in the destination directory when copying/moving */ static KProtocolInfo::FileNameUsedForCopying fileNameUsedForCopying( const KUrl &url ); /** * Returns default mimetype for this URL based on the protocol. * * This corresponds to the "defaultMimetype=" field in the protocol description file. * * @param url the url to check * @return the default mime type of the protocol, or null if unknown */ static QString defaultMimetype( const KUrl& url ); /** * Returns whether the protocol should be treated as a filesystem * or as a stream when reading from it. * * This corresponds to the "input=" field in the protocol description file. * Valid values for this field are "filesystem", "stream" or "none" (default). * * @param url the url to check * @return the input type of the given @p url */ static KProtocolInfo::Type inputType( const KUrl &url ); /** * Returns whether the protocol should be treated as a filesystem * or as a stream when writing to it. * * This corresponds to the "output=" field in the protocol description file. * Valid values for this field are "filesystem", "stream" or "none" (default). * * @param url the url to check * @return the output type of the given @p url */ static KProtocolInfo::Type outputType( const KUrl &url ); /** * Returns the list of fields this protocol returns when listing * The current possibilities are * Name, Type, Size, Date, AccessDate, Access, Owner, Group, Link, URL, MimeType * as well as Extra1, Extra2 etc. for extra fields (see extraFields). * * This corresponds to the "listing=" field in the protocol description file. * The supported fields should be separated with ',' in the protocol description file. * * @param url the url to check * @return a list of field names */ static QStringList listing( const KUrl &url ); /** * Returns whether the protocol can act as a source protocol. * * A source protocol retrieves data from or stores data to the * location specified by a URL. * A source protocol is the opposite of a filter protocol. * * The "source=" field in the protocol description file determines * whether a protocol is a source protocol or a filter protocol. * @param url the url to check * @return true if the protocol is a source of data (e.g. http), false if the * protocol is a filter (e.g. gzip) */ static bool isSourceProtocol( const KUrl &url ); /*=============================== OTHERS ====================================*/ /** * Force a reload of the general config file of * io-slaves ( kioslaverc). */ static void reparseConfiguration(); /** * Return the protocol to use in order to handle the given @p url * It's usually the same, except that FTP, when handled by a proxy, * needs an HTTP ioslave. * * When a proxy is to be used, proxy contains the URL for the proxy. * @param url the url to check * @param proxy the URL of the proxy to use * @return the slave protocol (e.g. 'http'), can be null if unknown */ static QString slaveProtocol(const KUrl &url, QString &proxy); /** * Return Accept-Languages header built up according to user's desktop * language settings. * @return Accept-Languages header string */ static QString acceptLanguagesHeader(); private: friend class KIO::SlaveConfigPrivate; /** * @internal * (Shared with SlaveConfig) */ KDE_NO_EXPORT static KSharedConfigPtr config(); }; #endif