This commit is contained in:
Martin Rotter 2020-08-14 15:02:48 +02:00
parent 04559c5b09
commit 580c067b02
3 changed files with 41 additions and 26 deletions

View File

@ -17,7 +17,7 @@ OAuthHttpHandler::OAuthHttpHandler(const QString& success_text, QObject* parent)
OAuthHttpHandler::~OAuthHttpHandler() { OAuthHttpHandler::~OAuthHttpHandler() {
if (m_httpServer.isListening()) { if (m_httpServer.isListening()) {
qWarning("Redirection OAuth handler is listening. Stopping it now."); qWarningNN << LOGSEC_OAUTH << "Redirection OAuth handler is listening. Stopping it now.";
m_httpServer.close(); m_httpServer.close();
} }
} }
@ -47,19 +47,23 @@ void OAuthHttpHandler::setListenAddressPort(const QString& full_uri) {
m_listenAddressPort = full_uri; m_listenAddressPort = full_uri;
if (m_httpServer.isListening()) { if (m_httpServer.isListening()) {
qWarning("Redirection OAuth handler is listening. Stopping it now."); qWarningNN << LOGSEC_OAUTH << "Redirection OAuth handler is listening. Stopping it now.";
m_httpServer.close(); m_httpServer.close();
} }
if (!m_httpServer.listen(m_listenAddress, m_listenPort)) { if (!m_httpServer.listen(m_listenAddress, m_listenPort)) {
qCritical("OAuth redirect handler FAILED TO START TO LISTEN on address '%s' and port '%u'.", qCriticalNN << LOGSEC_OAUTH
qPrintable(m_listenAddress.toString()), << "OAuth redirect handler FAILED TO START TO LISTEN on address"
m_listenPort); << QUOTE_W_SPACE(m_listenAddress.toString())
<< "and port"
<< QUOTE_W_SPACE_DOT(m_listenPort);
} }
else { else {
qDebug("OAuth redirect handler is listening on address '%s' and port '%u'.", qDebugNN << LOGSEC_OAUTH
qPrintable(m_listenAddress.toString()), << "OAuth redirect handler IS LISTENING on address"
m_listenPort); << QUOTE_W_SPACE(m_listenAddress.toString())
<< "and port"
<< QUOTE_W_SPACE_DOT(m_listenPort);
} }
} }
@ -85,15 +89,18 @@ void OAuthHttpHandler::handleRedirection(const QVariantMap& data) {
const QString uri = data.value(QSL("error_uri")).toString(); const QString uri = data.value(QSL("error_uri")).toString();
const QString description = data.value(QSL("error_description")).toString(); const QString description = data.value(QSL("error_description")).toString();
qWarning("OAuth HTTP handler: AuthenticationError: %s(%s): %s", qPrintable(error), qPrintable(uri), qPrintable(description)); qCriticalNN << LOGSEC_OAUTH
<< "AuthenticationError: " << error << "(" << uri << "): " << description;
emit authRejected(description, received_state); emit authRejected(description, received_state);
} }
else if (code.isEmpty()) { else if (code.isEmpty()) {
qWarning("OAuth HTTP handler: AuthenticationError: Code not received"); qCriticalNN << LOGSEC_OAUTH
emit authRejected(QSL("AuthenticationError: Code not received"), received_state); << "We did not receive authentication code.";
emit authRejected(QSL("Code not received"), received_state);
} }
else if (received_state.isEmpty()) { else if (received_state.isEmpty()) {
qWarning("OAuth HTTP handler: State not received"); qCriticalNN << LOGSEC_OAUTH
<< "State not received.";
emit authRejected(QSL("State not received"), received_state); emit authRejected(QSL("State not received"), received_state);
} }
else { else {
@ -103,7 +110,7 @@ void OAuthHttpHandler::handleRedirection(const QVariantMap& data) {
void OAuthHttpHandler::answerClient(QTcpSocket* socket, const QUrl& url) { void OAuthHttpHandler::answerClient(QTcpSocket* socket, const QUrl& url) {
if (!url.path().remove(QL1C('/')).isEmpty()) { if (!url.path().remove(QL1C('/')).isEmpty()) {
qWarning("OAuth HTTP handler: Invalid request: %s", qPrintable(url.toString())); qCriticalNN << LOGSEC_OAUTH << "Invalid request:" << QUOTE_W_SPACE_DOT(url.toString());
} }
else { else {
QVariantMap received_data; QVariantMap received_data;
@ -145,25 +152,25 @@ void OAuthHttpHandler::readReceivedData(QTcpSocket* socket) {
if (Q_LIKELY(request->m_state == QHttpRequest::State::ReadingMethod)) { if (Q_LIKELY(request->m_state == QHttpRequest::State::ReadingMethod)) {
if (Q_UNLIKELY(error = !request->readMethod(socket))) { if (Q_UNLIKELY(error = !request->readMethod(socket))) {
qWarning("OAuth HTTP handler: Invalid dethod"); qWarningNN << LOGSEC_OAUTH << "Invalid method.";
} }
} }
if (Q_LIKELY(!error && request->m_state == QHttpRequest::State::ReadingUrl)) { if (Q_LIKELY(!error && request->m_state == QHttpRequest::State::ReadingUrl)) {
if (Q_UNLIKELY(error = !request->readUrl(socket))) { if (Q_UNLIKELY(error = !request->readUrl(socket))) {
qWarning("OAuth HTTP handler: Invalid URL"); qWarningNN << LOGSEC_OAUTH << "Invalid URL.";
} }
} }
if (Q_LIKELY(!error && request->m_state == QHttpRequest::State::ReadingStatus)) { if (Q_LIKELY(!error && request->m_state == QHttpRequest::State::ReadingStatus)) {
if (Q_UNLIKELY(error = !request->readStatus(socket))) { if (Q_UNLIKELY(error = !request->readStatus(socket))) {
qWarning("OAuth HTTP handler: Invalid status"); qWarningNN << LOGSEC_OAUTH << "Invalid status.";
} }
} }
if (Q_LIKELY(!error && request->m_state == QHttpRequest::State::ReadingHeader)) { if (Q_LIKELY(!error && request->m_state == QHttpRequest::State::ReadingHeader)) {
if (Q_UNLIKELY(error = !request->readHeader(socket))) { if (Q_UNLIKELY(error = !request->readHeader(socket))) {
qWarning("OAuth HTTP handler: Invalid header"); qWarningNN << LOGSEC_OAUTH << "Invalid header.";
} }
} }
@ -222,7 +229,7 @@ bool OAuthHttpHandler::QHttpRequest::readMethod(QTcpSocket* socket) {
m_method = Method::Delete; m_method = Method::Delete;
} }
else { else {
qWarning("OAuth HTTP handler: Invalid operation %s", m_fragment.data()); qWarningNN << LOGSEC_OAUTH << "Invalid operation:" << QUOTE_W_SPACE_DOT(m_fragment.data());
} }
m_state = State::ReadingUrl; m_state = State::ReadingUrl;
@ -250,7 +257,7 @@ bool OAuthHttpHandler::QHttpRequest::readUrl(QTcpSocket* socket) {
if (finished) { if (finished) {
if (!m_fragment.startsWith("/")) { if (!m_fragment.startsWith("/")) {
qWarning("OAuth HTTP handler: Invalid URL path %s", m_fragment.constData()); qWarningNN << LOGSEC_OAUTH << "Invalid URL path" << QUOTE_W_SPACE_DOT(m_fragment);
return false; return false;
} }
@ -258,7 +265,7 @@ bool OAuthHttpHandler::QHttpRequest::readUrl(QTcpSocket* socket) {
m_state = State::ReadingStatus; m_state = State::ReadingStatus;
if (!m_url.isValid()) { if (!m_url.isValid()) {
qWarning("OAuth HTTP handler: Invalid URL %s", m_fragment.constData()); qWarningNN << LOGSEC_OAUTH << "Invalid URL" << QUOTE_W_SPACE_DOT(m_fragment);
return false; return false;
} }
@ -283,7 +290,7 @@ bool OAuthHttpHandler::QHttpRequest::readStatus(QTcpSocket* socket) {
if (finished) { if (finished) {
if ((std::isdigit(m_fragment.at(m_fragment.size() - 3)) == 0) || (std::isdigit(m_fragment.at(m_fragment.size() - 1)) == 0)) { if ((std::isdigit(m_fragment.at(m_fragment.size() - 3)) == 0) || (std::isdigit(m_fragment.at(m_fragment.size() - 1)) == 0)) {
qWarning("OAuth HTTP handler: Invalid version"); qWarningNN << LOGSEC_OAUTH << "Invalid version";
return false; return false;
} }

View File

@ -14,7 +14,7 @@ SilentNetworkAccessManager::SilentNetworkAccessManager(QObject* parent)
} }
SilentNetworkAccessManager::~SilentNetworkAccessManager() { SilentNetworkAccessManager::~SilentNetworkAccessManager() {
qDebug("Destroying SilentNetworkAccessManager instance."); qDebugNN << LOGSEC_NETWORK << "Destroying SilentNetworkAccessManager instance.";
} }
void SilentNetworkAccessManager::onAuthenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator) { void SilentNetworkAccessManager::onAuthenticationRequired(QNetworkReply* reply, QAuthenticator* authenticator) {
@ -23,12 +23,18 @@ void SilentNetworkAccessManager::onAuthenticationRequired(QNetworkReply* reply,
authenticator->setUser(reply->property("username").toString()); authenticator->setUser(reply->property("username").toString());
authenticator->setPassword(reply->property("password").toString()); authenticator->setPassword(reply->property("password").toString());
reply->setProperty("authentication-given", true); reply->setProperty("authentication-given", true);
qDebug("Item '%s' requested authentication and got it.", qPrintable(reply->url().toString())); qDebugNN << LOGSEC_NETWORK
<< "URL"
<< QUOTE_W_SPACE(reply->url().toString())
<< "requested authentication and got it.";
} }
else { else {
reply->setProperty("authentication-given", false); reply->setProperty("authentication-given", false);
// Authentication is required but this feed does not contain it. // Authentication is required but this feed does not contain it.
qWarning("Item '%s' requested authentication but username/password is not available.", qPrintable(reply->url().toString())); qWarningNN << LOGSEC_NETWORK
<< "Item"
<< QUOTE_W_SPACE(reply->url().toString())
<< "requested authentication but username/password is not available.";
} }
} }

View File

@ -50,12 +50,12 @@ bool WebFactory::openUrlInExternalBrowser(const QString& url) const {
const QString arguments = qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserArguments)).toString(); const QString arguments = qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalBrowserArguments)).toString();
auto nice_args = arguments.arg(url); auto nice_args = arguments.arg(url);
qDebug("Arguments for external browser: '%s'.", qPrintable(nice_args)); qDebugNN << LOGSEC_NETWORK << "Arguments for external browser:" << QUOTE_W_SPACE_DOT(nice_args);
const bool result = IOFactory::startProcessDetached(browser, {}, nice_args); const bool result = IOFactory::startProcessDetached(browser, {}, nice_args);
if (!result) { if (!result) {
qDebug("External web browser call failed."); qDebugNN << LOGSEC_NETWORK << "External web browser call failed.";
} }
return result; return result;
@ -167,6 +167,7 @@ void WebFactory::createMenu(QMenu* menu) {
actions << createEngineSettingsAction(tr("Error pages enabled"), QWebEngineSettings::ErrorPageEnabled); actions << createEngineSettingsAction(tr("Error pages enabled"), QWebEngineSettings::ErrorPageEnabled);
actions << createEngineSettingsAction(tr("Plugins enabled"), QWebEngineSettings::PluginsEnabled); actions << createEngineSettingsAction(tr("Plugins enabled"), QWebEngineSettings::PluginsEnabled);
actions << createEngineSettingsAction(tr("Fullscreen enabled"), QWebEngineSettings::FullScreenSupportEnabled); actions << createEngineSettingsAction(tr("Fullscreen enabled"), QWebEngineSettings::FullScreenSupportEnabled);
#if !defined(Q_OS_LINUX) #if !defined(Q_OS_LINUX)
actions << createEngineSettingsAction(tr("Screen capture enabled"), QWebEngineSettings::ScreenCaptureEnabled); actions << createEngineSettingsAction(tr("Screen capture enabled"), QWebEngineSettings::ScreenCaptureEnabled);
actions << createEngineSettingsAction(tr("WebGL enabled"), QWebEngineSettings::WebGLEnabled); actions << createEngineSettingsAction(tr("WebGL enabled"), QWebEngineSettings::WebGLEnabled);
@ -175,6 +176,7 @@ void WebFactory::createMenu(QMenu* menu) {
actions << createEngineSettingsAction(tr("Allow running insecure content"), QWebEngineSettings::AllowRunningInsecureContent); actions << createEngineSettingsAction(tr("Allow running insecure content"), QWebEngineSettings::AllowRunningInsecureContent);
actions << createEngineSettingsAction(tr("Allow geolocation on insecure origins"), QWebEngineSettings::AllowGeolocationOnInsecureOrigins); actions << createEngineSettingsAction(tr("Allow geolocation on insecure origins"), QWebEngineSettings::AllowGeolocationOnInsecureOrigins);
#endif #endif
menu->addActions(actions); menu->addActions(actions);
} }