diff options
author | jhale <jhale@FreeBSD.org> | 2018-04-06 01:20:36 +0800 |
---|---|---|
committer | jhale <jhale@FreeBSD.org> | 2018-04-06 01:20:36 +0800 |
commit | e67f56dbe3e8006d85e62bb540203dc2b5963f11 (patch) | |
tree | e8fdda6a796b24c407224bd8ed949f431e6b1485 | |
parent | 08505fa944bc66ebd65e47017509cadf91864c55 (diff) | |
download | freebsd-ports-gnome-e67f56dbe3e8006d85e62bb540203dc2b5963f11.tar.gz freebsd-ports-gnome-e67f56dbe3e8006d85e62bb540203dc2b5963f11.tar.zst freebsd-ports-gnome-e67f56dbe3e8006d85e62bb540203dc2b5963f11.zip |
Fix 301 redirects in the UrlBuilder class
- http scheme redirects to https
- Mobile website (m.last.fm) redirects to www.last.fm
- Localized hosts redirect e.g. www.lastfm.de to www.last.fm/de
- New localePath() function has been added to handle the localized
base path since the library was localizing using the host before.
This is not an official fix, but upstream is pretty dead.
Move USES upward
Convert CMAKE_ARGS to CMAKE_ON
-rw-r--r-- | audio/liblastfm/Makefile | 7 | ||||
-rw-r--r-- | audio/liblastfm/files/patch-src_UrlBuilder.cpp | 123 | ||||
-rw-r--r-- | audio/liblastfm/files/patch-src_UrlBuilder.h | 31 | ||||
-rw-r--r-- | audio/liblastfm/files/patch-src_mbid__mp3.c | 2 | ||||
-rw-r--r-- | audio/liblastfm/files/patch-tests_TestUrlBuilder.h | 13 |
5 files changed, 171 insertions, 5 deletions
diff --git a/audio/liblastfm/Makefile b/audio/liblastfm/Makefile index 82b08d1eb999..b5607760dbad 100644 --- a/audio/liblastfm/Makefile +++ b/audio/liblastfm/Makefile @@ -3,7 +3,7 @@ PORTNAME= liblastfm PORTVERSION= 1.0.9 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= audio MAINTAINER= jhale@FreeBSD.org @@ -12,15 +12,14 @@ COMMENT= Qt C++ library for the Last.fm webservices LICENSE= GPLv3+ LICENSE_FILE= ${WRKSRC}/COPYING +USES= cmake pkgconfig USE_GITHUB= yes GH_ACCOUNT= lastfm - -USES= cmake pkgconfig USE_LDCONFIG= yes USE_QT4= corelib dbus network sql xml \ moc_build qmake_build rcc_build -CMAKE_ARGS= -DBUILD_WITH_QT4:BOOL=ON +CMAKE_ON= BUILD_WITH_QT4 OPTIONS_DEFINE= FINGERPRINT TEST OPTIONS_DEFAULT= FINGERPRINT diff --git a/audio/liblastfm/files/patch-src_UrlBuilder.cpp b/audio/liblastfm/files/patch-src_UrlBuilder.cpp new file mode 100644 index 000000000000..dbe336905355 --- /dev/null +++ b/audio/liblastfm/files/patch-src_UrlBuilder.cpp @@ -0,0 +1,123 @@ +url(): + - Use https scheme to avoid 301 redirects + - Override default QUrl::TolerantMode with QUrl::StrictMode for Qt 5.x to + prevent overprocessing the already encoded input URL +localePath(): + - New function to return the base path of the localized website +host(): + - Just return www.last.fm since the localized hosts 301 redirect there +localize(): + - Set the path of the url instead of the host since the localized + hosts 301 redirect to the main website with a localized path +mobilize(): + - Mobile website 301 redirects to main website, so just return the url as-is + +--- src/UrlBuilder.cpp.orig 2014-10-02 14:05:46 UTC ++++ src/UrlBuilder.cpp +@@ -32,7 +32,7 @@ class lastfm::UrlBuilderPrivate (public) + lastfm::UrlBuilder::UrlBuilder( const QString& base ) + : d( new UrlBuilderPrivate ) + { +- d->path = '/' + base.toLatin1(); ++ d->path = localePath().toLatin1() + '/' + base.toLatin1(); + } + + +@@ -60,10 +60,10 @@ QUrl + lastfm::UrlBuilder::url() const + { + QUrl url; +- url.setScheme( "http" ); ++ url.setScheme( "https" ); + url.setHost( host() ); + #if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) +- url.setPath( d->path ); ++ url.setPath( d->path, QUrl::StrictMode ); + #else + url.setEncodedPath( d->path ); + #endif +@@ -85,49 +85,50 @@ lastfm::UrlBuilder::encode( QString s ) + + + QString //static +-lastfm::UrlBuilder::host( const QLocale& locale ) ++lastfm::UrlBuilder::localePath( const QLocale& locale ) + { + switch (locale.language()) + { +- case QLocale::Portuguese: return "www.lastfm.com.br"; +- case QLocale::Turkish: return "www.lastfm.com.tr"; +- case QLocale::French: return "www.lastfm.fr"; +- case QLocale::Italian: return "www.lastfm.it"; +- case QLocale::German: return "www.lastfm.de"; +- case QLocale::Spanish: return "www.lastfm.es"; +- case QLocale::Polish: return "www.lastfm.pl"; +- case QLocale::Russian: return "www.lastfm.ru"; +- case QLocale::Japanese: return "www.lastfm.jp"; +- case QLocale::Swedish: return "www.lastfm.se"; +- case QLocale::Chinese: return "cn.last.fm"; +- default: return "www.last.fm"; ++ case QLocale::Chinese: return "/zh"; ++ case QLocale::French: return "/fr"; ++ case QLocale::German: return "/de"; ++ case QLocale::Italian: return "/it"; ++ case QLocale::Japanese: return "/ja"; ++ case QLocale::Polish: return "/pl"; ++ case QLocale::Portuguese: return "/pt"; ++ case QLocale::Russian: return "/ru"; ++ case QLocale::Spanish: return "/es"; ++ case QLocale::Swedish: return "/sv"; ++ case QLocale::Turkish: return "/tr"; ++ default: return ""; + } + } + + ++QString //static ++lastfm::UrlBuilder::host( const QLocale& locale ) ++{ ++ return "www.last.fm"; ++} ++ ++ + bool // static + lastfm::UrlBuilder::isHost( const QUrl& url ) + { +- QStringList hosts = QStringList() << "www.lastfm.com.br" +- << "www.lastfm.com.tr" +- << "www.lastfm.fr" +- << "www.lastfm.it" +- << "www.lastfm.de" +- << "www.lastfm.es" +- << "www.lastfm.pl" +- << "www.lastfm.ru" +- << "www.lastfm.jp" +- << "www.lastfm.se" +- << "cn.last.fm" +- << "www.last.fm"; ++ QStringList hosts = QStringList() << "www.last.fm"; + + return hosts.contains( url.host() ); + } + ++ + QUrl //static + lastfm::UrlBuilder::localize( QUrl url) + { +- url.setHost( url.host().replace( QRegExp("^(www.)?last.fm"), host() ) ); ++#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) ++ url.setPath( url.path().prepend( localePath() ), QUrl::DecodedMode ); ++#else ++ url.setPath( url.path().prepend( localePath() ) ); ++#endif + return url; + } + +@@ -135,7 +136,6 @@ lastfm::UrlBuilder::localize( QUrl url) + QUrl //static + lastfm::UrlBuilder::mobilize( QUrl url ) + { +- url.setHost( url.host().replace( QRegExp("^(www.)?last"), "m.last" ) ); + return url; + } + diff --git a/audio/liblastfm/files/patch-src_UrlBuilder.h b/audio/liblastfm/files/patch-src_UrlBuilder.h new file mode 100644 index 000000000000..88626358b253 --- /dev/null +++ b/audio/liblastfm/files/patch-src_UrlBuilder.h @@ -0,0 +1,31 @@ +Add prototype for localePath() and adjust comments to reflect current +website layout + +--- src/UrlBuilder.h.orig 2014-10-02 14:05:46 UTC ++++ src/UrlBuilder.h +@@ -44,9 +44,11 @@ namespace lastfm + + QUrl url() const; + +- /** www.last.fm becomes the local version, eg www.lastfm.de */ ++ /** www.last.fm becomes the local version, e.g. www.last.fm/de */ + static QUrl localize( QUrl ); +- /** www.last.fm becomes m.last.fm, localisation is preserved */ ++ ++ /** DEPRECATED: Returns url as-is since the mobile website redirects ++ * to the main website */ + static QUrl mobilize( QUrl ); + + /** Use this to URL encode any database item (artist, track, album). It +@@ -60,7 +62,10 @@ namespace lastfm + */ + static QByteArray encode( QString ); + +- /** returns eg. www.lastfm.de */ ++ /** returns the base path of the localized website e.g. /de */ ++ static QString localePath ( const QLocale& = QLocale() ); ++ ++ /** returns www.last.fm */ + static QString host( const QLocale& = QLocale() ); + + /** return true if url is a last.fm url */ diff --git a/audio/liblastfm/files/patch-src_mbid__mp3.c b/audio/liblastfm/files/patch-src_mbid__mp3.c index 50a5dd1c091e..a56a6974f2cb 100644 --- a/audio/liblastfm/files/patch-src_mbid__mp3.c +++ b/audio/liblastfm/files/patch-src_mbid__mp3.c @@ -4,7 +4,7 @@ warning: logical not is only applied to the left hand side of this comparison [- --- src/mbid_mp3.c.orig 2014-10-02 14:05:46 UTC +++ src/mbid_mp3.c -@@ -94,7 +94,7 @@ int getMP3_MBID(const char *path, char m +@@ -94,7 +94,7 @@ int getMP3_MBID(const char *path, char mbid[MBID_BUFFE while (s) { mfile(3,head,fp,&s); diff --git a/audio/liblastfm/files/patch-tests_TestUrlBuilder.h b/audio/liblastfm/files/patch-tests_TestUrlBuilder.h new file mode 100644 index 000000000000..65807f92c783 --- /dev/null +++ b/audio/liblastfm/files/patch-tests_TestUrlBuilder.h @@ -0,0 +1,13 @@ +http://www.last.fm 301 redirects to https://www.last.fm causing test to fail + +--- tests/TestUrlBuilder.h.orig 2018-03-31 12:04:00 UTC ++++ tests/TestUrlBuilder.h +@@ -81,7 +81,7 @@ private slots: + + void test404() /** @author <max@last.fm> */ + { +- QCOMPARE( getResponseCode( QUrl("http://www.last.fm/404") ), 404 ); ++ QCOMPARE( getResponseCode( QUrl("https://www.last.fm/404") ), 404 ); + } + }; + |