monitor network devices and reconfigure upnp server
This commit is contained in:
parent
123536f9f3
commit
4e7238578c
@ -52,6 +52,8 @@
|
|||||||
#include <QNetworkInterface>
|
#include <QNetworkInterface>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
#include <QXmlStreamWriter>
|
#include <QXmlStreamWriter>
|
||||||
|
#include <QNetworkConfiguration>
|
||||||
|
#include <QNetworkConfigurationManager>
|
||||||
|
|
||||||
namespace nymeaserver {
|
namespace nymeaserver {
|
||||||
|
|
||||||
@ -65,6 +67,11 @@ UpnpDiscoveryImplementation::UpnpDiscoveryImplementation(QNetworkAccessManager *
|
|||||||
m_notificationTimer->setSingleShot(false);
|
m_notificationTimer->setSingleShot(false);
|
||||||
connect(m_notificationTimer, &QTimer::timeout, this, &UpnpDiscoveryImplementation::notificationTimeout);
|
connect(m_notificationTimer, &QTimer::timeout, this, &UpnpDiscoveryImplementation::notificationTimeout);
|
||||||
|
|
||||||
|
QNetworkConfigurationManager *configManager = new QNetworkConfigurationManager(this);
|
||||||
|
connect(configManager, &QNetworkConfigurationManager::configurationAdded, this, &UpnpDiscoveryImplementation::networkConfigurationChanged);
|
||||||
|
connect(configManager, &QNetworkConfigurationManager::configurationRemoved, this, &UpnpDiscoveryImplementation::networkConfigurationChanged);
|
||||||
|
connect(configManager, &QNetworkConfigurationManager::configurationChanged, this, &UpnpDiscoveryImplementation::networkConfigurationChanged);
|
||||||
|
|
||||||
m_available = true;
|
m_available = true;
|
||||||
|
|
||||||
qCDebug(dcHardware()) << "-->" << name() << "created successfully.";
|
qCDebug(dcHardware()) << "-->" << name() << "created successfully.";
|
||||||
@ -168,7 +175,7 @@ void UpnpDiscoveryImplementation::respondToSearchRequest(QHostAddress host, int
|
|||||||
"USN:uuid:" + uuid + "::urn:schemas-upnp-org:device:Basic:1\r\n"
|
"USN:uuid:" + uuid + "::urn:schemas-upnp-org:device:Basic:1\r\n"
|
||||||
"\r\n");
|
"\r\n");
|
||||||
|
|
||||||
//qCDebug(dcHardware) << QString("Sending response to %1:%2\n").arg(host.toString()).arg(port);
|
qCDebug(dcUpnp()) << QString("Sending response to %1:%2").arg(host.toString()).arg(port);
|
||||||
m_socket->writeDatagram(rootdeviceResponseMessage, host, port);
|
m_socket->writeDatagram(rootdeviceResponseMessage, host, port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,6 +207,7 @@ void UpnpDiscoveryImplementation::setEnabled(bool enabled)
|
|||||||
if (m_enabled == enabled)
|
if (m_enabled == enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
qCDebug(dcUpnp()) << "Enabling UPnP server";
|
||||||
m_enabled = enabled;
|
m_enabled = enabled;
|
||||||
emit enabledChanged(m_enabled);
|
emit enabledChanged(m_enabled);
|
||||||
|
|
||||||
@ -230,6 +238,7 @@ void UpnpDiscoveryImplementation::readData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data.contains("M-SEARCH") && !QNetworkInterface::allAddresses().contains(hostAddress)) {
|
if (data.contains("M-SEARCH") && !QNetworkInterface::allAddresses().contains(hostAddress)) {
|
||||||
|
qCDebug(dcUpnp()) << "UPnP discovery request received";
|
||||||
respondToSearchRequest(hostAddress, port);
|
respondToSearchRequest(hostAddress, port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -455,6 +464,15 @@ void UpnpDiscoveryImplementation::discoverTimeout()
|
|||||||
delete discoveryRequest;
|
delete discoveryRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UpnpDiscoveryImplementation::networkConfigurationChanged(const QNetworkConfiguration &config)
|
||||||
|
{
|
||||||
|
Q_UNUSED(config)
|
||||||
|
if (m_enabled) {
|
||||||
|
disable();
|
||||||
|
enable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool UpnpDiscoveryImplementation::enable()
|
bool UpnpDiscoveryImplementation::enable()
|
||||||
{
|
{
|
||||||
// Clean up
|
// Clean up
|
||||||
@ -506,6 +524,9 @@ bool UpnpDiscoveryImplementation::enable()
|
|||||||
|
|
||||||
bool UpnpDiscoveryImplementation::disable()
|
bool UpnpDiscoveryImplementation::disable()
|
||||||
{
|
{
|
||||||
|
if (!m_socket) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
sendByeByeMessage();
|
sendByeByeMessage();
|
||||||
m_socket->waitForBytesWritten();
|
m_socket->waitForBytesWritten();
|
||||||
m_socket->close();
|
m_socket->close();
|
||||||
|
|||||||
@ -86,6 +86,8 @@ private slots:
|
|||||||
void sendAliveMessage();
|
void sendAliveMessage();
|
||||||
void discoverTimeout();
|
void discoverTimeout();
|
||||||
|
|
||||||
|
void networkConfigurationChanged(const QNetworkConfiguration &config);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool enable();
|
bool enable();
|
||||||
bool disable();
|
bool disable();
|
||||||
|
|||||||
@ -48,9 +48,6 @@ ServerManager::ServerManager(NymeaConfiguration *configuration, QObject *parent)
|
|||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_sslConfiguration(QSslConfiguration())
|
m_sslConfiguration(QSslConfiguration())
|
||||||
{
|
{
|
||||||
// TODO: check this
|
|
||||||
|
|
||||||
|
|
||||||
if (!QSslSocket::supportsSsl()) {
|
if (!QSslSocket::supportsSsl()) {
|
||||||
qCWarning(dcConnection) << "SSL is not supported/installed on this platform.";
|
qCWarning(dcConnection) << "SSL is not supported/installed on this platform.";
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user