From c13943bfbb90777dbec94a7262b55e2c7a3a9eec Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 1 Nov 2021 09:51:50 +0000 Subject: [PATCH] Fix for 1028 - allow API to bind to any address --- sdrbase/mainparser.cpp | 28 +++++++++++++++------------- sdrgui/mainwindow.cpp | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/sdrbase/mainparser.cpp b/sdrbase/mainparser.cpp index 76759e360..ef3cf48b2 100644 --- a/sdrbase/mainparser.cpp +++ b/sdrbase/mainparser.cpp @@ -26,7 +26,7 @@ MainParser::MainParser() : m_serverAddressOption(QStringList() << "a" << "api-address", "Web API server address.", "address", - "127.0.0.1"), + ""), m_serverPortOption(QStringList() << "p" << "api-port", "Web API server port.", "port", @@ -36,7 +36,7 @@ MainParser::MainParser() : "file", "") { - m_serverAddress = "127.0.0.1"; + m_serverAddress = ""; // Bind to any address m_serverPort = 8091; m_mimoSupport = false; m_fftwfWindowFileName = ""; @@ -63,18 +63,20 @@ void MainParser::parse(const QCoreApplication& app) // server address QString serverAddress = m_parser.value(m_serverAddressOption); + if (!serverAddress.isEmpty()) + { + QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"; + QRegExp ipRegex ("^" + ipRange + + "\\." + ipRange + + "\\." + ipRange + + "\\." + ipRange + "$"); + QRegExpValidator ipValidator(ipRegex); - QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])"; - QRegExp ipRegex ("^" + ipRange - + "\\." + ipRange - + "\\." + ipRange - + "\\." + ipRange + "$"); - QRegExpValidator ipValidator(ipRegex); - - if (ipValidator.validate(serverAddress, pos) == QValidator::Acceptable) { - m_serverAddress = serverAddress; - } else { - qWarning() << "MainParser::parse: server address invalid. Defaulting to " << m_serverAddress; + if (ipValidator.validate(serverAddress, pos) == QValidator::Acceptable) { + m_serverAddress = serverAddress; + } else { + qWarning() << "MainParser::parse: server address invalid. Defaulting to any address."; + } } // server port diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index d6a471ce9..e776b6c5e 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -2191,7 +2191,7 @@ void MainWindow::deleteFeature(int featureSetIndex, int featureIndex) void MainWindow::on_action_About_triggered() { - AboutDialog dlg(m_apiHost, m_apiPort, m_mainCore->m_settings, this); + AboutDialog dlg(m_apiHost.isEmpty() ? "127.0.0.1" : m_apiHost, m_apiPort, m_mainCore->m_settings, this); dlg.exec(); }