[Marble-commits] KDE/kdeedu/marble/src
Jens-Michael Hoffmann
jensmh at gmx.de
Mon Jan 11 23:04:04 CET 2010
SVN commit 1073274 by jmhoffmann:
Change user agent string for HTTP requests to
"Mozilla/5.0 (compatible; Marble/<marble-version>; <download-usage>; <plugin-id>)".
This results for example in:
- "Mozilla/5.0 (compatible; Marble/0.9; Browser; QNamNetworkPlugin)"
- "Mozilla/5.0 (compatible; Marble/0.9.1; BulkDownloader; KioNetworkPlugin)"
M +31 -1 lib/HttpJob.cpp
M +5 -0 lib/HttpJob.h
M +2 -1 lib/global.h
M +1 -1 plugins/network/qnam/QNamDownloadJob.cpp
M +3 -1 plugins/network/qnam/QNamNetworkPlugin.cpp
--- trunk/KDE/kdeedu/marble/src/lib/HttpJob.cpp #1073273:1073274
@@ -13,6 +13,8 @@
#include "HttpJob.h"
+#include <QtCore/QDebug>
+
using namespace Marble;
class Marble::HttpJobPrivate
@@ -25,6 +27,7 @@
QString m_initiatorId;
int m_trialsLeft;
DownloadUsage m_downloadUsage;
+ QString m_pluginId;
};
HttpJobPrivate::HttpJobPrivate( const QUrl & sourceUrl, const QString & destFileName,
@@ -33,7 +36,10 @@
m_destinationFileName( destFileName ),
m_initiatorId( id ),
m_trialsLeft( 3 ),
- m_downloadUsage( DownloadBrowse )
+ m_downloadUsage( DownloadBrowse ),
+ // FIXME: remove initialization depending on if empty pluginId
+ // results in valid user agent string
+ m_pluginId( "unknown" )
{
}
@@ -99,4 +105,28 @@
d->m_downloadUsage = usage;
}
+void HttpJob::setUserAgentPluginId( const QString & pluginId ) const
+{
+ d->m_pluginId = pluginId;
+}
+
+QByteArray HttpJob::userAgent() const
+{
+ QString result( "Mozilla/5.0 (compatible; Marble/%1; %2; %3)" );
+ result.arg( MARBLE_VERSION_STRING );
+ switch ( d->m_downloadUsage ) {
+ case DownloadBrowse:
+ result.arg( "Browser" );
+ break;
+ case DownloadBulk:
+ result.arg( "BulkDownloader" );
+ break;
+ default:
+ qCritical() << "Unknown download usage value:" << d->m_downloadUsage;
+ result.arg( "unknown" );
+ }
+ result.arg( d->m_pluginId );
+ return result.toAscii();
+}
+
#include "HttpJob.moc"
--- trunk/KDE/kdeedu/marble/src/lib/HttpJob.h #1073273:1073274
@@ -15,6 +15,7 @@
#ifndef HTTPJOB_H
#define HTTPJOB_H
+#include <QtCore/QByteArray>
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QUrl>
@@ -49,6 +50,10 @@
DownloadUsage downloadUsage() const;
void setDownloadUsage( const DownloadUsage );
+ void setUserAgentPluginId( const QString & pluginId ) const;
+
+ QByteArray userAgent() const;
+
Q_SIGNALS:
/**
* errorCode contains 0, if there was no error and 1 otherwise
--- trunk/KDE/kdeedu/marble/src/lib/global.h #1073273:1073274
@@ -195,7 +195,8 @@
// Version definitions to use with an external application (as digiKam)
-// String for about dialog.
+// String for about dialog and http user agent
+// FIXME: check if blanks are allowed in user agent version numbers
const QString MARBLE_VERSION_STRING = QString::fromLatin1( "0.10.0 SVN" );
// API Version id:
--- trunk/KDE/kdeedu/marble/src/plugins/network/qnam/QNamDownloadJob.cpp #1073273:1073274
@@ -30,7 +30,7 @@
void QNamDownloadJob::execute()
{
QNetworkRequest request( sourceUrl() );
- request.setRawHeader( "User-Agent", "Marble TinyWebBrowser" );
+ request.setRawHeader( "User-Agent", userAgent() );
m_networkReply = m_networkAccessManager->get( request );
connect( m_networkReply, SIGNAL( downloadProgress( qint64, qint64 )),
--- trunk/KDE/kdeedu/marble/src/plugins/network/qnam/QNamNetworkPlugin.cpp #1073273:1073274
@@ -68,7 +68,9 @@
const QString & destination,
const QString & id )
{
- return new QNamDownloadJob( sourceUrl, destination, id, m_networkAccessManager );
+ HttpJob * const job = new QNamDownloadJob( sourceUrl, destination, id, m_networkAccessManager );
+ job->setUserAgentPluginId( "QNamNetworkPlugin" );
+ return job;
}
NetworkPlugin * QNamNetworkPlugin::newInstance() const
More information about the Marble-commits
mailing list