This commit is contained in:
Martin Rotter 2020-08-13 15:18:07 +02:00
parent 811d29f643
commit 01e79d7c5d
5 changed files with 28 additions and 22 deletions

View File

@ -95,6 +95,7 @@
#define LOGSEC_INOREADER "inoreader: " #define LOGSEC_INOREADER "inoreader: "
#define LOGSEC_TTRSS "tt-rss: " #define LOGSEC_TTRSS "tt-rss: "
#define LOGSEC_GMAIL "gmail: " #define LOGSEC_GMAIL "gmail: "
#define LOGSEC_OAUTH "oauth: "
#define MAX_ZOOM_FACTOR 5.0f #define MAX_ZOOM_FACTOR 5.0f
#define MIN_ZOOM_FACTOR 0.25f #define MIN_ZOOM_FACTOR 0.25f

View File

@ -123,6 +123,10 @@ void Downloader::finished() {
request.setUrl(redirection_url); request.setUrl(redirection_url);
} }
qWarningNN << LOGSEC_NETWORK
<< "We are redirecting URL request to:"
<< QUOTE_W_SPACE_DOT(request.url());
m_activeReply->deleteLater(); m_activeReply->deleteLater();
m_activeReply = nullptr; m_activeReply = nullptr;
@ -175,6 +179,12 @@ void Downloader::progressInternal(qint64 bytes_received, qint64 bytes_total) {
emit progress(bytes_received, bytes_total); emit progress(bytes_received, bytes_total);
} }
void Downloader::setCustomPropsToReply(QNetworkReply* reply) {
reply->setProperty("protected", m_targetProtected);
reply->setProperty("username", m_targetUsername);
reply->setProperty("password", m_targetPassword);
}
QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) { QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) {
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
@ -231,9 +241,7 @@ QList<HttpResponse> Downloader::decodeMultipartAnswer(QNetworkReply* reply) {
void Downloader::runDeleteRequest(const QNetworkRequest& request) { void Downloader::runDeleteRequest(const QNetworkRequest& request) {
m_timer->start(); m_timer->start();
m_activeReply = m_downloadManager->deleteResource(request); m_activeReply = m_downloadManager->deleteResource(request);
m_activeReply->setProperty("protected", m_targetProtected); setCustomPropsToReply(m_activeReply);
m_activeReply->setProperty("username", m_targetUsername);
m_activeReply->setProperty("password", m_targetPassword);
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal); connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished); connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
} }
@ -241,9 +249,7 @@ void Downloader::runDeleteRequest(const QNetworkRequest& request) {
void Downloader::runPutRequest(const QNetworkRequest& request, const QByteArray& data) { void Downloader::runPutRequest(const QNetworkRequest& request, const QByteArray& data) {
m_timer->start(); m_timer->start();
m_activeReply = m_downloadManager->put(request, data); m_activeReply = m_downloadManager->put(request, data);
m_activeReply->setProperty("protected", m_targetProtected); setCustomPropsToReply(m_activeReply);
m_activeReply->setProperty("username", m_targetUsername);
m_activeReply->setProperty("password", m_targetPassword);
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal); connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished); connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
} }
@ -251,9 +257,7 @@ void Downloader::runPutRequest(const QNetworkRequest& request, const QByteArray&
void Downloader::runPostRequest(const QNetworkRequest& request, QHttpMultiPart* multipart_data) { void Downloader::runPostRequest(const QNetworkRequest& request, QHttpMultiPart* multipart_data) {
m_timer->start(); m_timer->start();
m_activeReply = m_downloadManager->post(request, multipart_data); m_activeReply = m_downloadManager->post(request, multipart_data);
m_activeReply->setProperty("protected", m_targetProtected); setCustomPropsToReply(m_activeReply);
m_activeReply->setProperty("username", m_targetUsername);
m_activeReply->setProperty("password", m_targetPassword);
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal); connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished); connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
} }
@ -261,9 +265,7 @@ void Downloader::runPostRequest(const QNetworkRequest& request, QHttpMultiPart*
void Downloader::runPostRequest(const QNetworkRequest& request, const QByteArray& data) { void Downloader::runPostRequest(const QNetworkRequest& request, const QByteArray& data) {
m_timer->start(); m_timer->start();
m_activeReply = m_downloadManager->post(request, data); m_activeReply = m_downloadManager->post(request, data);
m_activeReply->setProperty("protected", m_targetProtected); setCustomPropsToReply(m_activeReply);
m_activeReply->setProperty("username", m_targetUsername);
m_activeReply->setProperty("password", m_targetPassword);
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal); connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished); connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
} }
@ -271,10 +273,7 @@ void Downloader::runPostRequest(const QNetworkRequest& request, const QByteArray
void Downloader::runGetRequest(const QNetworkRequest& request) { void Downloader::runGetRequest(const QNetworkRequest& request) {
m_timer->start(); m_timer->start();
m_activeReply = m_downloadManager->get(request); m_activeReply = m_downloadManager->get(request);
m_activeReply->setProperty("protected", m_targetProtected); setCustomPropsToReply(m_activeReply);
m_activeReply->setProperty("username", m_targetUsername);
m_activeReply->setProperty("password", m_targetPassword);
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal); connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished); connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
} }

