From 1ecfc5210d4a356d30ac870992c78b100d82301a Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Wed, 12 Aug 2026 19:24:48 +0000
Subject: [PATCH] Qt4: fix QUrl::url(), Q_OS_MACOS, and seeded qHash()

Three issues in vpninfo.cpp, plus one latent (non-build-breaking)
regression in main.cpp found while fixing the same root cause there:

- QUrl::url() doesn't exist on this Qt4; toString() is the universal
  equivalent, available on every Qt version.
- Q_OS_OSX (Qt5.0+) isn't defined on Qt4, which tripped the vpninfo.cpp
  platform-name #error fallback and left `osName` undeclared. Qt4 only
  defines Q_OS_MAC (still defined on every later Qt version too), so
  check for Q_OS_MACOS || Q_OS_OSX || Q_OS_MAC.
- The same Q_OS_MACOS-without-a-Q_OS_MAC-fallback pattern was already
  present in main.cpp, guarding the root-privilege re-exec logic
  (relaunch_as_root() and friends). That one doesn't fail to build --
  it just silently compiles out under Qt4, meaning the app would never
  try to relaunch itself as root, and VPN tunnel setup (which needs
  root) would fail at runtime instead. Fixed the same way.
- qHash(key, seed) -- the seeded 2-arg overload -- was added in Qt5;
  Qt4 only has the 1-arg form. Dropped the explicit seed of 0, which is
  the default anyway, so this is a no-op on Qt5/6 too.
---
 src/main.cpp    | 12 +++++++++---
 src/vpninfo.cpp | 12 +++++++++---
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/main.cpp b/src/main.cpp
index a2a212d..349cd89 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -57,7 +57,9 @@ static void log_callback(int level, const char* str)
         Logger::ComponentType::GNUTLS);
 }
 
-#if defined(Q_OS_MACOS) && defined(PROJ_ADMIN_PRIV_ELEVATION)
+/* Q_OS_MACOS (Qt 5.9+) doesn't exist on Qt4, which only defines
+ * Q_OS_MAC (also still defined on every later Qt version). */
+#if (defined(Q_OS_MACOS) || defined(Q_OS_MAC)) && defined(PROJ_ADMIN_PRIV_ELEVATION)
 bool relaunch_as_root()
 {
     QMessageBox msgBox;
@@ -165,7 +167,9 @@ int main(int argc, char* argv[])
 
     qRegisterMetaType<Logger::Message>();
 
-#if defined(Q_OS_MACOS) && defined(PROJ_ADMIN_PRIV_ELEVATION)
+/* Q_OS_MACOS (Qt 5.9+) doesn't exist on Qt4, which only defines
+ * Q_OS_MAC (also still defined on every later Qt version). */
+#if (defined(Q_OS_MACOS) || defined(Q_OS_MAC)) && defined(PROJ_ADMIN_PRIV_ELEVATION)
     /* Re-launching with root privs on OS X needs Qt to allow setsuid */
     QApplication::setSetuidAllowed(true);
 #endif
@@ -194,7 +198,9 @@ int main(int argc, char* argv[])
         haveTray=true;
     }
 
-#if defined(Q_OS_MACOS) && defined(PROJ_ADMIN_PRIV_ELEVATION)
+/* Q_OS_MACOS (Qt 5.9+) doesn't exist on Qt4, which only defines
+ * Q_OS_MAC (also still defined on every later Qt version). */
+#if (defined(Q_OS_MACOS) || defined(Q_OS_MAC)) && defined(PROJ_ADMIN_PRIV_ELEVATION)
     if (geteuid() != 0) {
         if (relaunch_as_root()) {
             /* We have re-launched with root privs. Exit this process. */
diff --git a/src/vpninfo.cpp b/src/vpninfo.cpp
index 7f8439e..7e01b51 100644
--- a/src/vpninfo.cpp
+++ b/src/vpninfo.cpp
@@ -505,7 +505,7 @@ void VpnInfo::setUrl(const QUrl& url)
         mUrl.setScheme(QLatin1String("https"));
     }
 
-    openconnect_parse_url(this->vpninfo, mUrl.url().toUtf8().constData());
+    openconnect_parse_url(this->vpninfo, mUrl.toString().toUtf8().constData());
 }
 
 int VpnInfo::connect()
@@ -542,7 +542,10 @@ int VpnInfo::connect()
 
 #ifdef Q_OS_WIN32
     const QString osName{ "win" };
-#elif defined Q_OS_OSX
+#elif defined Q_OS_MACOS || defined Q_OS_OSX || defined Q_OS_MAC
+    /* Q_OS_MACOS (Qt 5.9+) and Q_OS_OSX (Qt5.0-5.8) don't exist on Qt4,
+     * which only defines Q_OS_MAC (also still defined on every later
+     * Qt version, so this covers all of them). */
     const QString osName{ "mac-intel" };
 #elif defined Q_OS_LINUX
     const QString osName = QString("linux%1").arg(sizeof(void*) == 4 ? "" : "-64").toStdString().c_str();
@@ -715,7 +718,10 @@ void VpnInfo::logVpncScriptOutput()
 QByteArray VpnInfo::generateUniqueInterfaceName()
 {
     //generate a hash from server_gateway (as input) and username
-    size_t uhash = qHash(this->ss->get_server_gateway() + this->ss->get_username(), 0);
+    /* the seeded 2-arg qHash() overload was added in Qt5; Qt4 only has
+     * the 1-arg form, which is what an explicit seed of 0 amounts to
+     * anyway. */
+    size_t uhash = qHash(this->ss->get_server_gateway() + this->ss->get_username());
     QString hash = QString::number(uhash, 16);
     QString host = mUrl.host();
 
-- 
2.43.0

