diff --git a/connector/CMakeLists.txt b/connector/CMakeLists.txt index 75e2338..7e7851e 100644 --- a/connector/CMakeLists.txt +++ b/connector/CMakeLists.txt @@ -123,11 +123,11 @@ if(SYNCTHING_CONNECTION_LOG_SYNCTHING_EVENTS) endif() # configure whether POSTs should be logged -option(SYNCTHING_CONNECTION_LOG_POSTS "enables logging POSTs done by the SyncthingConnector (enable only for debugging!)" OFF) -if(SYNCTHING_CONNECTION_LOG_POSTS) +option(SYNCTHING_CONNECTION_LOG_API_CALLS "enables logging API calls done by the SyncthingConnector (enable only for debugging!)" OFF) +if(SYNCTHING_CONNECTION_LOG_API_CALLS) set_source_files_properties( syncthingconnection.cpp - PROPERTIES COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_LOG_POSTS + PROPERTIES COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_LOG_API_CALLS ) message(WARNING "SyncthingConnection class will log event data to stdout") endif() diff --git a/connector/syncthingconnection.cpp b/connector/syncthingconnection.cpp index 048237a..ea264e3 100644 --- a/connector/syncthingconnection.cpp +++ b/connector/syncthingconnection.cpp @@ -10,7 +10,7 @@ #include #include -#if defined(LIB_SYNCTHING_CONNECTOR_LOG_SYNCTHING_EVENTS) || defined(LIB_SYNCTHING_CONNECTOR_LOG_POSTS) +#if defined(LIB_SYNCTHING_CONNECTOR_LOG_SYNCTHING_EVENTS) || defined(LIB_SYNCTHING_CONNECTOR_LOG_API_CALLS) #include #endif @@ -32,7 +32,7 @@ using namespace std; using namespace ChronoUtilities; using namespace ConversionUtilities; -#if defined(LIB_SYNCTHING_CONNECTOR_LOG_SYNCTHING_EVENTS) || defined(LIB_SYNCTHING_CONNECTOR_LOG_POSTS) +#if defined(LIB_SYNCTHING_CONNECTOR_LOG_SYNCTHING_EVENTS) || defined(LIB_SYNCTHING_CONNECTOR_LOG_API_CALLS) using namespace EscapeCodes; #endif @@ -455,7 +455,10 @@ QNetworkRequest SyncthingConnection::prepareRequest(const QString &path, const Q QNetworkReply *SyncthingConnection::requestData(const QString &path, const QUrlQuery &query, bool rest) { #ifndef LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED - auto *reply = networkAccessManager().get(prepareRequest(path, query, rest)); + auto *const reply = networkAccessManager().get(prepareRequest(path, query, rest)); +#ifdef LIB_SYNCTHING_CONNECTOR_LOG_API_CALLS + cout << Phrases::Info << "GETing: " << reply->url().toString().toStdString() << Phrases::EndFlush; +#endif reply->ignoreSslErrors(m_expectedSslErrors); return reply; #else @@ -468,11 +471,11 @@ QNetworkReply *SyncthingConnection::requestData(const QString &path, const QUrlQ */ QNetworkReply *SyncthingConnection::postData(const QString &path, const QUrlQuery &query, const QByteArray &data) { - auto *reply = networkAccessManager().post(prepareRequest(path, query), data); - reply->ignoreSslErrors(m_expectedSslErrors); -#ifdef LIB_SYNCTHING_CONNECTOR_LOG_POSTS - cout << Phrases::Info << "POSTing:" << Phrases::End << data.data() << endl; + auto *const reply = networkAccessManager().post(prepareRequest(path, query), data); +#ifdef LIB_SYNCTHING_CONNECTOR_LOG_API_CALLS + cout << Phrases::Info << "POSTing: " << reply->url().toString().toStdString() << Phrases::End << data.data() << endl; #endif + reply->ignoreSslErrors(m_expectedSslErrors); return reply; } @@ -2520,6 +2523,7 @@ void SyncthingConnection::emitMyIdChanged(const QString &newId) void SyncthingConnection::handleFatalConnectionError() { setStatus(SyncthingStatus::Disconnected); + abortAllRequests(); if (m_autoReconnectTimer.interval()) { m_autoReconnectTimer.start(); } diff --git a/connector/tests/connectiontests.cpp b/connector/tests/connectiontests.cpp index 2b67b0a..a7461ea 100644 --- a/connector/tests/connectiontests.cpp +++ b/connector/tests/connectiontests.cpp @@ -350,14 +350,14 @@ void ConnectionTests::testErrorCases() cerr << "\n - Error handling in case of wrong credentials ..." << endl; waitForConnection(defaultConnect(), 5000, connectionSignal(&SyncthingConnection::error, errorHandler)); - while (!authErrorStatus || !authErrorConfig) { + while (!authErrorStatus && !authErrorConfig) { waitForSignals(noop, 5000, connectionSignal(&SyncthingConnection::error, errorHandler)); } cerr << "\n - Error handling in case of wrong API key ..." << endl; m_connection.setCredentials(QStringLiteral("nobody"), QStringLiteral("supersecret")); waitForConnection(defaultConnect(), 5000, connectionSignal(&SyncthingConnection::error, errorHandler)); - while (!apiKeyErrorStatus || !apiKeyErrorConfig) { + while (!apiKeyErrorStatus && !apiKeyErrorConfig) { waitForSignals(noop, 5000, connectionSignal(&SyncthingConnection::error, errorHandler)); } } @@ -636,7 +636,7 @@ void ConnectionTests::testRequestingRescan() CPPUNIT_ASSERT_EQUAL(QStringLiteral("test2"), dir); rescanTriggered = true; }; - waitForSignals(bind(&SyncthingConnection::rescanAllDirs, &m_connection), 5000, + waitForSignalsOrFail(bind(&SyncthingConnection::rescanAllDirs, &m_connection), 5000, connectionSignal(&SyncthingConnection::error), connectionSignal(&SyncthingConnection::rescanTriggered, rescanTriggeredHandler, &rescanTriggered)); bool errorOccured = false;