View File

@ -66,6 +66,7 @@ class Downloader : public QObject {
void progressInternal(qint64 bytes_received, qint64 bytes_total); void progressInternal(qint64 bytes_received, qint64 bytes_total);
private: private:
void setCustomPropsToReply(QNetworkReply* reply);
QList<HttpResponse> decodeMultipartAnswer(QNetworkReply* reply); QList<HttpResponse> decodeMultipartAnswer(QNetworkReply* reply);
void manipulateData(const QString& url, QNetworkAccessManager::Operation operation, void manipulateData(const QString& url, QNetworkAccessManager::Operation operation,
const QByteArray& data, QHttpMultiPart* multipart_data, const QByteArray& data, QHttpMultiPart* multipart_data,

View File

@ -440,7 +440,7 @@ DownloadManager::DownloadManager(QWidget* parent) : TabContent(parent), m_ui(new
DownloadManager::~DownloadManager() { DownloadManager::~DownloadManager() {
m_autoSaver->changeOccurred(); m_autoSaver->changeOccurred();
m_autoSaver->saveIfNeccessary(); m_autoSaver->saveIfNeccessary();
qDebug("Destroying DownloadManager instance."); qDebugNN << LOGSEC_NETWORK << "Destroying DownloadManager instance.";
} }
int DownloadManager::activeDownloads() const { int DownloadManager::activeDownloads() const {

View File

@ -112,11 +112,11 @@ void OAuth2Service::timerEvent(QTimerEvent* event) {
if (window_about_expire < QDateTime::currentDateTime()) { if (window_about_expire < QDateTime::currentDateTime()) {
// We try to refresh access token, because it probably expires soon. // We try to refresh access token, because it probably expires soon.
qDebug("Refreshing automatically access token."); qDebugNN << LOGSEC_OAUTH << "Refreshing automatically access token.";
refreshAccessToken(); refreshAccessToken();
} }
else { else {
qDebug("Access token is not expired yet."); qDebugNN << LOGSEC_OAUTH << "Access token is not expired yet.";
} }
} }
@ -145,6 +145,7 @@ void OAuth2Service::retrieveAccessToken(const QString& auth_code) {
auth_code, m_tokenGrantType, auth_code, m_tokenGrantType,
m_redirectionHandler->listenAddressPort()); m_redirectionHandler->listenAddressPort());
qDebugNN << LOGSEC_OAUTH << "Posting data for access token retrieval:" << QUOTE_W_SPACE_DOT(content);
m_networkManager.post(networkRequest, content.toUtf8()); m_networkManager.post(networkRequest, content.toUtf8());
} }
@ -167,6 +168,7 @@ void OAuth2Service::refreshAccessToken(QString refresh_token) {
tr("Refreshing login tokens for '%1'...").arg(m_tokenUrl.toString()), tr("Refreshing login tokens for '%1'...").arg(m_tokenUrl.toString()),
QSystemTrayIcon::MessageIcon::Information); QSystemTrayIcon::MessageIcon::Information);
qDebugNN << LOGSEC_OAUTH << "Posting data for access token refreshing:" << QUOTE_W_SPACE_DOT(content);
m_networkManager.post(networkRequest, content.toUtf8()); m_networkManager.post(networkRequest, content.toUtf8());
} }
@ -175,7 +177,7 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) {
QJsonDocument json_document = QJsonDocument::fromJson(repl); QJsonDocument json_document = QJsonDocument::fromJson(repl);
QJsonObject root_obj = json_document.object(); QJsonObject root_obj = json_document.object();
qDebug() << "Token response:" << json_document.toJson(); qDebugNN << LOGSEC_OAUTH << "Token response:" << QUOTE_W_SPACE_DOT(json_document.toJson());
if (network_reply->error() != QNetworkReply::NetworkError::NoError) { if (network_reply->error() != QNetworkReply::NetworkError::NoError) {
emit tokensRetrieveError(QString(), NetworkFactory::networkErrorText(network_reply->error())); emit tokensRetrieveError(QString(), NetworkFactory::networkErrorText(network_reply->error()));
@ -200,7 +202,9 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) {
setRefreshToken(refresh_token); setRefreshToken(refresh_token);
} }
qDebug() << "Obtained refresh token" << refreshToken() << "- expires on date/time" << tokensExpireIn(); qDebugNN << LOGSEC_OAUTH
<< "Obtained refresh token" << QUOTE_W_SPACE(refreshToken())
<< "- expires on date/time" << QUOTE_W_SPACE_DOT(tokensExpireIn());
emit tokensReceived(accessToken(), refreshToken(), expires); emit tokensReceived(accessToken(), refreshToken(), expires);
} }
@ -260,7 +264,8 @@ void OAuth2Service::setRefreshToken(const QString& refresh_token) {
bool OAuth2Service::login() { bool OAuth2Service::login() {
if (!m_redirectionHandler->isListening()) { if (!m_redirectionHandler->isListening()) {
qCritical("Cannot log-in because OAuth redirection handler is not listening."); qCriticalNN << LOGSEC_OAUTH
<< "Cannot log-in because OAuth redirection handler is not listening.";
return false; return false;
} }