|
|
@ -27,11 +27,13 @@ |
|
|
|
* exception statement from your version. |
|
|
|
* exception statement from your version. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDateTime> |
|
|
|
#include <QNetworkRequest> |
|
|
|
#include <QNetworkRequest> |
|
|
|
#include <QNetworkProxy> |
|
|
|
#include <QNetworkProxy> |
|
|
|
#include <QNetworkCookieJar> |
|
|
|
#include <QNetworkCookieJar> |
|
|
|
#include <QNetworkReply> |
|
|
|
#include <QNetworkReply> |
|
|
|
#include <QNetworkCookie> |
|
|
|
#include <QNetworkCookie> |
|
|
|
|
|
|
|
#include <QNetworkCookieJar> |
|
|
|
#include <QSslError> |
|
|
|
#include <QSslError> |
|
|
|
#include <QUrl> |
|
|
|
#include <QUrl> |
|
|
|
#include <QDebug> |
|
|
|
#include <QDebug> |
|
|
@ -40,6 +42,71 @@ |
|
|
|
#include "downloadhandler.h" |
|
|
|
#include "downloadhandler.h" |
|
|
|
#include "downloadmanager.h" |
|
|
|
#include "downloadmanager.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
class NetworkCookieJar: public QNetworkCookieJar |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
explicit NetworkCookieJar(QObject *parent = 0) |
|
|
|
|
|
|
|
: QNetworkCookieJar(parent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QDateTime now = QDateTime::currentDateTime(); |
|
|
|
|
|
|
|
QList<QNetworkCookie> cookies = Preferences::instance()->getNetworkCookies(); |
|
|
|
|
|
|
|
foreach (const QNetworkCookie &cookie, Preferences::instance()->getNetworkCookies()) { |
|
|
|
|
|
|
|
if (cookie.isSessionCookie() || (cookie.expirationDate() <= now)) |
|
|
|
|
|
|
|
cookies.removeAll(cookie); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setAllCookies(cookies); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
~NetworkCookieJar() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QDateTime now = QDateTime::currentDateTime(); |
|
|
|
|
|
|
|
QList<QNetworkCookie> cookies = allCookies(); |
|
|
|
|
|
|
|
foreach (const QNetworkCookie &cookie, allCookies()) { |
|
|
|
|
|
|
|
if (cookie.isSessionCookie() || (cookie.expirationDate() <= now)) |
|
|
|
|
|
|
|
cookies.removeAll(cookie); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Preferences::instance()->setNetworkCookies(cookies); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef QBT_USES_QT5 |
|
|
|
|
|
|
|
virtual bool deleteCookie(const QNetworkCookie &cookie) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto myCookies = allCookies(); |
|
|
|
|
|
|
|
myCookies.removeAll(cookie); |
|
|
|
|
|
|
|
setAllCookies(myCookies); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QList<QNetworkCookie> cookiesForUrl(const QUrl &url) const override |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QDateTime now = QDateTime::currentDateTime(); |
|
|
|
|
|
|
|
QList<QNetworkCookie> cookies = QNetworkCookieJar::cookiesForUrl(url); |
|
|
|
|
|
|
|
foreach (const QNetworkCookie &cookie, QNetworkCookieJar::cookiesForUrl(url)) { |
|
|
|
|
|
|
|
if (!cookie.isSessionCookie() && (cookie.expirationDate() <= now)) |
|
|
|
|
|
|
|
cookies.removeAll(cookie); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return cookies; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) override |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QDateTime now = QDateTime::currentDateTime(); |
|
|
|
|
|
|
|
QList<QNetworkCookie> cookies = cookieList; |
|
|
|
|
|
|
|
foreach (const QNetworkCookie &cookie, cookieList) { |
|
|
|
|
|
|
|
if (!cookie.isSessionCookie() && (cookie.expirationDate() <= now)) |
|
|
|
|
|
|
|
cookies.removeAll(cookie); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return QNetworkCookieJar::setCookiesFromUrl(cookies, url); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
using namespace Net; |
|
|
|
using namespace Net; |
|
|
|
|
|
|
|
|
|
|
|
DownloadManager *DownloadManager::m_instance = 0; |
|
|
|
DownloadManager *DownloadManager::m_instance = 0; |
|
|
@ -50,10 +117,7 @@ DownloadManager::DownloadManager(QObject *parent) |
|
|
|
#ifndef QT_NO_OPENSSL |
|
|
|
#ifndef QT_NO_OPENSSL |
|
|
|
connect(&m_networkManager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)), this, SLOT(ignoreSslErrors(QNetworkReply *, QList<QSslError>))); |
|
|
|
connect(&m_networkManager, SIGNAL(sslErrors(QNetworkReply *, QList<QSslError>)), this, SLOT(ignoreSslErrors(QNetworkReply *, QList<QSslError>))); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
m_networkManager.setCookieJar(new NetworkCookieJar(this)); |
|
|
|
|
|
|
|
|
|
|
|
DownloadManager::~DownloadManager() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DownloadManager::initInstance() |
|
|
|
void DownloadManager::initInstance() |
|
|
@ -92,22 +156,27 @@ DownloadHandler *DownloadManager::downloadUrl(const QString &url, bool saveToFil |
|
|
|
request.setRawHeader("Referer", request.url().toEncoded().data()); |
|
|
|
request.setRawHeader("Referer", request.url().toEncoded().data()); |
|
|
|
|
|
|
|
|
|
|
|
qDebug("Downloading %s...", request.url().toEncoded().data()); |
|
|
|
qDebug("Downloading %s...", request.url().toEncoded().data()); |
|
|
|
|
|
|
|
qDebug() << "Cookies:" << m_networkManager.cookieJar()->cookiesForUrl(request.url()); |
|
|
|
// accept gzip
|
|
|
|
// accept gzip
|
|
|
|
request.setRawHeader("Accept-Encoding", "gzip"); |
|
|
|
request.setRawHeader("Accept-Encoding", "gzip"); |
|
|
|
return new DownloadHandler(m_networkManager.get(request), this, saveToFile, limit, handleRedirectToMagnet); |
|
|
|
return new DownloadHandler(m_networkManager.get(request), this, saveToFile, limit, handleRedirectToMagnet); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QList<QNetworkCookie> DownloadManager::cookiesForUrl(const QString &url) const |
|
|
|
QList<QNetworkCookie> DownloadManager::cookiesForUrl(const QUrl &url) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return m_networkManager.cookieJar()->cookiesForUrl(url); |
|
|
|
return m_networkManager.cookieJar()->cookiesForUrl(url); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool DownloadManager::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) |
|
|
|
bool DownloadManager::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url) |
|
|
|
{ |
|
|
|
{ |
|
|
|
qDebug("Setting %d cookies for url: %s", cookieList.size(), qPrintable(url.toString())); |
|
|
|
|
|
|
|
return m_networkManager.cookieJar()->setCookiesFromUrl(cookieList, url); |
|
|
|
return m_networkManager.cookieJar()->setCookiesFromUrl(cookieList, url); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool DownloadManager::deleteCookie(const QNetworkCookie &cookie) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
return static_cast<NetworkCookieJar *>(m_networkManager.cookieJar())->deleteCookie(cookie); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void DownloadManager::applyProxySettings() |
|
|
|
void DownloadManager::applyProxySettings() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QNetworkProxy proxy; |
|
|
|
QNetworkProxy proxy; |
|
|
|