Fix memory leak on app exit. Work on oauth handler.

This commit is contained in:
Martin Rotter 2020-07-24 08:12:44 +02:00
parent 47528a48e9
commit 0d77d5481f
7 changed files with 28 additions and 30 deletions

View File

@ -285,7 +285,7 @@ void OAuth2Service::logout() {
void OAuth2Service::startRefreshTimer() {
if (!refreshToken().isEmpty()) {
m_timerId = startTimer(1000 * 60 * 15, Qt::VeryCoarseTimer);
m_timerId = startTimer(1000 * 60 * 15, Qt::TimerType::VeryCoarseTimer);
}
}

View File

@ -19,23 +19,44 @@ OAuthHttpHandler::OAuthHttpHandler(QObject* parent) : QObject(parent) {
OAuthHttpHandler::~OAuthHttpHandler() {
if (m_httpServer.isListening()) {
qWarning("Redirection OAuth handler is listening. Stopping it now.");
m_httpServer.close();
}
}
void OAuthHttpHandler::setListenAddressPort(const QString& full_uri) {
QUrl url = QUrl::fromUserInput(full_uri);
QHostAddress listen_address;
m_listenAddress = QHostAddress(url.host());
if (url.host() == QL1S("localhost")) {
listen_address = QHostAddress(QHostAddress::SpecialAddress::LocalHost);
}
else {
listen_address = QHostAddress(url.host());
}
if (listen_address == m_listenAddress || m_listenPort == url.port()) {
return;
}
m_listenAddress = listen_address;
m_listenPort = quint16(url.port());
m_listenAddressPort = full_uri;
if (m_httpServer.isListening()) {
qWarning("Redirection OAuth handler is listening. Stopping it now.");
m_httpServer.close();
}
if (!m_httpServer.listen(m_listenAddress, m_listenPort)) {
qCritical("OAuth HTTP handler: Failed to start listening on port '%d'.", OAUTH_REDIRECT_URI_PORT);
qCritical("OAuth redirect handler FAILED TO START TO LISTEN on address '%s' and port '%u'.",
qPrintable(m_listenAddress.toString()),
m_listenPort);
}
else {
qDebug("OAuth redirect handler is listening on address '%s' and port '%u'.",
qPrintable(m_listenAddress.toString()),
m_listenPort);
}
}

View File

@ -101,27 +101,6 @@ QString WebFactory::deEscapeHtml(const QString& text) {
return output;
}
QString WebFactory::toSecondLevelDomain(const QUrl& url) {
const QString top_level_domain = url.topLevelDomain();
const QString url_host = url.host();
if (top_level_domain.isEmpty() || url_host.isEmpty()) {
return QString();
}
QString domain = url_host.left(url_host.size() - top_level_domain.size());
if (domain.count(QL1C('.')) == 0) {
return url_host;
}
while (domain.count(QL1C('.')) != 0) {
domain = domain.mid(domain.indexOf(QL1C('.')) + 1);
}
return domain + top_level_domain;
}
void WebFactory::updateProxy() {
const QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(qApp->settings()->value(GROUP(Proxy),
SETTING(Proxy::Type)).

View File

@ -31,8 +31,6 @@ class WebFactory : public QObject {
QString escapeHtml(const QString& html);
QString deEscapeHtml(const QString& text);
QString toSecondLevelDomain(const QUrl& url);
#if defined (USE_WEBENGINE)
QAction* engineSettingsAction();
#endif
@ -43,7 +41,6 @@ class WebFactory : public QObject {
bool sendMessageViaEmail(const Message& message);
#if defined (USE_WEBENGINE)
private slots:
void createMenu(QMenu* menu = nullptr);
void webEngineSettingChanged(bool enabled);

View File

@ -28,7 +28,7 @@
GmailNetworkFactory::GmailNetworkFactory(QObject* parent) : QObject(parent),
m_service(nullptr), m_username(QString()), m_batchSize(GMAIL_DEFAULT_BATCH_SIZE),
m_oauth2(new OAuth2Service(GMAIL_OAUTH_AUTH_URL, GMAIL_OAUTH_TOKEN_URL,
QString(), QString(), GMAIL_OAUTH_SCOPE)) {
QString(), QString(), GMAIL_OAUTH_SCOPE, this)) {
initializeOauth();
}

View File

@ -13,7 +13,8 @@
#include "services/inoreader/inoreaderfeed.h"
#include "services/inoreader/network/inoreadernetworkfactory.h"
InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent) : ServiceRoot(parent), m_network(network) {
InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, RootItem* parent)
: ServiceRoot(parent), m_network(network) {
if (network == nullptr) {
m_network = new InoreaderNetworkFactory(this);
}

View File

@ -25,7 +25,7 @@
InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent),
m_service(nullptr), m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE),
m_oauth2(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL,
INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE)) {
INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE, this)) {
initializeOauth();
}