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
@@ -85,6 +85,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)
@@ -134,11 +135,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()
 
   find_package(Magic REQUIRED)
   include_directories(${MAGIC_INCLUDE_DIRS})
@@ -219,6 +222,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:
@@ -236,7 +244,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)
@@ -366,9 +373,14 @@ 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")
@@ -380,8 +392,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} ${MAGIC_LIBRARIES}
-  ${CMAKE_REQUIRED_LIBRARIES})
+  target_link_libraries(pwsafe ${wxWidgets_LIBRARIES} uuid Xtst X11 ${CURL_LIBS} ${MAGIC_LIBRARIES} ${CMAKE_REQUIRED_LIBRARIES})
 endif()
 
 if (IPO_SUPPORTED)
--- a/src/ui/wxWidgets/AboutDlg.cpp
+++ b/src/ui/wxWidgets/AboutDlg.cpp
@@ -49,14 +49,20 @@ BEGIN_EVENT_TABLE( AboutDlg, wxDialog )
   EVT_HYPERLINK( ID_CHECKNEW     , AboutDlg::OnCheckNewClicked   )
   EVT_HYPERLINK( ID_SITEHYPERLINK, AboutDlg::OnVisitSiteClicked  )
   EVT_BUTTON(    wxID_CLOSE      , AboutDlg::OnCloseClick        )
+#ifndef NO_VERCHECK
   EVT_THREAD(    wxID_ANY        , AboutDlg::OnDownloadCompleted )
+#endif
 
 END_EVENT_TABLE()
 
+#ifndef NO_VERCHECK
 wxString AboutDlg::s_VersionData = wxEmptyString;
-
-const wstringT AboutDlg::s_URL_HOME      = L"https://pwsafe.org";
 const cstringT AboutDlg::s_URL_VERSION   =  "https://pwsafe.org/latest.xml";
+#else
+const cstringT AboutDlg::s_URL_VERSION   =  "https://pwsafe.org/news.shtml";
+#endif
+
+const wstringT AboutDlg::s_URL_HOME      =  L"https://pwsafe.org";
 
 /*!
  * AboutDlg constructors
@@ -73,8 +79,12 @@ AboutDlg::AboutDlg( wxWindow* parent, wx
   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().wc_str());
+#endif
+#ifndef NO_VERCHECK
   pws_os::Trace(GetLibCurlVersion().wc_str());
+#endif
 }
 
 /*!
@@ -117,8 +127,10 @@ AboutDlg::~AboutDlg()
 
 void AboutDlg::Init()
 {
+#ifndef NO_VERCHECK
   m_VersionStatus = nullptr;
   m_CurlHandle = nullptr;
+#endif // NO_VERCHECK
 }
 
 /*!
@@ -174,9 +186,11 @@ void AboutDlg::CreateControls()
   wxStaticText* copyrightStaticText = new wxStaticText(aboutDialog, wxID_STATIC, _("Copyright (c) 2003-2020 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);
@@ -229,7 +243,9 @@ wxIcon AboutDlg::GetIconResource( const
 
 void AboutDlg::OnCloseWindow( wxCloseEvent& WXUNUSED(event) )
 {
+#ifndef NO_VERCHECK
   Cleanup();
+#endif // NO_VERCHECK
   EndModal(wxID_CLOSE);
 }
 
@@ -239,10 +255,13 @@ void AboutDlg::OnCloseWindow( wxCloseEve
 
 void AboutDlg::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
@@ -407,14 +426,6 @@ wxString AboutDlg::GetLibCurlVersion()
 }
 
 /**
- * Provides version information about wxWidgets framework.
- */
-wxString AboutDlg::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.
@@ -698,6 +709,17 @@ void AboutDlg::OnDownloadCompleted(wxThr
     s_VersionData.Empty();
   }
 }
