Description: Allow disabling of online version check
 Gives a build-time option to disable curl-based check for new version.  Patch
 was submitted by author to upstream but it has not been merged.
Author: Andrey Kuznetsov (pm-kan on github), with modifications/additions by Bill Blough <bblough@debian.org>
Origin: https://github.com/pwsafe/pwsafe/commit/2a0f595edf83fe8d1433645e27dc444767fff315.diff
Forwarded: not-needed
Last-Update: 2019-08-19
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -83,6 +83,7 @@ endif (pwsafe_REVISION)
 # Configurable options:
 option (NO_YUBI "Set ON to disable YubiKey support" OFF)
 option (NO_GTEST "Set ON to disable gtest unit testing" OFF)
+option (NO_VERCHECK "Set ON to disable online version check" OFF)
 
 if (WIN32)
   option (WX_WINDOWS "Build wxWidget under Windows" OFF)
@@ -132,11 +133,13 @@ if (NOT WIN32 OR WX_WINDOWS)
                )
      endif (NOT PWSHINT_wxconfig)
   endif (NOT WIN32)
-  find_package(wxWidgets COMPONENTS adv base core html net REQUIRED)
+  find_package(wxWidgets COMPONENTS adv base core html REQUIRED)
   include(${wxWidgets_USE_FILE})
 
-  find_package(OpenSSL REQUIRED)
-  include_directories(${OPENSSL_INCLUDE_DIR})
+  if (NOT NO_VERCHECK)
+    find_package(OpenSSL REQUIRED)
+    include_directories(${OPENSSL_INCLUDE_DIR})
+  endif()
 endif (NOT WIN32 OR WX_WINDOWS)
 
 if (NOT WIN32)
@@ -214,6 +217,11 @@ if (res)
   set(pwsafe_VERSTRING "local")
 endif()
 
+if (NO_VERCHECK)
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_VERCHECK")
+  message(STATUS "Online version check disabled")
+endif (NO_VERCHECK)
+
 # Assume that we're either MSVC or a Unix-like
 if (MSVC)
 # Debug build looks for dlls with _D postfix, this provides it:
@@ -231,7 +239,6 @@ if (NO_YUBI)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_YUBI")
 endif (NO_YUBI)
 
-
 if (WX_WINDOWS)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D __WX__")
 endif (WX_WINDOWS)
@@ -360,9 +367,13 @@ if (XML_XERCESC)
   target_link_libraries(pwsafe ${XercesC_LIBRARY})
 endif (XML_XERCESC)
 
+if (NOT NO_VERCHECK)
+ set (CURL_LIBS "curl ${OPENSSL_SSL_LIBRARY}")
+endif ()
+
 if (APPLE)
     FIND_LIBRARY(QUARTZCORE_LIBS QuartzCore)
-    target_link_libraries(pwsafe ${wxWidgets_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES} ${QUARTZCORE_LIBS} curl ${OPENSSL_SSL_LIBRARY})
+    target_link_libraries(pwsafe ${wxWidgets_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES} ${QUARTZCORE_LIBS} ${CURL_LIBS})
 elseif (WIN32)
   if (NOT NO_YUBI)
    set (YUBILIB "YkLib22")
@@ -374,8 +385,7 @@ else ()
   if (NOT NO_QR)
     target_link_libraries(pwsafe qrencode  ${CMAKE_REQUIRED_LIBRARIES})
   endif (NOT NO_QR)
-  target_link_libraries(pwsafe ${wxWidgets_LIBRARIES} uuid Xtst X11 curl ${OPENSSL_SSL_LIBRARY}
-  ${CMAKE_REQUIRED_LIBRARIES})
+  target_link_libraries(pwsafe ${wxWidgets_LIBRARIES} uuid Xtst X11 ${CURL_LIBS} ${CMAKE_REQUIRED_LIBRARIES})
 endif()
 
 if (IPO_SUPPORTED)
--- a/src/ui/wxWidgets/about.cpp
+++ b/src/ui/wxWidgets/about.cpp
@@ -53,14 +53,19 @@ BEGIN_EVENT_TABLE( CAbout, wxDialog )
   EVT_HYPERLINK( ID_CHECKNEW     , CAbout::OnCheckNewClicked   )
   EVT_HYPERLINK( ID_SITEHYPERLINK, CAbout::OnVisitSiteClicked  )
   EVT_BUTTON(    wxID_CLOSE      , CAbout::OnCloseClick        )
+#ifndef NO_VERCHECK
   EVT_THREAD(    wxID_ANY        , CAbout::OnDownloadCompleted )
