Added support for acc proxy to standard acc.

This commit is contained in:
Martin Rotter 2021-01-21 10:51:45 +01:00
parent 15eadf188e
commit 8e95f8a5ec
13 changed files with 87 additions and 23 deletions

View file

@ -21,9 +21,9 @@ void BaseNetworkAccessManager::loadSettings() {
SETTING(Proxy::Type)).
toInt());
if (selected_proxy_type == QNetworkProxy::NoProxy) {
if (selected_proxy_type == QNetworkProxy::ProxyType::NoProxy) {
// No extra setting is needed, set new proxy and exit this method.
setProxy(QNetworkProxy::NoProxy);
setProxy(QNetworkProxy::ProxyType::NoProxy);
}
else {
setProxy(QNetworkProxy::applicationProxy());

View file

@ -10,8 +10,6 @@ class BaseNetworkAccessManager : public QNetworkAccessManager {
Q_OBJECT
public:
// Constructors and desctructors.
explicit BaseNetworkAccessManager(QObject* parent = nullptr);
public slots:

View file

@ -282,6 +282,12 @@ QVariant Downloader::lastContentType() const {
return m_lastContentType;
}
void Downloader::setProxy(const QNetworkProxy& proxy) {
qWarningNN << LOGSEC_NETWORK << "Setting custom proxy:" << QUOTE_W_SPACE_DOT(proxy.hostName());
m_downloadManager->setProxy(proxy);
}
void Downloader::cancel() {
if (m_activeReply != nullptr) {
// Download action timed-out, too slow connection or target is not reachable.

View file

@ -9,6 +9,7 @@
#include "network-web/httpresponse.h"
#include <QHttpMultiPart>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QSslError>
@ -28,6 +29,8 @@ class Downloader : public QObject {
QList<HttpResponse> lastOutputMultipartData() const;
QVariant lastContentType() const;
void setProxy(const QNetworkProxy& proxy);
public slots:
void cancel();

View file

@ -208,7 +208,8 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url, int ti
QByteArray& output, QNetworkAccessManager::Operation operation,
QList<QPair<QByteArray, QByteArray>> additional_headers,
bool protected_contents,
const QString& username, const QString& password) {
const QString& username, const QString& password,
const QNetworkProxy& custom_proxy) {
Downloader downloader;
QEventLoop loop;
NetworkResult result;
@ -222,6 +223,10 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url, int ti
}
}
if (custom_proxy.type() != QNetworkProxy::ProxyType::DefaultProxy) {
downloader.setProxy(custom_proxy);
}
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
loop.exec();
@ -239,7 +244,8 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
QList<QPair<QByteArray, QByteArray>> additional_headers,
bool protected_contents,
const QString& username,
const QString& password) {
const QString& password,
const QNetworkProxy& custom_proxy) {
Downloader downloader;
QEventLoop loop;
NetworkResult result;
@ -253,6 +259,10 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url,
}
}
if (custom_proxy.type() != QNetworkProxy::ProxyType::DefaultProxy) {
downloader.setProxy(custom_proxy);
}
downloader.manipulateData(url, operation, input_data, timeout, protected_contents, username, password);
loop.exec();

View file

@ -7,6 +7,7 @@
#include <QCoreApplication>
#include <QHttpPart>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QPair>
#include <QVariant>
@ -50,7 +51,8 @@ class NetworkFactory {
QByteArray>> additional_headers = QList<QPair<QByteArray, QByteArray>>(),
bool protected_contents = false,
const QString& username = QString(),
const QString& password = QString());
const QString& password = QString(),
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
static NetworkResult performNetworkOperation(const QString& url, int timeout,
QHttpMultiPart* input_data,
QList<HttpResponse>& output,
@ -59,7 +61,8 @@ class NetworkFactory {
QByteArray>> additional_headers = QList<QPair<QByteArray, QByteArray>>(),
bool protected_contents = false,
const QString& username = QString(),
const QString& password = QString());
const QString& password = QString(),
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
};
#endif // NETWORKFACTORY_H

View file

@ -14,7 +14,7 @@
<string>Form</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="m_gbAuthentication">
<property name="toolTip">
<string>Some feeds require authentication, including GMail feeds. BASIC, NTLM-2 and DIGEST-MD5 authentication schemes are supported.</string>

View file

@ -16,6 +16,8 @@ FormAccountDetails::FormAccountDetails(const QIcon& icon, QWidget* parent)
? qApp->icons()->fromTheme(QSL("emblem-system"))
: icon);
createConnections();
m_proxyDetails->setProxy(QNetworkProxy());
}
void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {

View file

@ -78,8 +78,12 @@ StandardFeedDetails::StandardFeedDetails(QWidget* parent) : QWidget(parent) {
onUrlChanged(QString());
}
void StandardFeedDetails::guessIconOnly(const QString& url, const QString& username, const QString& password) {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url, username, password);
void StandardFeedDetails::guessIconOnly(const QString& url, const QString& username,
const QString& password, const QNetworkProxy& custom_proxy) {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url,
username,
password,
custom_proxy);
if (result.first != nullptr) {
// Icon or whole feed was guessed.
@ -107,8 +111,12 @@ void StandardFeedDetails::guessIconOnly(const QString& url, const QString& usern
}
}
void StandardFeedDetails::guessFeed(const QString& url, const QString& username, const QString& password) {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url, username, password);
void StandardFeedDetails::guessFeed(const QString& url, const QString& username,
const QString& password, const QNetworkProxy& custom_proxy) {
QPair<StandardFeed*, QNetworkReply::NetworkError> result = StandardFeed::guessFeed(url,
username,
password,
custom_proxy);
if (result.first != nullptr) {
// Icon or whole feed was guessed.

View file

@ -7,6 +7,8 @@
#include "ui_standardfeeddetails.h"
#include <QNetworkProxy>
class Category;
class RootItem;
class StandardFeed;
@ -20,8 +22,14 @@ class StandardFeedDetails : public QWidget {
explicit StandardFeedDetails(QWidget* parent = nullptr);
private slots:
void guessIconOnly(const QString& url, const QString& username, const QString& password);
void guessFeed(const QString& url, const QString& username, const QString& password);
void guessIconOnly(const QString& url,
const QString& username,
const QString& password,
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
void guessFeed(const QString& url,
const QString& username,
const QString& password,
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
void onTitleChanged(const QString& new_title);
void onDescriptionChanged(const QString& new_description);

View file

@ -111,7 +111,10 @@ QString StandardFeed::typeToString(StandardFeed::Type type) {
}
void StandardFeed::fetchMetadataForItself() {
QPair<StandardFeed*, QNetworkReply::NetworkError> metadata = guessFeed(url(), username(), password());
QPair<StandardFeed*, QNetworkReply::NetworkError> metadata = guessFeed(url(),
username(),
password(),
getParentServiceRoot()->networkProxy());
if (metadata.first != nullptr && metadata.second == QNetworkReply::NetworkError::NoError) {
// Some properties are not updated when new metadata are fetched.
@ -138,7 +141,8 @@ void StandardFeed::fetchMetadataForItself() {
QPair<StandardFeed*, QNetworkReply::NetworkError> StandardFeed::guessFeed(const QString& url,
const QString& username,
const QString& password) {
const QString& password,
const QNetworkProxy& custom_proxy) {
QPair<StandardFeed*, QNetworkReply::NetworkError> result;
result.first = nullptr;
@ -146,14 +150,17 @@ QPair<StandardFeed*, QNetworkReply::NetworkError> StandardFeed::guessFeed(const
QList<QPair<QByteArray, QByteArray>> headers;
headers << NetworkFactory::generateBasicAuthHeader(username, password);
NetworkResult network_result = NetworkFactory::performNetworkOperation(url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QByteArray(),
feed_contents,
QNetworkAccessManager::GetOperation,
headers);
headers,
false,
{},
{},
custom_proxy);
result.second = network_result.first;
@ -430,7 +437,11 @@ QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) {
QByteArray(),
feed_contents,
QNetworkAccessManager::GetOperation,
headers).first;
headers,
false,
{},
{},
getParentServiceRoot()->networkProxy()).first;
if (m_networkError != QNetworkReply::NoError) {
qWarningNN << LOGSEC_CORE

View file

@ -8,6 +8,7 @@
#include <QCoreApplication>
#include <QDateTime>
#include <QMetaType>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QPair>
#include <QSqlRecord>
@ -72,7 +73,8 @@ class StandardFeed : public Feed {
// or NULL feed.
static QPair<StandardFeed*, QNetworkReply::NetworkError> guessFeed(const QString& url,
const QString& username = QString(),
const QString& password = QString());
const QString& password = QString(),
const QNetworkProxy& custom_proxy = QNetworkProxy::ProxyType::DefaultProxy);
// Converts particular feed type to string.
static QString typeToString(Type type);

View file

@ -152,6 +152,12 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
int completed = 0, total = 0, succeded = 0, failed = 0;
auto* root_item = new StandardServiceRoot();
QStack<RootItem*> model_items;
QNetworkProxy custom_proxy;
if (sourceModel()->rootItem() != nullptr &&
sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
custom_proxy = sourceModel()->rootItem()->getParentServiceRoot()->networkProxy();
}
model_items.push(root_item);
QStack<QDomElement> elements_to_process;
@ -182,7 +188,7 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
QPair<StandardFeed*, QNetworkReply::NetworkError> guessed;
if (fetch_metadata_online &&
(guessed = StandardFeed::guessFeed(feed_url)).second == QNetworkReply::NoError) {
(guessed = StandardFeed::guessFeed(feed_url, {}, {}, custom_proxy)).second == QNetworkReply::NoError) {
// We should obtain fresh metadata from online feed source.
guessed.first->setUrl(feed_url);
active_model_item->appendChild(guessed.first);
@ -287,6 +293,13 @@ void FeedsImportExportModel::importAsTxtURLPerLine(const QByteArray& data, bool
emit layoutChanged();
int completed = 0, succeded = 0, failed = 0;
auto* root_item = new StandardServiceRoot();
QNetworkProxy custom_proxy;
if (sourceModel()->rootItem() != nullptr &&
sourceModel()->rootItem()->getParentServiceRoot() != nullptr) {
custom_proxy = sourceModel()->rootItem()->getParentServiceRoot()->networkProxy();
}
QList<QByteArray> urls = data.split('\n');
for (const QByteArray& url : urls) {
@ -294,7 +307,7 @@ void FeedsImportExportModel::importAsTxtURLPerLine(const QByteArray& data, bool
QPair<StandardFeed*, QNetworkReply::NetworkError> guessed;
if (fetch_metadata_online &&
(guessed = StandardFeed::guessFeed(url)).second == QNetworkReply::NoError) {
(guessed = StandardFeed::guessFeed(url, {}, {}, custom_proxy)).second == QNetworkReply::NoError) {
guessed.first->setUrl(url);
root_item->appendChild(guessed.first);
succeded++;