+#endif // NO_VERCHECK
+
+#if defined(_DEBUG) || defined(DEBUG)
+/**
+ * Provides version information about wxWidgets framework.
+ */
+wxString AboutDlg::GetLibWxVersion()
+{
+  return wxString::Format("[wx] Wx Version:\n%s\n", wxGetLibraryVersionInfo().ToString());
+}
+#endif // debug
 
 /**
  * wxEVT_HYPERLINK event handler for ID_SITEHYPERLINK
@@ -705,3 +727,14 @@ void AboutDlg::OnDownloadCompleted(wxThr
 void AboutDlg::OnVisitSiteClicked(wxHyperlinkEvent& WXUNUSED(event)) {
   wxLaunchDefaultBrowser(s_URL_HOME);
 }
+
+/**
+ * wxEVT_HYPERLINK event handler for ID_CHECKNEW
+ */
+void AboutDlg::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=QRCodeDlg.cpp QREncode.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 -lmagic -l$(YBPERS_LIBS) ${LIBCXX_LD_EXTRA_FLAGS}
+LIBS=`$(WX_CONFIG) --debug=yes --unicode=no --libs` -lcore -los -lcore -luuid -lXtst -lX11 $(CURL_LDFLAGS) -lmagic -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 -lmagic -l$(YBPERS_LIBS)
+LIBS=`$(WX_CONFIG) --debug=no --unicode=no --inplace --libs` -lcore -los -lcore -luuid -lXtst -lX11 $(CURL_LDFLAGS) -lmagic -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 -lmagic
+		LIBS += -luuid -lXtst -lX11 $(CURL_LDFLAGS) -lmagic
 		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 -lmagic
+		LIBS += -luuid -lXtst -lX11 $(CURL_LDFLAGS) -lmagic
 		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 SafeCombinationEntryDlg.cpp \
--- a/src/ui/wxWidgets/AboutDlg.h
+++ b/src/ui/wxWidgets/AboutDlg.h
@@ -20,11 +20,12 @@
 ////@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>
+
 #ifndef __WINDOWS__
 #define HAS_CURL
 #endif // !__WINDOWS__
@@ -33,6 +34,10 @@
 #include <curl/curl.h>
 #endif // HAS_CURL
 
+#endif // NO_VERCHECK
+////@end includes
+
+
 /*!
  * Forward declarations
  */
@@ -61,22 +66,31 @@
  * AboutDlg class declaration
  */
 
-class AboutDlg : public wxDialog, public wxThreadHelper
+class AboutDlg : public wxDialog
+#ifndef NO_VERCHECK
+              , public wxThreadHelper
+#endif // NO_VERCHECK
 {
   DECLARE_CLASS( AboutDlg )
   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
@@ -95,12 +109,14 @@ public:
   /// Creates the controls and sizers
   void CreateControls();
 
+#ifndef NO_VERCHECK
   void CheckNewVersion();
+#endif // NO_VERCHECK
 
 ////@begin AboutDlg event handler declarations
 
   /// event handler for ID_CHECKNEW
-  void OnCheckNewClicked(wxHyperlinkEvent& WXUNUSED(event)) { CheckNewVersion(); }
+  void OnCheckNewClicked(wxHyperlinkEvent& WXUNUSED(event));
 
   /// event handler for ID_SITEHYPERLINK
   void OnVisitSiteClicked(wxHyperlinkEvent& event);
@@ -111,8 +127,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 AboutDlg event handler declarations
 
 ////@begin AboutDlg member function declarations
@@ -128,9 +147,11 @@ public:
   static bool ShowToolTips();
 
 private:
+#ifndef NO_VERCHECK
 ////@begin AboutDlg member variables
   wxTextCtrl* m_VersionStatus;
 ////@end AboutDlg member variables
+#endif
 
   /// The CURL handle with connection specific options for request of version data
 #ifdef HAS_CURL
@@ -139,8 +160,10 @@ private:
   void *m_CurlHandle;
 #endif // HAS_CURL
 
+#ifndef NO_VERCHECK
   /// Set to downloaded data by worker thread, resp. WriteCallback, and read by main thread for final version check
   static wxString s_VersionData;
+#endif
 
   static const wstringT s_URL_HOME;
   static const cstringT s_URL_VERSION;