-
+#endif
 END_EVENT_TABLE()
 
+#ifndef NO_VERCHECK
 wxString CAbout::s_VersionData = wxEmptyString;
+const cstringT s_URL_VERSION   =  "https://pwsafe.org/latest.xml";
+#else
+const cstringT s_URL_VERSION   =  "https://pwsafe.org/news.shtml";
+#endif
 
 const wstringT s_URL_HOME      = L"https://pwsafe.org";
-const cstringT s_URL_VERSION   =  "https://pwsafe.org/latest.xml";
 
 /*!
  * CAbout constructors
@@ -77,8 +82,12 @@ CAbout::CAbout( wxWindow* parent, wxWind
   Create(parent, id, caption, pos, size, style);
 
   // Print version information on standard output which might be useful for error reports.
+#if defined(_DEBUG) || defined(DEBUG)
   pws_os::Trace(GetLibWxVersion());
+#endif
+#ifndef NO_VERCHECK
   pws_os::Trace(GetLibCurlVersion());
+#endif // NO_VERCHECK
 }
 
 /*!
@@ -121,8 +130,10 @@ CAbout::~CAbout()
 
 void CAbout::Init()
 {
+#ifndef NO_VERCHECK
   m_VersionStatus = nullptr;
   m_CurlHandle = nullptr;
+#endif // NO_VERCHECK
 }
 
 /*!
@@ -178,9 +189,11 @@ void CAbout::CreateControls()
   wxStaticText* copyrightStaticText = new wxStaticText(aboutDialog, wxID_STATIC, _("Copyright (c) 2003-2019 Rony Shapiro"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
   rightSizer->Add(copyrightStaticText, 0, wxALIGN_LEFT|wxALL, 5);
 
+#ifndef NO_VERCHECK
   m_VersionStatus = new wxTextCtrl(aboutDialog, ID_TEXTCTRL, wxT("\n\n"), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxNO_BORDER);
   rightSizer->Add(m_VersionStatus, 0, wxALIGN_LEFT|wxALL|wxEXPAND|wxRESERVE_SPACE_EVEN_IF_HIDDEN, 5);
   m_VersionStatus->Hide();
+#endif // NO_VERCHECK
 
   wxButton* closeButton = new wxButton(aboutDialog, wxID_CLOSE, _("&Close"), wxDefaultPosition, wxDefaultSize, 0);
   rightSizer->Add(closeButton, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
@@ -233,7 +246,9 @@ wxIcon CAbout::GetIconResource( const wx
 
 void CAbout::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
 {
+#ifndef NO_VERCHECK
   Cleanup();
+#endif // NO_VERCHECK
   EndModal(wxID_CLOSE);
 }
 
@@ -243,10 +258,13 @@ void CAbout::OnCloseWindow( wxCloseEvent
 
 void CAbout::OnCloseClick( wxCommandEvent& WXUNUSED(event) )
 {
+#ifndef NO_VERCHECK
   Cleanup();
+#endif // NO_VERCHECK
   EndModal(wxID_CLOSE);
 }
 
+#ifndef NO_VERCHECK
 /**
  * Returns a <code>wxCriticalSection</code> object that is used to protect
  * the shared data <code>s_VersionData</code>, which is accessed by worker
@@ -403,14 +421,6 @@ wxString CAbout::GetLibCurlVersion()
 }
 
 /**
- * Provides version information about wxWidgets framework.
- */
-wxString CAbout::GetLibWxVersion()
-{
-  return wxString::Format("[wx] Wx Version:\n%s\n", wxGetLibraryVersionInfo().ToString());
-}
-
-/**
  * Checks whether database is closed.
  *
  * If database is open user is prompted to close the database.
@@ -691,6 +701,17 @@ void CAbout::OnDownloadCompleted(wxThrea
     s_VersionData.Empty();
   }
 }
+#endif // NO_VERCHECK
+
+#if defined(_DEBUG) || defined(DEBUG)
+/**
+ * Provides version information about wxWidgets framework.
+ */
+wxString CAbout::GetLibWxVersion()
+{
+  return wxString::Format("[wx] Wx Version:\n%s\n", wxGetLibraryVersionInfo().ToString());
+}
+#endif // debug
 
 /**
  * wxEVT_HYPERLINK event handler for ID_SITEHYPERLINK
@@ -698,3 +719,14 @@ void CAbout::OnDownloadCompleted(wxThrea
 void CAbout::OnVisitSiteClicked(wxHyperlinkEvent& WXUNUSED(event)) {
   wxLaunchDefaultBrowser(s_URL_HOME);
 }
+
+/**
+ * wxEVT_HYPERLINK event handler for ID_CHECKNEW
+ */
+void CAbout::OnCheckNewClicked(wxHyperlinkEvent& WXUNUSED(event)) {
+#ifndef NO_VERCHECK
+  CheckNewVersion();
+#else
+  wxLaunchDefaultBrowser(s_URL_VERSION);
+#endif // NO_VERCHECK
+}
--- a/src/ui/wxWidgets/Makefile
+++ b/src/ui/wxWidgets/Makefile
@@ -31,6 +31,12 @@ YUBIFLAGS=-DNO_YUBI
 YBPERS_LIBS=core
 endif
 
