Browse Source

Fix cookie support for RSS feeds (closes #119)

adaptive-webui-19844
Christophe Dumez 12 years ago
parent
commit
6cf2f942e7
  1. 4
      src/downloadthread.h
  2. 11
      src/rss/rss_imp.cpp
  3. 8
      src/rss/rssfeed.cpp
  4. 2
      src/rss/rssfeed.h
  5. 14
      src/rss/rsssettings.h

4
src/downloadthread.h

@ -46,8 +46,8 @@ class DownloadThread : public QObject { @@ -46,8 +46,8 @@ class DownloadThread : public QObject {
public:
DownloadThread(QObject* parent = 0);
QNetworkReply* downloadUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
void downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& raw_cookies = QList<QNetworkCookie>());
QNetworkReply* downloadUrl(const QString &url, const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
void downloadTorrentUrl(const QString &url, const QList<QNetworkCookie>& cookies = QList<QNetworkCookie>());
//void setProxy(QString IP, int port, QString username, QString password);
signals:

11
src/rss/rss_imp.cpp

@ -347,19 +347,10 @@ void RSSImp::downloadSelectedTorrents() @@ -347,19 +347,10 @@ void RSSImp::downloadSelectedTorrents()
QBtSession::instance()->addMagnetInteractive(torrentLink);
else {
// Load possible cookies
QList<QNetworkCookie> cookies;
QString feed_url = m_feedList->getItemID(m_feedList->selectedItems().first());
QString feed_hostname = QUrl::fromEncoded(feed_url.toUtf8()).host();
const QList<QByteArray> raw_cookies = RssSettings().getHostNameCookies(feed_hostname);
foreach (const QByteArray& raw_cookie, raw_cookies) {
QList<QByteArray> cookie_parts = raw_cookie.split('=');
if (cookie_parts.size() == 2) {
qDebug("Loading cookie: %s = %s", cookie_parts.first().constData(), cookie_parts.last().constData());
cookies << QNetworkCookie(cookie_parts.first(), cookie_parts.last());
}
}
QList<QNetworkCookie> cookies = RssSettings().getHostNameQNetworkCookies(feed_hostname);
qDebug("Loaded %d cookies for RSS item\n", cookies.size());
QBtSession::instance()->downloadFromUrl(torrentLink, cookies);
}
}

8
src/rss/rssfeed.cpp

@ -136,6 +136,12 @@ void RssFeed::addArticle(const RssArticlePtr& article) @@ -136,6 +136,12 @@ void RssFeed::addArticle(const RssArticlePtr& article)
}
}
QList<QNetworkCookie> RssFeed::feedCookies() const
{
QString feed_hostname = QUrl::fromEncoded(m_url.toUtf8()).host();
return RssSettings().getHostNameQNetworkCookies(feed_hostname);
}
bool RssFeed::refresh()
{
if (m_loading) {
@ -144,7 +150,7 @@ bool RssFeed::refresh() @@ -144,7 +150,7 @@ bool RssFeed::refresh()
}
m_loading = true;
// Download the RSS again
m_manager->rssDownloader()->downloadUrl(m_url);
m_manager->rssDownloader()->downloadUrl(m_url, feedCookies());
return true;
}

2
src/rss/rssfeed.h

@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
#include <QSharedPointer>
#include <QVariantHash>
#include <QXmlStreamReader>
#include <QNetworkCookie>
#include "rssfile.h"
@ -90,6 +91,7 @@ private: @@ -90,6 +91,7 @@ private:
void loadItemsFromDisk();
void addArticle(const RssArticlePtr& article);
void downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const RssArticlePtr& article);
QList<QNetworkCookie> feedCookies() const;
private:
RssManager* m_manager;

14
src/rss/rsssettings.h

@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
#define RSSSETTINGS_H
#include <QStringList>
#include <QNetworkCookie>
#include "qinisettings.h"
class RssSettings: public QIniSettings{
@ -94,6 +95,19 @@ public: @@ -94,6 +95,19 @@ public:
return raw_cookies.split(':');
}
QList<QNetworkCookie> getHostNameQNetworkCookies(const QString& host_name) const {
QList<QNetworkCookie> cookies;
const QList<QByteArray> raw_cookies = getHostNameCookies(host_name);
foreach (const QByteArray& raw_cookie, raw_cookies) {
QList<QByteArray> cookie_parts = raw_cookie.split('=');
if (cookie_parts.size() == 2) {
qDebug("Loading cookie: %s = %s", cookie_parts.first().constData(), cookie_parts.last().constData());
cookies << QNetworkCookie(cookie_parts.first(), cookie_parts.last());
}
}
return cookies;
}
void setHostNameCookies(const QString &host_name, const QList<QByteArray> &cookies) {
QMap<QString, QVariant> hosts_table = value("Rss/hosts_cookies").toMap();
QByteArray raw_cookies = "";

Loading…
Cancel
Save