From 19f5ad8cabcef647c52c2912c2f9d49ff6dba0da Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Tue, 23 Jun 2015 17:10:49 -0700 Subject: [PATCH 01/10] Add delay routine to MainWindow to allow sleep in a Qt friendly way #4823 --- src/gui/src/MainWindow.cpp | 9 +++++++++ src/gui/src/MainWindow.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 1ecfde01..fa09d8ad 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -1351,3 +1351,12 @@ QString MainWindow::getProfileRootForArg() return QString("\"%1\"").arg(dir); } + +void MainWindow::delay(unsigned int s) +{ + QTime dieTime= QTime::currentTime().addSecs(s); + + while( QTime::currentTime() < dieTime ) { + QCoreApplication::processEvents(QEventLoop::AllEvents, 100); + } +} diff --git a/src/gui/src/MainWindow.h b/src/gui/src/MainWindow.h index 80b1dbb4..7f81d177 100644 --- a/src/gui/src/MainWindow.h +++ b/src/gui/src/MainWindow.h @@ -63,6 +63,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase friend class QSynergyApplication; friend class SetupWizard; + friend class PluginWizardPage; public: enum qSynergyState @@ -108,6 +109,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindowBase void serverDetected(const QString name); void setEdition(int type); void updateLocalFingerprint(); + void delay(unsigned int); public slots: void appendLogRaw(const QString& text); From 6442bcb8f6b4966fb8aad0b367809d82c802606c Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Tue, 23 Jun 2015 17:11:39 -0700 Subject: [PATCH 02/10] Change PluginWizardPage to take and use MainWindow instead of appConfig #4823 --- src/gui/src/PluginWizardPage.cpp | 12 +++++++++--- src/gui/src/PluginWizardPage.h | 5 +++-- src/gui/src/SetupWizard.cpp | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/gui/src/PluginWizardPage.cpp b/src/gui/src/PluginWizardPage.cpp index 9c2994a6..331d6a0c 100644 --- a/src/gui/src/PluginWizardPage.cpp +++ b/src/gui/src/PluginWizardPage.cpp @@ -22,16 +22,18 @@ #include "FileSysClient.h" #include "WebClient.h" #include "PluginManager.h" +#include "MainWindow.h" #include #include +#include -PluginWizardPage::PluginWizardPage(AppConfig& appConfig, QWidget *parent) : +PluginWizardPage::PluginWizardPage(MainWindow& mainWindow, QWidget *parent) : QWizardPage(parent), m_Finished(false), m_pFileSysClient(NULL), m_pSslCertificate(NULL), - m_AppConfig(appConfig) + m_mainWindow(mainWindow) { setupUi(this); @@ -77,14 +79,18 @@ void PluginWizardPage::queryPluginDone() showFinished(); } else { + m_mainWindow.stopSynergy(); + m_mainWindow.delay(5); copyPlugins(); + m_mainWindow.startSynergy(); + m_mainWindow.delay(5); } } void PluginWizardPage::finished() { // TODO: we should check if ns plugin exists - m_AppConfig.setCryptoEnabled(true); + m_mainWindow.appConfig().setCryptoEnabled(true); updateStatus(tr("Plugins installed successfully.")); showFinished(); diff --git a/src/gui/src/PluginWizardPage.h b/src/gui/src/PluginWizardPage.h index dbd834b7..8b2006b7 100644 --- a/src/gui/src/PluginWizardPage.h +++ b/src/gui/src/PluginWizardPage.h @@ -27,13 +27,14 @@ class FileSysClient; class WebClient; class SslCertificate; +class MainWindow; class PluginWizardPage : public QWizardPage, public Ui::PluginWizardPage { Q_OBJECT public: - PluginWizardPage(AppConfig& appConfig, QWidget *parent = 0); + PluginWizardPage(MainWindow& mainWindow, QWidget *parent = 0); ~PluginWizardPage(); void setFinished(bool b) { m_Finished = b; } @@ -66,6 +67,6 @@ private: PluginManager m_PluginManager; SslCertificate* m_pSslCertificate; QThread* m_pThread; - AppConfig& m_AppConfig; + MainWindow& m_mainWindow; }; #endif // PLUGINWIZARDPAGE_H diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index b4414142..5bb400fb 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -30,7 +30,7 @@ SetupWizard::SetupWizard(MainWindow& mainWindow, bool startMain) : m_Edition(Unknown) { setupUi(this); - m_pPluginPage = new PluginWizardPage(mainWindow.appConfig()); + m_pPluginPage = new PluginWizardPage(mainWindow); addPage(m_pPluginPage); #if defined(Q_OS_MAC) From c9b60eca271810cc872dbe34d670057cecceaaab Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Wed, 24 Jun 2015 10:34:19 -0700 Subject: [PATCH 03/10] Changed secure connest and accept to match read/write retry logic #4750 --- src/lib/plugin/ns/SecureSocket.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index b753188a..a898e5a8 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -429,11 +429,19 @@ SecureSocket::checkResult(int status, int& retry) break; case SSL_ERROR_WANT_CONNECT: - case SSL_ERROR_WANT_ACCEPT: + m_writable = true; + m_readable = true; retry++; LOG((CLOG_DEBUG2 "want to connect, error=%d, attempt=%d", errorCode, retry)); break; + case SSL_ERROR_WANT_ACCEPT: + m_writable = true; + m_readable = true; + retry++; + LOG((CLOG_DEBUG2 "want to accept, error=%d, attempt=%d", errorCode, retry)); + break; + case SSL_ERROR_SYSCALL: LOG((CLOG_ERR "ssl error occurred (system call failure)")); if (ERR_peek_error() == 0) { From e50b2395924fb61dc1a2b71c645dbc17e8852d88 Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Wed, 24 Jun 2015 11:11:20 -0700 Subject: [PATCH 04/10] Changed secure connest and accept to match read/write retry logic #4750 --- src/lib/plugin/ns/SecureSocket.cpp | 34 +++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index b753188a..d18d53c7 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -429,11 +429,19 @@ SecureSocket::checkResult(int status, int& retry) break; case SSL_ERROR_WANT_CONNECT: - case SSL_ERROR_WANT_ACCEPT: + m_writable = true; + m_readable = true; retry++; LOG((CLOG_DEBUG2 "want to connect, error=%d, attempt=%d", errorCode, retry)); break; + case SSL_ERROR_WANT_ACCEPT: + m_writable = true; + m_readable = true; + retry++; + LOG((CLOG_DEBUG2 "want to accept, error=%d, attempt=%d", errorCode, retry)); + break; + case SSL_ERROR_SYSCALL: LOG((CLOG_ERR "ssl error occurred (system call failure)")); if (ERR_peek_error() == 0) { @@ -595,14 +603,12 @@ SecureSocket::serviceConnect(ISocketMultiplexerJob* job, status = secureConnect(getSocket()->m_fd); #endif - if (status > 0) { - return newJob(); - } - else if (status == 0) { - return job; - } // If status < 0, error happened - return NULL; + if (status < 0) { + return NULL; + } + + return newJob(); } ISocketMultiplexerJob* @@ -618,14 +624,12 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job, status = secureAccept(getSocket()->m_fd); #endif - if (status > 0) { - return newJob(); - } - else if (status == 0) { - return job; - } // If status < 0, error happened - return NULL; + if (status < 0) { + return NULL; + } + + return newJob(); } void From 2df88e07c4b21ba6361732e59400db16e8474302 Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Wed, 24 Jun 2015 12:20:25 -0700 Subject: [PATCH 05/10] fixed retry logic for secure connect and accept #4750 --- src/lib/plugin/ns/SecureSocket.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index d18d53c7..7533350d 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -299,6 +299,7 @@ SecureSocket::secureAccept(int socket) LOG((CLOG_INFO "client connection may not be secure")); m_secureReady = false; ARCH->sleep(1); + retry = 0; return -1; // Failed, error out } @@ -342,6 +343,7 @@ SecureSocket::secureConnect(int socket) if (isFatal()) { LOG((CLOG_ERR "failed to connect secure socket")); + retry = 0; return -1; } @@ -352,6 +354,7 @@ SecureSocket::secureConnect(int socket) return 0; } + retry = 0; // No error, set ready, process and return ok m_secureReady = true; if (verifyCertFingerprint()) { @@ -623,7 +626,7 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job, #elif SYSAPI_UNIX status = secureAccept(getSocket()->m_fd); #endif - + LOG((CLOG_ERR "DELME: status:%d",status)); // If status < 0, error happened if (status < 0) { return NULL; From f10f0f13c43635f1e3587d6d6a5f36e91011d777 Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Wed, 24 Jun 2015 16:31:47 -0700 Subject: [PATCH 06/10] retry case needs to do another job with the same parameters not just a new job #4750 --- src/lib/plugin/ns/SecureSocket.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index 7533350d..9f803f8c 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -439,7 +439,7 @@ SecureSocket::checkResult(int status, int& retry) break; case SSL_ERROR_WANT_ACCEPT: - m_writable = true; + m_writable = true; m_readable = true; retry++; LOG((CLOG_DEBUG2 "want to accept, error=%d, attempt=%d", errorCode, retry)); @@ -611,7 +611,15 @@ SecureSocket::serviceConnect(ISocketMultiplexerJob* job, return NULL; } - return newJob(); + // If status > 0, success + if (status > 0) { + return newJob(); + } + + // Retry case + return new TSocketMultiplexerMethodJob( + this, &SecureSocket::serviceConnect, + getSocket(), isReadable(), isWritable()); } ISocketMultiplexerJob* @@ -626,13 +634,20 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job, #elif SYSAPI_UNIX status = secureAccept(getSocket()->m_fd); #endif - LOG((CLOG_ERR "DELME: status:%d",status)); - // If status < 0, error happened + // If status < 0, error happened if (status < 0) { return NULL; } - return newJob(); + // If status > 0, success + if (status > 0) { + return newJob(); + } + + // Retry case + return new TSocketMultiplexerMethodJob( + this, &SecureSocket::serviceConnect, + getSocket(), isReadable(), isWritable()); } void From 55a38ff8cca04f810fd626d5f7501b1d778b997b Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Wed, 24 Jun 2015 17:57:22 -0700 Subject: [PATCH 07/10] removed unnecessary flag settings, fixed wrong call. #4750 --- src/lib/plugin/ns/SecureSocket.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index 9f803f8c..397e2e5e 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -420,7 +420,6 @@ SecureSocket::checkResult(int status, int& retry) break; case SSL_ERROR_WANT_READ: - m_readable = true; retry++; LOG((CLOG_DEBUG2 "want to read, error=%d, attempt=%d", errorCode, retry)); break; @@ -432,15 +431,11 @@ SecureSocket::checkResult(int status, int& retry) break; case SSL_ERROR_WANT_CONNECT: - m_writable = true; - m_readable = true; retry++; LOG((CLOG_DEBUG2 "want to connect, error=%d, attempt=%d", errorCode, retry)); break; case SSL_ERROR_WANT_ACCEPT: - m_writable = true; - m_readable = true; retry++; LOG((CLOG_DEBUG2 "want to accept, error=%d, attempt=%d", errorCode, retry)); break; @@ -646,7 +641,7 @@ SecureSocket::serviceAccept(ISocketMultiplexerJob* job, // Retry case return new TSocketMultiplexerMethodJob( - this, &SecureSocket::serviceConnect, + this, &SecureSocket::serviceAccept, getSocket(), isReadable(), isWritable()); } From d7043ef84b73ffc5a96f0a7eaf413d8a6e8a970f Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Thu, 25 Jun 2015 09:35:56 -0700 Subject: [PATCH 08/10] Added plugin version output to unix builds #4793 --- src/lib/arch/unix/ArchPluginUnix.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/arch/unix/ArchPluginUnix.cpp b/src/lib/arch/unix/ArchPluginUnix.cpp index 3e390f06..bba2b017 100644 --- a/src/lib/arch/unix/ArchPluginUnix.cpp +++ b/src/lib/arch/unix/ArchPluginUnix.cpp @@ -35,6 +35,7 @@ typedef void (*cleanupFunc)(); void* g_eventTarget = NULL; IEventQueue* g_events = NULL; +static const char kPre174Plugin[] = "Pre-1.7.4"; ArchPluginUnix::ArchPluginUnix() { @@ -82,7 +83,13 @@ ArchPluginUnix::load() String filename = synergy::string::removeFileExt(*it); m_pluginTable.insert(std::make_pair(filename, library)); - LOG((CLOG_DEBUG "loaded plugin: %s", (*it).c_str())); + + const char * version = (char*)invoke( filename.c_str(),"version",NULL); + if (version == NULL) { + version = kPre174Plugin; + } + + LOG((CLOG_DEBUG "loaded plugin: %s (%s)", (*it).c_str(),version)); } } From 4569de54133dd1f727c70c94da2c52afab7faf4e Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Thu, 25 Jun 2015 09:44:16 -0700 Subject: [PATCH 09/10] Fixed misplaces statis string in windows code #4793 --- src/lib/arch/win32/ArchPluginWindows.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/arch/win32/ArchPluginWindows.cpp b/src/lib/arch/win32/ArchPluginWindows.cpp index 1f560e06..37440d7c 100644 --- a/src/lib/arch/win32/ArchPluginWindows.cpp +++ b/src/lib/arch/win32/ArchPluginWindows.cpp @@ -34,6 +34,7 @@ typedef void (*cleanupFunc)(); void* g_eventTarget = NULL; IEventQueue* g_events = NULL; +static const char * kPre174Plugin = "Pre-1.7.v"; ArchPluginWindows::ArchPluginWindows() { @@ -69,9 +70,9 @@ ArchPluginWindows::load() String filename = synergy::string::removeFileExt(*it); m_pluginTable.insert(std::make_pair(filename, lib)); - char * version = (char*)invoke( filename.c_str(),"version",NULL); + const char * version = (char*)invoke( filename.c_str(),"version",NULL); if (version == NULL) { - version = "Pre-1.7.4"; + version = kPre174Plugin; } LOG((CLOG_DEBUG "loaded plugin: %s (%s)", (*it).c_str(),version)); From 9dc0a1d862c234303b6b385a77daf40017a155ed Mon Sep 17 00:00:00 2001 From: Adam Potolsky Date: Thu, 25 Jun 2015 09:54:28 -0700 Subject: [PATCH 10/10] Added comment for clarity #4750 --- src/lib/plugin/ns/SecureSocket.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/plugin/ns/SecureSocket.cpp b/src/lib/plugin/ns/SecureSocket.cpp index 397e2e5e..40c3f219 100644 --- a/src/lib/plugin/ns/SecureSocket.cpp +++ b/src/lib/plugin/ns/SecureSocket.cpp @@ -425,6 +425,9 @@ SecureSocket::checkResult(int status, int& retry) break; case SSL_ERROR_WANT_WRITE: + // Need to make sure the socket is known to be writable so the impending + // select action actually triggers on a write. This isn't necessary for + // m_readable because the socket logic is always readable m_writable = true; retry++; LOG((CLOG_DEBUG2 "want to write, error=%d, attempt=%d", errorCode, retry));