+ifndef NO_VERCHECK
+CURL_LDFLAGS=-lcurl -lssl
+else
+CURL_CPPFLAGS=-DNO_VERCHECK
+endif
+
 ifndef NO_QR
 ifeq ($(findstring Linux, $(shell uname -s)), Linux)
 QR_SRC=pwsqrcodedlg.cpp pwsqrencode.cpp
@@ -57,7 +63,7 @@ OUTPUTPATH=GCCDebug
 OBJECTPATH=GCCDebug
 BUILDPATHS=$(OBJECTPATH)
 PROGRAM=pwsafe
-LIBS=`$(WX_CONFIG) --debug=yes --unicode=no --libs` -lcore -los -lcore -luuid -lXtst -lX11  -lcurl -lssl -l$(YBPERS_LIBS) ${LIBCXX_LD_EXTRA_FLAGS}
+LIBS=`$(WX_CONFIG) --debug=yes --unicode=no --libs` -lcore -los -lcore -luuid -lXtst -lX11 $(CURL_LDFLAGS) -l$(YBPERS_LIBS) ${LIBCXX_LD_EXTRA_FLAGS}
 LINKERFLAGS=
 WARNINGFLAGS=-Wall
 OPTFLAGS=-O0
@@ -84,7 +90,7 @@ OUTPUTPATH=GCCRelease
 OBJECTPATH=GCCRelease
 BUILDPATHS=$(OBJECTPATH)
 PROGRAM=pwsafe
-LIBS=`$(WX_CONFIG) --debug=no --unicode=no --inplace --libs` -lcore -los -lcore -luuid -lXtst -lX11 -lcurl -lssl -l$(YBPERS_LIBS)
+LIBS=`$(WX_CONFIG) --debug=no --unicode=no --inplace --libs` -lcore -los -lcore -luuid -lXtst -lX11 $(CURL_LDFLAGS) -l$(YBPERS_LIBS)
 LINKERFLAGS=
 WARNINGFLAGS=-Wall
 OPTFLAGS=-O
@@ -113,7 +119,7 @@ BUILDPATHS=$(OBJECTPATH)
 PROGRAM=pwsafe
 LIBS=`$(WX_CONFIG) --debug=yes --unicode=yes --inplace --libs` -lcore -los -lcore -l$(YBPERS_LIBS)
 ifneq ($(findstring Darwin, $(shell uname -s)), Darwin)
-		LIBS += -luuid -lXtst -lX11 -lcurl -lssl
+		LIBS += -luuid -lXtst -lX11 $(CURL_LDFLAGS)
 		XERCESLIBFLAGS=-lxerces-c
 		XERCESCPPFLAGS=-DUSE_XML_LIBRARY=XERCES -DWCHAR_INCOMPATIBLE_XMLCH
 endif
@@ -144,7 +150,7 @@ BUILDPATHS=$(OBJECTPATH)
 PROGRAM=pwsafe
 LIBS=`$(WX_CONFIG) --debug=no --unicode=yes --inplace --libs` -lcore -los -lcore -l$(YBPERS_LIBS)
 ifneq ($(findstring Darwin, $(shell uname -s)), Darwin)
-		LIBS += -luuid -lXtst -lX11 -lcurl -lssl
+		LIBS += -luuid -lXtst -lX11 $(CURL_LDFLAGS)
 		XERCESLIBFLAGS=-lxerces-c
 		XERCESCPPFLAGS=-DUSE_XML_LIBRARY=XERCES -DWCHAR_INCOMPATIBLE_XMLCH
 endif
