Move the proxyfiles to libsync where they make more sense
authorRoeland Jago Douma <roeland@famdouma.nl>
Sat, 21 Mar 2020 10:25:34 +0000 (11:25 +0100)
committerMichael Schuster <michael@schuster.ms>
Thu, 18 Jun 2020 16:38:06 +0000 (18:38 +0200)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/CMakeLists.txt
src/gui/clientproxy.cpp [deleted file]
src/gui/clientproxy.h [deleted file]
src/libsync/CMakeLists.txt
src/libsync/clientproxy.cpp [new file with mode: 0644]
src/libsync/clientproxy.h [new file with mode: 0644]
test/CMakeLists.txt

index cb8738581ea4dbe2b3ae0ff1ba03dd33ecaf52b2..b83106441d308311e97d797c4a6badd258bebcc5 100644 (file)
@@ -54,7 +54,6 @@ set(client_SRCS
     accountmanager.cpp
     accountsettings.cpp
     application.cpp
-    clientproxy.cpp
     connectionvalidator.cpp
     folder.cpp
     folderman.cpp
diff --git a/src/gui/clientproxy.cpp b/src/gui/clientproxy.cpp
deleted file mode 100644 (file)
index d9f851d..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#include "clientproxy.h"
-
-#include "configfile.h"
-#include <QLoggingCategory>
-#include <QUrl>
-#include <QThreadPool>
-
-namespace OCC {
-
-Q_LOGGING_CATEGORY(lcClientProxy, "nextcloud.sync.clientproxy", QtInfoMsg)
-
-ClientProxy::ClientProxy(QObject *parent)
-    : QObject(parent)
-{
-}
-
-static QNetworkProxy proxyFromConfig(const ConfigFile &cfg)
-{
-    QNetworkProxy proxy;
-
-    if (cfg.proxyHostName().isEmpty())
-        return QNetworkProxy();
-
-    proxy.setHostName(cfg.proxyHostName());
-    proxy.setPort(cfg.proxyPort());
-    if (cfg.proxyNeedsAuth()) {
-        proxy.setUser(cfg.proxyUser());
-        proxy.setPassword(cfg.proxyPassword());
-    }
-    return proxy;
-}
-
-bool ClientProxy::isUsingSystemDefault()
-{
-    OCC::ConfigFile cfg;
-
-    // if there is no config file, default to system proxy.
-    if (cfg.exists()) {
-        return cfg.proxyType() == QNetworkProxy::DefaultProxy;
-    }
-
-    return true;
-}
-
-QString printQNetworkProxy(const QNetworkProxy &proxy)
-{
-    return QString("%1://%2:%3").arg(proxy.type()).arg(proxy.hostName()).arg(proxy.port());
-}
-
-void ClientProxy::setupQtProxyFromConfig()
-{
-    OCC::ConfigFile cfg;
-    int proxyType = QNetworkProxy::DefaultProxy;
-    QNetworkProxy proxy;
-
-    // if there is no config file, default to system proxy.
-    if (cfg.exists()) {
-        proxyType = cfg.proxyType();
-        proxy = proxyFromConfig(cfg);
-    }
-
-    switch (proxyType) {
-        case QNetworkProxy::NoProxy:
-            qCInfo(lcClientProxy) << "Set proxy configuration to use NO proxy";
-            QNetworkProxyFactory::setUseSystemConfiguration(false);
-            QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
-            break;
-        case QNetworkProxy::DefaultProxy:
-            qCInfo(lcClientProxy) << "Set proxy configuration to use the preferred system proxy for http tcp connections";
-            {
-                QNetworkProxyQuery query;
-                query.setProtocolTag("http");
-                query.setQueryType(QNetworkProxyQuery::TcpSocket);
-                auto proxies = QNetworkProxyFactory::proxyForQuery(query);
-                proxy = proxies.first();
-            }
-            QNetworkProxyFactory::setUseSystemConfiguration(false);
-            QNetworkProxy::setApplicationProxy(proxy);
-            break;
-        case QNetworkProxy::Socks5Proxy:
-            proxy.setType(QNetworkProxy::Socks5Proxy);
-            qCInfo(lcClientProxy) << "Set proxy configuration to SOCKS5" << printQNetworkProxy(proxy);
-            QNetworkProxyFactory::setUseSystemConfiguration(false);
-            QNetworkProxy::setApplicationProxy(proxy);
-            break;
-        case QNetworkProxy::HttpProxy:
-            proxy.setType(QNetworkProxy::HttpProxy);
-            qCInfo(lcClientProxy) << "Set proxy configuration to HTTP" << printQNetworkProxy(proxy);
-            QNetworkProxyFactory::setUseSystemConfiguration(false);
-            QNetworkProxy::setApplicationProxy(proxy);
-            break;
-        default:
-            break;
-    }
-}
-
-const char *ClientProxy::proxyTypeToCStr(QNetworkProxy::ProxyType type)
-{
-    switch (type) {
-    case QNetworkProxy::NoProxy:
-        return "NoProxy";
-    case QNetworkProxy::DefaultProxy:
-        return "DefaultProxy";
-    case QNetworkProxy::Socks5Proxy:
-        return "Socks5Proxy";
-    case QNetworkProxy::HttpProxy:
-        return "HttpProxy";
-    case QNetworkProxy::HttpCachingProxy:
-        return "HttpCachingProxy";
-    case QNetworkProxy::FtpCachingProxy:
-        return "FtpCachingProxy";
-    default:
-        return "NoProxy";
-    }
-}
-
-void ClientProxy::lookupSystemProxyAsync(const QUrl &url, QObject *dst, const char *slot)
-{
-    auto *runnable = new SystemProxyRunnable(url);
-    QObject::connect(runnable, SIGNAL(systemProxyLookedUp(QNetworkProxy)), dst, slot);
-    QThreadPool::globalInstance()->start(runnable); // takes ownership and deletes
-}
-
-SystemProxyRunnable::SystemProxyRunnable(const QUrl &url)
-    : QObject()
-    , QRunnable()
-    , _url(url)
-{
-}
-
-void SystemProxyRunnable::run()
-{
-    qRegisterMetaType<QNetworkProxy>("QNetworkProxy");
-    QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(QNetworkProxyQuery(_url));
-
-    if (proxies.isEmpty()) {
-        emit systemProxyLookedUp(QNetworkProxy(QNetworkProxy::NoProxy));
-    } else {
-        emit systemProxyLookedUp(proxies.first());
-        // FIXME Would we really ever return more?
-    }
-}
-}
diff --git a/src/gui/clientproxy.h b/src/gui/clientproxy.h
deleted file mode 100644 (file)
index 348eab9..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-#ifndef CLIENTPROXY_H
-#define CLIENTPROXY_H
-
-#include <QObject>
-#include <QNetworkProxy>
-#include <QRunnable>
-#include <QUrl>
-
-#include <csync.h>
-#include "common/utility.h"
-#include "owncloudlib.h"
-
-namespace OCC {
-
-class ConfigFile;
-
-/**
- * @brief The ClientProxy class
- * @ingroup libsync
- */
-class ClientProxy : public QObject
-{
-    Q_OBJECT
-public:
-    explicit ClientProxy(QObject *parent = nullptr);
-
-    static bool isUsingSystemDefault();
-    static void lookupSystemProxyAsync(const QUrl &url, QObject *dst, const char *slot);
-
-public slots:
-    void setupQtProxyFromConfig();
-
-private:
-    const char *proxyTypeToCStr(QNetworkProxy::ProxyType type);
-};
-
-class SystemProxyRunnable : public QObject, public QRunnable
-{
-    Q_OBJECT
-public:
-    SystemProxyRunnable(const QUrl &url);
-    void run() override;
-signals:
-    void systemProxyLookedUp(const QNetworkProxy &url);
-
-private:
-    QUrl _url;
-};
-
-QString printQNetworkProxy(const QNetworkProxy &proxy);
-}
-
-#endif // CLIENTPROXY_H
index 663bc1ac86bcb9e2052eac8a7d2717d19c031697..ac3e99bd4eb172ccc8b4827088a2f791cb4d7b43 100644 (file)
@@ -24,6 +24,7 @@ set(libsync_SRCS
     wordlist.cpp
     bandwidthmanager.cpp
     capabilities.cpp
+    clientproxy.cpp
     cookiejar.cpp
     discoveryphase.cpp
     filesystem.cpp
diff --git a/src/libsync/clientproxy.cpp b/src/libsync/clientproxy.cpp
new file mode 100644 (file)
index 0000000..8d078f2
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "clientproxy.h"
+
+#include "configfile.h"
+#include <QLoggingCategory>
+#include <QUrl>
+#include <QThreadPool>
+
+namespace OCC {
+
+Q_LOGGING_CATEGORY(lcClientProxy, "nextcloud.sync.clientproxy", QtInfoMsg)
+
+ClientProxy::ClientProxy(QObject *parent)
+    : QObject(parent)
+{
+}
+
+static QNetworkProxy proxyFromConfig(const ConfigFile &cfg)
+{
+    QNetworkProxy proxy;
+
+    if (cfg.proxyHostName().isEmpty())
+        return QNetworkProxy();
+
+    proxy.setHostName(cfg.proxyHostName());
+    proxy.setPort(cfg.proxyPort());
+    if (cfg.proxyNeedsAuth()) {
+        proxy.setUser(cfg.proxyUser());
+        proxy.setPassword(cfg.proxyPassword());
+    }
+    return proxy;
+}
+
+bool ClientProxy::isUsingSystemDefault()
+{
+    OCC::ConfigFile cfg;
+
+    // if there is no config file, default to system proxy.
+    if (cfg.exists()) {
+        return cfg.proxyType() == QNetworkProxy::DefaultProxy;
+    }
+
+    return true;
+}
+
+QString printQNetworkProxy(const QNetworkProxy &proxy)
+{
+    return QString("%1://%2:%3").arg(proxy.type()).arg(proxy.hostName()).arg(proxy.port());
+}
+
+void ClientProxy::setupQtProxyFromConfig()
+{
+    OCC::ConfigFile cfg;
+    int proxyType = QNetworkProxy::DefaultProxy;
+    QNetworkProxy proxy;
+
+    // if there is no config file, default to system proxy.
+    if (cfg.exists()) {
+        proxyType = cfg.proxyType();
+        proxy = proxyFromConfig(cfg);
+    }
+
+    switch (proxyType) {
+        case QNetworkProxy::NoProxy:
+            qCInfo(lcClientProxy) << "Set proxy configuration to use NO proxy";
+            QNetworkProxyFactory::setUseSystemConfiguration(false);
+            QNetworkProxy::setApplicationProxy(QNetworkProxy::NoProxy);
+            break;
+        case QNetworkProxy::DefaultProxy:
+            qCInfo(lcClientProxy) << "Set proxy configuration to use the preferred system proxy for http tcp connections";
+            {
+                QNetworkProxyQuery query;
+                query.setProtocolTag("http");
+                query.setQueryType(QNetworkProxyQuery::TcpSocket);
+                auto proxies = QNetworkProxyFactory::proxyForQuery(query);
+                proxy = proxies.first();
+            }
+            QNetworkProxyFactory::setUseSystemConfiguration(false);
+            QNetworkProxy::setApplicationProxy(proxy);
+            break;
+        case QNetworkProxy::Socks5Proxy:
+            proxy.setType(QNetworkProxy::Socks5Proxy);
+            qCInfo(lcClientProxy) << "Set proxy configuration to SOCKS5" << printQNetworkProxy(proxy);
+            QNetworkProxyFactory::setUseSystemConfiguration(false);
+            QNetworkProxy::setApplicationProxy(proxy);
+            break;
+        case QNetworkProxy::HttpProxy:
+            proxy.setType(QNetworkProxy::HttpProxy);
+            qCInfo(lcClientProxy) << "Set proxy configuration to HTTP" << printQNetworkProxy(proxy);
+            QNetworkProxyFactory::setUseSystemConfiguration(false);
+            QNetworkProxy::setApplicationProxy(proxy);
+            break;
+        default:
+            break;
+    }
+}
+
+void ClientProxy::lookupSystemProxyAsync(const QUrl &url, QObject *dst, const char *slot)
+{
+    auto *runnable = new SystemProxyRunnable(url);
+    QObject::connect(runnable, SIGNAL(systemProxyLookedUp(QNetworkProxy)), dst, slot);
+    QThreadPool::globalInstance()->start(runnable); // takes ownership and deletes
+}
+
+SystemProxyRunnable::SystemProxyRunnable(const QUrl &url)
+    : QObject()
+    , QRunnable()
+    , _url(url)
+{
+}
+
+void SystemProxyRunnable::run()
+{
+    qRegisterMetaType<QNetworkProxy>("QNetworkProxy");
+    QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(QNetworkProxyQuery(_url));
+
+    if (proxies.isEmpty()) {
+        emit systemProxyLookedUp(QNetworkProxy(QNetworkProxy::NoProxy));
+    } else {
+        emit systemProxyLookedUp(proxies.first());
+        // FIXME Would we really ever return more?
+    }
+}
+}
diff --git a/src/libsync/clientproxy.h b/src/libsync/clientproxy.h
new file mode 100644 (file)
index 0000000..0363ae4
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef CLIENTPROXY_H
+#define CLIENTPROXY_H
+
+#include <QObject>
+#include <QNetworkProxy>
+#include <QRunnable>
+#include <QUrl>
+
+#include <csync.h>
+#include "common/utility.h"
+#include "owncloudlib.h"
+
+namespace OCC {
+
+class ConfigFile;
+
+/**
+ * @brief The ClientProxy class
+ * @ingroup libsync
+ */
+class OWNCLOUDSYNC_EXPORT ClientProxy : public QObject
+{
+    Q_OBJECT
+public:
+    explicit ClientProxy(QObject *parent = nullptr);
+
+    static bool isUsingSystemDefault();
+    static void lookupSystemProxyAsync(const QUrl &url, QObject *dst, const char *slot);
+
+public slots:
+    void setupQtProxyFromConfig();
+};
+
+class OWNCLOUDSYNC_EXPORT SystemProxyRunnable : public QObject, public QRunnable
+{
+    Q_OBJECT
+public:
+    SystemProxyRunnable(const QUrl &url);
+    void run() override;
+signals:
+    void systemProxyLookedUp(const QNetworkProxy &url);
+
+private:
+    QUrl _url;
+};
+
+QString printQNetworkProxy(const QNetworkProxy &proxy);
+}
+
+#endif // CLIENTPROXY_H
index a39da386dc433a5c65af90e014de5f1aec69123b..8a7a790495b3a0028edac1db72c843ef0f89ffee 100644 (file)
@@ -69,7 +69,6 @@ list(APPEND FolderMan_SRC ../src/gui/guiutility.cpp )
 list(APPEND FolderMan_SRC ../src/gui/navigationpanehelper.cpp )
 list(APPEND FolderMan_SRC ../src/gui/userinfo.cpp )
 list(APPEND FolderMan_SRC ../src/gui/connectionvalidator.cpp )
-list(APPEND FolderMan_SRC ../src/gui/clientproxy.cpp )
 list(APPEND FolderMan_SRC ../src/gui/ocsjob.cpp )
 list(APPEND FolderMan_SRC ../src/gui/ocsnavigationappsjob.cpp )
 list(APPEND FolderMan_SRC ../src/gui/accountstate.cpp )
@@ -79,7 +78,6 @@ list(APPEND FolderMan_SRC stubfolderman.cpp )
 nextcloud_add_test(FolderMan "${FolderMan_SRC}")
 
 SET(RemoteWipe_SRC ../src/gui/remotewipe.cpp)
-list(APPEND RemoteWipe_SRC ../src/gui/clientproxy.cpp )
 list(APPEND RemoteWipe_SRC ../src/gui/guiutility.cpp )
 list(APPEND RemoteWipe_SRC ../src/gui/userinfo.cpp )
 list(APPEND RemoteWipe_SRC ../src/gui/connectionvalidator.cpp )