mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-04 19:04:30 +00:00
parent
12c151eb69
commit
e378a65508
@ -42,6 +42,9 @@
|
|||||||
#include "downloadhandler.h"
|
#include "downloadhandler.h"
|
||||||
#include "downloadmanager.h"
|
#include "downloadmanager.h"
|
||||||
|
|
||||||
|
// Spoof Firefox 38 user agent to avoid web server banning
|
||||||
|
const char DEFAULT_USER_AGENT[] = "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0";
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
class NetworkCookieJar: public QNetworkCookieJar
|
class NetworkCookieJar: public QNetworkCookieJar
|
||||||
@ -139,7 +142,7 @@ DownloadManager *DownloadManager::instance()
|
|||||||
return m_instance;
|
return m_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadHandler *DownloadManager::downloadUrl(const QString &url, bool saveToFile, qint64 limit, bool handleRedirectToMagnet)
|
DownloadHandler *DownloadManager::downloadUrl(const QString &url, bool saveToFile, qint64 limit, bool handleRedirectToMagnet, const QString &userAgent)
|
||||||
{
|
{
|
||||||
// Update proxy settings
|
// Update proxy settings
|
||||||
applyProxySettings();
|
applyProxySettings();
|
||||||
@ -149,8 +152,10 @@ DownloadHandler *DownloadManager::downloadUrl(const QString &url, bool saveToFil
|
|||||||
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
const QUrl qurl = QUrl::fromEncoded(url.toUtf8());
|
||||||
QNetworkRequest request(qurl);
|
QNetworkRequest request(qurl);
|
||||||
|
|
||||||
// Spoof Firefox 38 user agent to avoid web server banning
|
if (userAgent.isEmpty())
|
||||||
request.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0");
|
request.setRawHeader("User-Agent", DEFAULT_USER_AGENT);
|
||||||
|
else
|
||||||
|
request.setRawHeader("User-Agent", userAgent.toUtf8());
|
||||||
|
|
||||||
// Spoof HTTP Referer to allow adding torrent link from Torcache/KickAssTorrents
|
// Spoof HTTP Referer to allow adding torrent link from Torcache/KickAssTorrents
|
||||||
request.setRawHeader("Referer", request.url().toEncoded().data());
|
request.setRawHeader("Referer", request.url().toEncoded().data());
|
||||||
|
@ -51,7 +51,7 @@ namespace Net
|
|||||||
static void freeInstance();
|
static void freeInstance();
|
||||||
static DownloadManager *instance();
|
static DownloadManager *instance();
|
||||||
|
|
||||||
DownloadHandler *downloadUrl(const QString &url, bool saveToFile = false, qint64 limit = 0, bool handleRedirectToMagnet = false);
|
DownloadHandler *downloadUrl(const QString &url, bool saveToFile = false, qint64 limit = 0, bool handleRedirectToMagnet = false, const QString &userAgent = "");
|
||||||
QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const;
|
QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const;
|
||||||
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
|
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
|
||||||
bool deleteCookie(const QNetworkCookie &cookie);
|
bool deleteCookie(const QNetworkCookie &cookie);
|
||||||
|
@ -28,23 +28,20 @@
|
|||||||
* Contact : chris@qbittorrent.org
|
* Contact : chris@qbittorrent.org
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QNetworkProxy>
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
#include "programupdater.h"
|
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/preferences.h"
|
#include "base/net/downloadmanager.h"
|
||||||
|
#include "base/net/downloadhandler.h"
|
||||||
|
#include "programupdater.h"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
const QUrl RSS_URL("http://www.fosshub.com/software/feedqBittorent");
|
const QString RSS_URL("http://www.fosshub.com/software/feedqBittorent");
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
const QString OS_TYPE("Mac OS X");
|
const QString OS_TYPE("Mac OS X");
|
||||||
@ -59,99 +56,73 @@ ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_invokedByUser(invokedByUser)
|
, m_invokedByUser(invokedByUser)
|
||||||
{
|
{
|
||||||
m_networkManager = new QNetworkAccessManager(this);
|
|
||||||
Preferences* const pref = Preferences::instance();
|
|
||||||
// Proxy support
|
|
||||||
if (pref->isProxyEnabled()) {
|
|
||||||
QNetworkProxy proxy;
|
|
||||||
switch(pref->getProxyType()) {
|
|
||||||
case Proxy::SOCKS4:
|
|
||||||
case Proxy::SOCKS5:
|
|
||||||
case Proxy::SOCKS5_PW:
|
|
||||||
proxy.setType(QNetworkProxy::Socks5Proxy);
|
|
||||||
default:
|
|
||||||
proxy.setType(QNetworkProxy::HttpProxy);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
proxy.setHostName(pref->getProxyIp());
|
|
||||||
proxy.setPort(pref->getProxyPort());
|
|
||||||
// Proxy authentication
|
|
||||||
if (pref->isProxyAuthEnabled()) {
|
|
||||||
proxy.setUser(pref->getProxyUsername());
|
|
||||||
proxy.setPassword(pref->getProxyPassword());
|
|
||||||
}
|
|
||||||
m_networkManager->setProxy(proxy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ProgramUpdater::~ProgramUpdater()
|
|
||||||
{
|
|
||||||
delete m_networkManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramUpdater::checkForUpdates()
|
void ProgramUpdater::checkForUpdates()
|
||||||
{
|
{
|
||||||
// SIGNAL/SLOT
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(
|
||||||
connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
|
RSS_URL, false, 0, false,
|
||||||
this, SLOT(rssDownloadFinished(QNetworkReply*)));
|
// Don't change this User-Agent. In case our updater goes haywire,
|
||||||
// Send the request
|
// the filehost can identify it and contact us.
|
||||||
QNetworkRequest request(RSS_URL);
|
QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION));
|
||||||
// Don't change this User-Agent. In case our updater goes haywire, the filehost can indetify it and contact us.
|
connect(handler, SIGNAL(downloadFinished(QString,QByteArray)), SLOT(rssDownloadFinished(QString,QByteArray)));
|
||||||
request.setRawHeader("User-Agent", QString("qBittorrent/%1 ProgramUpdater (www.qbittorrent.org)").arg(VERSION).toLocal8Bit());
|
connect(handler, SIGNAL(downloadFailed(QString,QString)), SLOT(rssDownloadFailed(QString,QString)));
|
||||||
m_networkManager->get(request);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply)
|
void ProgramUpdater::rssDownloadFinished(const QString &url, const QByteArray &data)
|
||||||
{
|
{
|
||||||
// Disconnect SIGNAL/SLOT
|
Q_UNUSED(url);
|
||||||
disconnect(m_networkManager, 0, this, 0);
|
|
||||||
qDebug("Finished downloading the new qBittorrent updates RSS");
|
qDebug("Finished downloading the new qBittorrent updates RSS");
|
||||||
QString version;
|
QString version;
|
||||||
|
|
||||||
if (!reply->error()) {
|
QXmlStreamReader xml(data);
|
||||||
qDebug("No download error, good.");
|
bool inItem = false;
|
||||||
QXmlStreamReader xml(reply);
|
QString updateLink;
|
||||||
bool inItem = false;
|
QString type;
|
||||||
QString updateLink;
|
|
||||||
QString type;
|
|
||||||
|
|
||||||
while (!xml.atEnd()) {
|
while (!xml.atEnd()) {
|
||||||
xml.readNext();
|
xml.readNext();
|
||||||
|
|
||||||
if (xml.isStartElement()) {
|
if (xml.isStartElement()) {
|
||||||
if (xml.name() == "item")
|
if (xml.name() == "item")
|
||||||
inItem = true;
|
inItem = true;
|
||||||
else if (inItem && xml.name() == "link")
|
else if (inItem && xml.name() == "link")
|
||||||
updateLink = getStringValue(xml);
|
updateLink = getStringValue(xml);
|
||||||
else if (inItem && xml.name() == "type")
|
else if (inItem && xml.name() == "type")
|
||||||
type = getStringValue(xml);
|
type = getStringValue(xml);
|
||||||
else if (inItem && xml.name() == "version")
|
else if (inItem && xml.name() == "version")
|
||||||
version = getStringValue(xml);
|
version = getStringValue(xml);
|
||||||
}
|
}
|
||||||
else if (xml.isEndElement()) {
|
else if (xml.isEndElement()) {
|
||||||
if (inItem && xml.name() == "item") {
|
if (inItem && xml.name() == "item") {
|
||||||
if (type.compare(OS_TYPE, Qt::CaseInsensitive) == 0) {
|
if (type.compare(OS_TYPE, Qt::CaseInsensitive) == 0) {
|
||||||
qDebug("The last update available is %s", qPrintable(version));
|
qDebug("The last update available is %s", qPrintable(version));
|
||||||
if (!version.isEmpty()) {
|
if (!version.isEmpty()) {
|
||||||
qDebug("Detected version is %s", qPrintable(version));
|
qDebug("Detected version is %s", qPrintable(version));
|
||||||
if (isVersionMoreRecent(version))
|
if (isVersionMoreRecent(version))
|
||||||
m_updateUrl = updateLink;
|
m_updateUrl = updateLink;
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
inItem = false;
|
|
||||||
updateLink.clear();
|
|
||||||
type.clear();
|
|
||||||
version.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inItem = false;
|
||||||
|
updateLink.clear();
|
||||||
|
type.clear();
|
||||||
|
version.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit updateCheckFinished(!m_updateUrl.isEmpty(), version, m_invokedByUser);
|
emit updateCheckFinished(!m_updateUrl.isEmpty(), version, m_invokedByUser);
|
||||||
// Clean up
|
}
|
||||||
reply->deleteLater();
|
|
||||||
|
void ProgramUpdater::rssDownloadFailed(const QString &url, const QString &error)
|
||||||
|
{
|
||||||
|
Q_UNUSED(url);
|
||||||
|
|
||||||
|
qDebug() << "Downloading the new qBittorrent updates RSS failed:" << error;
|
||||||
|
emit updateCheckFinished(false, QString(), m_invokedByUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramUpdater::updateProgram()
|
void ProgramUpdater::updateProgram()
|
||||||
|
@ -34,30 +34,27 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
class QNetworkReply;
|
|
||||||
class QNetworkAccessManager;
|
|
||||||
|
|
||||||
class ProgramUpdater: public QObject
|
class ProgramUpdater: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ProgramUpdater(QObject *parent = 0, bool invokedByUser = false);
|
explicit ProgramUpdater(QObject *parent = 0, bool invokedByUser = false);
|
||||||
~ProgramUpdater();
|
|
||||||
void checkForUpdates();
|
void checkForUpdates();
|
||||||
void updateProgram();
|
void updateProgram();
|
||||||
|
|
||||||
protected:
|
|
||||||
bool isVersionMoreRecent(const QString &remoteVersion) const;
|
|
||||||
|
|
||||||
protected slots:
|
|
||||||
void rssDownloadFinished(QNetworkReply* reply);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateCheckFinished(bool updateAvailable, QString version, bool invokedByUser);
|
void updateCheckFinished(bool updateAvailable, QString version, bool invokedByUser);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void rssDownloadFinished(const QString &url, const QByteArray &data);
|
||||||
|
void rssDownloadFailed(const QString &url, const QString &error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool isVersionMoreRecent(const QString &remoteVersion) const;
|
||||||
|
|
||||||
QString m_updateUrl;
|
QString m_updateUrl;
|
||||||
QNetworkAccessManager *m_networkManager;
|
|
||||||
bool m_invokedByUser;
|
bool m_invokedByUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user