@@ -182,7 +188,7 @@ ifeq ($(findstring Darwin, $(shell uname
 		override LIBS += -framework QuartzCore
 endif
 override LDFLAGS:=$(LIBS) -L$(LIBPATH) $(LINKERFLAGS) $(XERCESLIBFLAGS) $(YBPERS_LIBPATH_FLAGS) $(LDFLAGS)
-CPPFLAGS:=$(CXXFLAGS) $(CPPINC) $(GCCFLAGS) $(DEBUGFLAGS) $(OPTFLAGS) $(WARNINGFLAGS) $(XERCESCPPFLAGS) $(YUBIFLAGS) $(QRFLAGS) $(CPPFLAGS)
+CPPFLAGS:=$(CXXFLAGS) $(CPPINC) $(GCCFLAGS) $(DEBUGFLAGS) $(OPTFLAGS) $(WARNINGFLAGS) $(XERCESCPPFLAGS) $(YUBIFLAGS) $(QRFLAGS) $(CURL_CPPFLAGS) $(CPPFLAGS)
 
 SOURCES= passwordsafeframe.cpp \
 	pwsafeapp.cpp safecombinationentry.cpp \
--- a/src/ui/wxWidgets/about.h
+++ b/src/ui/wxWidgets/about.h
@@ -19,12 +19,14 @@
 ////@begin includes
 #include <wx/hyperlink.h>
 #include <wx/event.h>
-#include <wx/thread.h>
-////@end includes
 
 #include "os/typedefs.h"
 
+#ifndef NO_VERCHECK
+#include <wx/thread.h>
 #include <curl/curl.h>
+#endif // NO_VERCHECK
+////@end includes
 
 /*!
  * Forward declarations
@@ -54,22 +56,32 @@
  * CAbout class declaration
  */
 
-class CAbout: public wxDialog, public wxThreadHelper
+class CAbout: public wxDialog
+#ifndef NO_VERCHECK
+              , public wxThreadHelper
+#endif // NO_VERCHECK
 {
   DECLARE_CLASS( CAbout )
   DECLARE_EVENT_TABLE()
 
+#if defined(_DEBUG) || defined(DEBUG)
+  wxString GetLibWxVersion();
+#endif //debug
+
+#ifndef NO_VERCHECK
   void CompareVersionData();
   bool CheckDatabaseStatus();
   bool SetupConnection();
   void Cleanup();
+#if defined(_DEBUG) || defined(DEBUG)
   wxString GetLibCurlVersion();
-  wxString GetLibWxVersion();
+#endif //debug
   static wxCriticalSection& CriticalSection();
   static size_t WriteCallback(char *receivedData, size_t size, size_t bytes, void *userData);
 
 protected:
   virtual wxThread::ExitCode Entry();
+#endif // NO_VERCHECK
 
 public:
   /// Constructors
@@ -82,18 +94,17 @@ public:
   /// Destructor
   ~CAbout();
 
-  /// Initialises member variables
+  /// Initializes member variables
   void Init();
 
   /// Creates the controls and sizers
   void CreateControls();
-
+#ifndef NO_VERCHECK
   void CheckNewVersion();
-
+#endif // NO_VERCHECK
 ////@begin CAbout event handler declarations
-
   /// event handler for ID_CHECKNEW
-  void OnCheckNewClicked(wxHyperlinkEvent& WXUNUSED(event)) { CheckNewVersion(); };
+  void OnCheckNewClicked(wxHyperlinkEvent& event);
 
   /// event handler for ID_SITEHYPERLINK
   void OnVisitSiteClicked(wxHyperlinkEvent& event);
@@ -104,8 +115,11 @@ public:
   /// wxEVT_CLOSE_WINDOW event handler
   void OnCloseWindow( wxCloseEvent& event );
 
+#ifndef NO_VERCHECK
   /// wxEVT_THREAD event handler for wxID_ANY
   void OnDownloadCompleted(wxThreadEvent& event);
+#endif // NO_VERCHECK
+
 ////@end CAbout event handler declarations
 
 ////@begin CAbout member function declarations
@@ -121,6 +135,7 @@ public:
   static bool ShowToolTips();
 
 private:
+#ifndef NO_VERCHECK
 ////@begin CAbout member variables
   wxTextCtrl* m_VersionStatus;
 ////@end CAbout member variables
@@ -130,9 +145,7 @@ private:
 
   /// Set to downloaded data by worker thread, resp. WriteCallback, and read by main thread for final version check
   static wxString s_VersionData;
-
-  static const wstringT s_HOME_URL;
-  static const cstringT s_VERSION_URL;
+#endif // NO_VERCHECK
 };
 
 #endif /* _ABOUT_H_ */
