From 8103019a8d9199d73d56d5aab84673da716f7c12 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Tue, 25 Sep 2012 11:22:11 -0400 Subject: [PATCH] Only accept http urls for resulthints --- .../database/DatabaseCommand_SetPlaylistRevision.cpp | 2 +- src/libtomahawk/database/DatabaseImpl.cpp | 8 +++++++- src/libtomahawk/utils/TomahawkUtils.cpp | 8 ++++++++ src/libtomahawk/utils/TomahawkUtils.h | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp b/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp index da55ce13e..052578e4a 100644 --- a/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp +++ b/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp @@ -280,7 +280,7 @@ DatabaseCommand_SetPlaylistRevision::hintFromQuery( const query_ptr& query ) con if ( foundResult.startsWith( "file://" ) || foundResult.startsWith( "servent://" ) || // Save resulthints for local files and peers automatically - ( foundResult.startsWith( "http" ) && query->saveHTTPResultHint() ) ) + ( TomahawkUtils::whitelistedHttpResultHint( foundResult ) && query->saveHTTPResultHint() ) ) { resultHint = foundResult; } diff --git a/src/libtomahawk/database/DatabaseImpl.cpp b/src/libtomahawk/database/DatabaseImpl.cpp index 31e6d745a..c0825a974 100644 --- a/src/libtomahawk/database/DatabaseImpl.cpp +++ b/src/libtomahawk/database/DatabaseImpl.cpp @@ -618,8 +618,9 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery ) s = SourceList::instance()->getLocal(); fileUrl = url; } - else if ( !url.isEmpty() ) + else if ( TomahawkUtils::whitelistedHttpResultHint( url ) ) { + // Return http resulthint directly res = Tomahawk::Result::get( url ); res->setRID( uuid() ); res->setScore( 1.0 ); @@ -632,6 +633,11 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery ) return res; } + else + { + // No resulthint + return res; + } bool searchlocal = s->isLocal(); diff --git a/src/libtomahawk/utils/TomahawkUtils.cpp b/src/libtomahawk/utils/TomahawkUtils.cpp index 80d99204f..d48d48eeb 100644 --- a/src/libtomahawk/utils/TomahawkUtils.cpp +++ b/src/libtomahawk/utils/TomahawkUtils.cpp @@ -941,6 +941,14 @@ extractBinaryResolver( const QString& zipFilename, QObject* receiver ) } +bool +whitelistedHttpResultHint( const QString& url ) +{ + // For now, just http/https + return url.startsWith( "http" ); +} + + } // ns #include "TomahawkUtils.moc" diff --git a/src/libtomahawk/utils/TomahawkUtils.h b/src/libtomahawk/utils/TomahawkUtils.h index cf6d9d936..fef9539c8 100644 --- a/src/libtomahawk/utils/TomahawkUtils.h +++ b/src/libtomahawk/utils/TomahawkUtils.h @@ -127,6 +127,8 @@ namespace TomahawkUtils // Used by the above, not exported void copyWithAuthentication( const QString& srcFile, const QDir dest, QObject* receiver ); + DLLEXPORT bool whitelistedHttpResultHint( const QString& url ); + /** * This helper is designed to help "update" an existing playlist with a newer revision of itself. * To avoid re-loading the whole playlist and re-resolving tracks that are the same in the old playlist,