diff --git a/src/gui/src/ActivationDialog.cpp b/src/gui/src/ActivationDialog.cpp index eb6593b5..88948958 100644 --- a/src/gui/src/ActivationDialog.cpp +++ b/src/gui/src/ActivationDialog.cpp @@ -2,7 +2,6 @@ #include "ui_ActivationDialog.h" #include "CancelActivationDialog.h" #include "AppConfig.h" -#include "WebClient.h" #include #include "ActivationNotifier.h" #include "MainWindow.h" diff --git a/src/gui/src/ActivationNotifier.cpp b/src/gui/src/ActivationNotifier.cpp index cfe99810..d63c8505 100644 --- a/src/gui/src/ActivationNotifier.cpp +++ b/src/gui/src/ActivationNotifier.cpp @@ -40,21 +40,10 @@ void ActivationNotifier::setUpdateInfo(QString const& fromVersion, void ActivationNotifier::notify() { - CoreInterface coreInterface; - try { - coreInterface.notifyActivation(m_Identity); - } - catch (...) { - // catch all exceptions and fails silently - } + // TODO: use something other than CURL } void ActivationNotifier::notifyUpdate() { - try { - CoreInterface coreInterface; - coreInterface.notifyUpdate(m_fromVersion, m_toVersion, - m_serialKey); - } catch (...) { - } + // TODO: use something other than CURL } diff --git a/src/gui/src/CoreInterface.cpp b/src/gui/src/CoreInterface.cpp index ef3dc326..38f09f07 100644 --- a/src/gui/src/CoreInterface.cpp +++ b/src/gui/src/CoreInterface.cpp @@ -62,29 +62,6 @@ QString CoreInterface::getSerialKeyFilePath() return filename; } -QString CoreInterface::notifyUpdate (QString const& fromVersion, - QString const& toVersion, - QString const& serialKey) { - QStringList args("--notify-update"); - QString input(fromVersion + ":" + toVersion + ":" + serialKey); - input.append("\n"); - return run(args, input); -} - -QString CoreInterface::notifyActivation(const QString& identity) -{ - QStringList args("--notify-activation"); - - QString input(identity + ":" + hash(getFirstMacAddress())); - QString os= getOSInformation(); - if (!os.isEmpty()) { - input.append(":").append(os); - } - input.append("\n"); - - return run(args, input); -} - QString CoreInterface::run(const QStringList& args, const QString& input) { QString program( diff --git a/src/gui/src/CoreInterface.h b/src/gui/src/CoreInterface.h index 45ae47d1..ce8bf1a7 100644 --- a/src/gui/src/CoreInterface.h +++ b/src/gui/src/CoreInterface.h @@ -28,9 +28,5 @@ public: QString getInstalledDir(); QString getArch(); QString getSerialKeyFilePath(); - QString notifyActivation(const QString& identity); - QString notifyUpdate (QString const& fromVersion, - QString const& toVersion, - QString const& serialKey); QString run(const QStringList& args, const QString& input = ""); }; diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index f49a5000..863b2aa3 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -17,7 +17,6 @@ #include "SetupWizard.h" #include "MainWindow.h" -#include "WebClient.h" #include "ActivationNotifier.h" #include "LicenseManager.h" #include "QSynergyApplication.h" diff --git a/src/gui/src/WebClient.cpp b/src/gui/src/WebClient.cpp deleted file mode 100644 index 99ad1a13..00000000 --- a/src/gui/src/WebClient.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2015-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "WebClient.h" - -#include "QUtility.h" - -#include -#include -#include -#include - -bool -WebClient::getEdition (int& edition, QString& errorOut) { - QString responseJson = request(); - - /* TODO: This is horrible and should be ripped out as soon as we move - * to Qt 5. See issue #5630 - */ - - QRegExp resultRegex(".*\"result\".*:.*(true|false).*"); - if (resultRegex.exactMatch (responseJson)) { - QString boolString = resultRegex.cap(1); - if (boolString == "true") { - QRegExp editionRegex(".*\"edition\".*:.*\"([^\"]+)\".*"); - if (editionRegex.exactMatch(responseJson)) { - QString e = editionRegex.cap(1); - edition = e.toInt(); - return true; - } else { - throw std::runtime_error ("Unrecognised server response."); - } - } else { - errorOut = tr("Login failed. Invalid email address or password."); - return false; - } - } else { - QRegExp errorRegex(".*\"error\".*:.*\"([^\"]+)\".*"); - if (errorRegex.exactMatch (responseJson)) { - errorOut = errorRegex.cap(1).replace("\\n", "\n"); - return false; - } else { - throw std::runtime_error ("Unrecognised server response."); - } - } -} - -bool -WebClient::setEmail (QString email, QString& errorOut) { - if (email.isEmpty()) { - errorOut = tr("Your email address cannot be left blank."); - return false; - } - m_Email = email; - return true; -} - -bool -WebClient::setPassword (QString password, QString&) { - m_Password = password; - return true; -} - -QString -WebClient::request() { - QStringList args("--login-auth"); - QString credentials (m_Email + ":" + hash(m_Password) + "\n"); - return m_CoreInterface.run (args, credentials); -} diff --git a/src/gui/src/WebClient.h b/src/gui/src/WebClient.h deleted file mode 100644 index 2280031e..00000000 --- a/src/gui/src/WebClient.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2015-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef WEBCLIENT_H -#define WEBCLIENT_H - -#include -#include - -#include "CoreInterface.h" - -class QMessageBox; -class QWidget; -class QStringList; - -class WebClient : public QObject -{ - Q_OBJECT - -public: - bool getEdition (int& edition, QString& errorOut); - bool setEmail (QString email, QString& errorOut); - bool setPassword (QString password, QString& errorOut); -signals: - void error(QString e); - -private: - QString request(); - - QString m_Email; - QString m_Password; - CoreInterface m_CoreInterface; -}; - -#endif // WEBCLIENT_H diff --git a/src/lib/arch/Arch.h b/src/lib/arch/Arch.h index 0b6740a6..99a26a57 100644 --- a/src/lib/arch/Arch.h +++ b/src/lib/arch/Arch.h @@ -50,7 +50,6 @@ # include "arch/win32/ArchSystemWindows.h" # include "arch/win32/ArchTaskBarWindows.h" # include "arch/win32/ArchTimeWindows.h" -# include "arch/win32/ArchInternetWindows.h" #elif SYSAPI_UNIX # include "arch/unix/ArchConsoleUnix.h" # include "arch/unix/ArchDaemonUnix.h" @@ -65,7 +64,6 @@ # include "arch/unix/ArchSystemUnix.h" # include "arch/unix/ArchTaskBarXWindows.h" # include "arch/unix/ArchTimeUnix.h" -# include "arch/unix/ArchInternetUnix.h" #endif /*! @@ -120,11 +118,8 @@ public: static void setInstance(Arch* s) { s_instance = s; } - ARCH_INTERNET& internet() const { return (ARCH_INTERNET&)m_internet; } - private: static Arch* s_instance; - ARCH_INTERNET m_internet; }; //! Convenience object to lock/unlock an arch mutex diff --git a/src/lib/arch/unix/ArchInternetUnix.cpp b/src/lib/arch/unix/ArchInternetUnix.cpp deleted file mode 100644 index 06326ed6..00000000 --- a/src/lib/arch/unix/ArchInternetUnix.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "arch/unix/ArchInternetUnix.h" - -#include "arch/XArch.h" -#include "common/Version.h" -#include "base/Log.h" - -#include -#include - -class CurlFacade { -public: - CurlFacade(); - ~CurlFacade(); - String get(const String& url); - String urlEncode(const String& url); - -private: - CURL* m_curl; -}; - -// -// ArchInternetUnix -// - -String -ArchInternetUnix::get(const String& url) -{ - CurlFacade curl; - return curl.get(url); -} - -String -ArchInternetUnix::urlEncode(const String& url) -{ - CurlFacade curl; - return curl.urlEncode(url); -} - -// -// CurlFacade -// - -static size_t -curlWriteCallback(void *contents, size_t size, size_t nmemb, void *userp) -{ - ((std::string*)userp)->append((char*)contents, size * nmemb); - return size * nmemb; -} - -CurlFacade::CurlFacade() : - m_curl(NULL) -{ - CURLcode init = curl_global_init(CURL_GLOBAL_ALL); - if (init != CURLE_OK) { - throw XArch("CURL global init failed."); - } - - m_curl = curl_easy_init(); - if (m_curl == NULL) { - throw XArch("CURL easy init failed."); - } -} - -CurlFacade::~CurlFacade() -{ - if (m_curl != NULL) { - curl_easy_cleanup(m_curl); - } - - curl_global_cleanup(); -} - -String -CurlFacade::get(const String& url) -{ - curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlWriteCallback); - - std::stringstream userAgent; - userAgent << "Synergy "; - userAgent << kVersion; - curl_easy_setopt(m_curl, CURLOPT_USERAGENT, userAgent.str().c_str()); - - std::string result; - curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &result); - - CURLcode code = curl_easy_perform(m_curl); - if (code != CURLE_OK) { - LOG((CLOG_ERR "curl perform error: %s", curl_easy_strerror(code))); - throw XArch("CURL perform failed."); - } - - return result; -} - -String -CurlFacade::urlEncode(const String& url) -{ - char* resultCStr = curl_easy_escape(m_curl, url.c_str(), 0); - - if (resultCStr == NULL) { - throw XArch("CURL escape failed."); - } - - std::string result(resultCStr); - curl_free(resultCStr); - - return result; -} diff --git a/src/lib/arch/unix/ArchInternetUnix.h b/src/lib/arch/unix/ArchInternetUnix.h deleted file mode 100644 index 6fcf2b59..00000000 --- a/src/lib/arch/unix/ArchInternetUnix.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define ARCH_INTERNET ArchInternetUnix - -#include "base/String.h" - -class ArchInternetUnix { -public: - String get(const String& url); - String urlEncode(const String& url); -}; diff --git a/src/lib/arch/win32/ArchInternetWindows.cpp b/src/lib/arch/win32/ArchInternetWindows.cpp deleted file mode 100644 index 5844d15d..00000000 --- a/src/lib/arch/win32/ArchInternetWindows.cpp +++ /dev/null @@ -1,224 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "arch/win32/ArchInternetWindows.h" -#include "arch/win32/XArchWindows.h" -#include "arch/Arch.h" -#include "common/Version.h" - -#include -#include -#include - -struct WinINetUrl { - String m_scheme; - String m_host; - String m_path; - INTERNET_PORT m_port; - DWORD m_flags; -}; - -class WinINetRequest { -public: - WinINetRequest(const String& url); - ~WinINetRequest(); - - String send(); - void openSession(); - void connect(); - void openRequest(); - -private: - HINTERNET m_session; - HINTERNET m_connect; - HINTERNET m_request; - WinINetUrl m_url; - bool m_used; -}; - -// -// ArchInternetWindows -// - -String -ArchInternetWindows::get(const String& url) -{ - WinINetRequest request(url); - return request.send(); -} - -String -ArchInternetWindows::urlEncode(const String& url) -{ - TCHAR buffer[1024]; - DWORD bufferSize = sizeof(buffer); - - if (UrlEscape(url.c_str(), buffer, &bufferSize, URL_ESCAPE_UNSAFE) != S_OK) { - throw XArch(new XArchEvalWindows()); - } - - String result(buffer); - - // the win32 url encoding funcitons are pretty useless (to us) and only - // escape "unsafe" chars, but not + or =, so we need to replace these - // manually (and probably many other chars). - synergy::string::findReplaceAll(result, "+", "%2B"); - synergy::string::findReplaceAll(result, "=", "%3D"); - - return result; -} - -// -// WinINetRequest -// - -static WinINetUrl parseUrl(const String& url); - -WinINetRequest::WinINetRequest(const String& url) : - m_session(NULL), - m_connect(NULL), - m_request(NULL), - m_used(false), - m_url(parseUrl(url)) -{ -} - -WinINetRequest::~WinINetRequest() -{ - if (m_request != NULL) { - InternetCloseHandle(m_request); - } - - if (m_connect != NULL) { - InternetCloseHandle(m_connect); - } - - if (m_session != NULL) { - InternetCloseHandle(m_session); - } -} - -String -WinINetRequest::send() -{ - if (m_used) { - throw XArch("class is one time use."); - } - m_used = true; - - openSession(); - connect(); - openRequest(); - - String headers("Content-Type: text/html"); - if (!HttpSendRequest(m_request, headers.c_str(), (DWORD)headers.length(), NULL, NULL)) { - throw XArch(new XArchEvalWindows()); - } - - std::stringstream result; - CHAR buffer[1025]; - DWORD read = 0; - - while (InternetReadFile(m_request, buffer, sizeof(buffer) - 1, &read) && (read != 0)) { - buffer[read] = 0; - result << buffer; - read = 0; - } - - return result.str(); -} - -void -WinINetRequest::openSession() -{ - std::stringstream userAgent; - userAgent << "Synergy "; - userAgent << kVersion; - - m_session = InternetOpen( - userAgent.str().c_str(), - INTERNET_OPEN_TYPE_PRECONFIG, - NULL, - NULL, - NULL); - - if (m_session == NULL) { - throw XArch(new XArchEvalWindows()); - } -} - -void -WinINetRequest::connect() -{ - m_connect = InternetConnect( - m_session, - m_url.m_host.c_str(), - m_url.m_port, - NULL, - NULL, - INTERNET_SERVICE_HTTP, - NULL, - NULL); - - if (m_connect == NULL) { - throw XArch(new XArchEvalWindows()); - } -} - -void -WinINetRequest::openRequest() -{ - m_request = HttpOpenRequest( - m_connect, - "GET", - m_url.m_path.c_str(), - HTTP_VERSION, - NULL, - NULL, - m_url.m_flags, - NULL); - - if (m_request == NULL) { - throw XArch(new XArchEvalWindows()); - } -} - -// nb: i tried to use InternetCrackUrl here, but couldn't quite get that to -// work. here's some (less robust) code to split the url into components. -// this works fine with simple urls, but doesn't consider the full url spec. -static WinINetUrl -parseUrl(const String& url) -{ - WinINetUrl parsed; - - size_t schemeEnd = url.find("://"); - size_t hostEnd = url.find('/', schemeEnd + 3); - - parsed.m_scheme = url.substr(0, schemeEnd); - parsed.m_host = url.substr(schemeEnd + 3, hostEnd - (schemeEnd + 3)); - parsed.m_path = url.substr(hostEnd); - - parsed.m_port = INTERNET_DEFAULT_HTTP_PORT; - parsed.m_flags = 0; - - if (parsed.m_scheme.find("https") != String::npos) { - parsed.m_port = INTERNET_DEFAULT_HTTPS_PORT; - parsed.m_flags = INTERNET_FLAG_SECURE; - } - - return parsed; -} diff --git a/src/lib/arch/win32/ArchInternetWindows.h b/src/lib/arch/win32/ArchInternetWindows.h deleted file mode 100644 index 3fda3334..00000000 --- a/src/lib/arch/win32/ArchInternetWindows.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2014-2016 Symless Ltd. - * - * This package is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * found in the file LICENSE that should have accompanied this file. - * - * This package 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#define ARCH_INTERNET ArchInternetWindows - -#include "base/String.h" - -class ArchInternetWindows { -public: - String get(const String& url); - String urlEncode(const String& url); -}; diff --git a/src/lib/synergy/ArgParser.cpp b/src/lib/synergy/ArgParser.cpp index c9da4e55..8690f455 100644 --- a/src/lib/synergy/ArgParser.cpp +++ b/src/lib/synergy/ArgParser.cpp @@ -179,10 +179,6 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv) args.m_printActiveDesktopName = true; return true; } - else if (isArg(i, argc, argv, NULL, "--login-auth", 0)) { - args.m_loginAuthenticate = true; - return true; - } else if (isArg(i, argc, argv, NULL, "--get-installed-dir", 0)) { args.m_getInstalledDir = true; return true; @@ -195,14 +191,6 @@ ArgParser::parseToolArgs(ToolArgs& args, int argc, const char* const* argv) args.m_getArch = true; return true; } - else if (isArg(i, argc, argv, NULL, "--notify-activation", 0)) { - args.m_notifyActivation = true; - return true; - } - else if (isArg(i, argc, argv, NULL, "--notify-update", 0)) { - args.m_notifyUpdate = true; - return true; - } else { return false; } diff --git a/src/lib/synergy/ToolApp.cpp b/src/lib/synergy/ToolApp.cpp index 8a9e1faf..540dd28a 100644 --- a/src/lib/synergy/ToolApp.cpp +++ b/src/lib/synergy/ToolApp.cpp @@ -68,9 +68,6 @@ ToolApp::run(int argc, char** argv) } #endif } - else if (m_args.m_loginAuthenticate) { - loginAuth(); - } else if (m_args.m_getInstalledDir) { std::cout << ARCH->getInstalledDirectory() << std::endl; } @@ -80,12 +77,6 @@ ToolApp::run(int argc, char** argv) else if (m_args.m_getArch) { std::cout << ARCH->getPlatformName() << std::endl; } - else if (m_args.m_notifyUpdate) { - notifyUpdate(); - } - else if (m_args.m_notifyActivation) { - notifyActivation(); - } else { throw XSynergy("Nothing to do"); } @@ -111,96 +102,3 @@ void ToolApp::help() { } - -void -ToolApp::loginAuth() -{ - String credentials; - std::cin >> credentials; - - std::vector parts = synergy::string::splitString(credentials, ':'); - size_t count = parts.size(); - - if (count == 2 ) { - String email = parts[0]; - String password = parts[1]; - - std::stringstream ss; - ss << JSON_URL << "auth/"; - ss << "?email=" << ARCH->internet().urlEncode(email); - ss << "&password=" << password; - - std::cout << ARCH->internet().get(ss.str()) << std::endl; - } - else { - throw XSynergy("Invalid credentials."); - } -} - -void -ToolApp::notifyUpdate() -{ - String data; - std::cin >> data; - - std::vector parts = synergy::string::splitString(data, ':'); - size_t count = parts.size(); - - if (count == 3) { - std::stringstream ss; - ss << JSON_URL << "notify/update"; - ss << "?from=" << parts[0]; - ss << "&to=" << parts[1]; - ss << "&serial=" << parts[2]; - - std::cout << ARCH->internet().get(ss.str()) << std::endl; - } - else { - throw XSynergy("Invalid update data."); - } -} - -void -ToolApp::notifyActivation() -{ - String info; - std::cin >> info; - - std::vector parts = synergy::string::splitString(info, ':'); - size_t count = parts.size(); - - if (count == 3 || count == 4) { - String action = parts[0]; - String identity = parts[1]; - String macHash = parts[2]; - String os; - - if (count == 4) { - os = parts[3]; - } - else { - os = ARCH->getOSName(); - } - - std::stringstream ss; - ss << JSON_URL << "notify/"; - ss << "?action=" << action; - ss << "&identity=" << ARCH->internet().urlEncode(identity); - ss << "&mac=" << ARCH->internet().urlEncode(macHash); - ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName()); - ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName()); - - try { - std::cout << ARCH->internet().get(ss.str()) << std::endl; - } - catch (std::exception& e) { - LOG((CLOG_NOTE "An error occurred during notification: %s\n", e.what())); - } - catch (...) { - LOG((CLOG_NOTE "An unknown error occurred during notification.\n")); - } - } - else { - LOG((CLOG_NOTE "notification failed")); - } -} diff --git a/src/lib/synergy/ToolArgs.cpp b/src/lib/synergy/ToolArgs.cpp index 07c3aa22..8292005b 100644 --- a/src/lib/synergy/ToolArgs.cpp +++ b/src/lib/synergy/ToolArgs.cpp @@ -19,11 +19,8 @@ ToolArgs::ToolArgs() : m_printActiveDesktopName(false), - m_loginAuthenticate(false), m_getInstalledDir(false), m_getProfileDir(false), - m_getArch(false), - m_notifyActivation(false), - m_notifyUpdate(false) + m_getArch(false) { } diff --git a/src/lib/synergy/ToolArgs.h b/src/lib/synergy/ToolArgs.h index 43928dd4..8a50da0d 100644 --- a/src/lib/synergy/ToolArgs.h +++ b/src/lib/synergy/ToolArgs.h @@ -25,10 +25,7 @@ public: public: bool m_printActiveDesktopName; - bool m_loginAuthenticate; bool m_getInstalledDir; bool m_getProfileDir; bool m_getArch; - bool m_notifyActivation; - bool m_notifyUpdate; };