Fixed virtualmonitorplugin url generation

BUG: 485830

The current implementation of the plugin is severly broken.

1. The generated URL links to the localhost
2. The port is not set

-----

The URL is now generated on the request receiving side, not send in the request.
This allows finding a valid IP address.

Furthermore, I changed the protocol by splitting it up. This could become useful, if we ever want to support other rdp protocols/platforms.

Note: This is a breaking change, but the current implementation is not working at all.. so it does not actually break something.
This commit is contained in:
Fabian Arndt 2024-04-28 14:14:26 +00:00 committed by Aleix Pol Gonzalez
parent 527b7b2835
commit 2716a7a2e6

View file

@ -18,6 +18,7 @@
K_PLUGIN_CLASS_WITH_JSON(VirtualMonitorPlugin, "kdeconnect_virtualmonitor.json") K_PLUGIN_CLASS_WITH_JSON(VirtualMonitorPlugin, "kdeconnect_virtualmonitor.json")
#define QS QLatin1String #define QS QLatin1String
static const int DEFAULT_PORT = 5901;
VirtualMonitorPlugin::~VirtualMonitorPlugin() VirtualMonitorPlugin::~VirtualMonitorPlugin()
{ {
@ -56,8 +57,29 @@ void VirtualMonitorPlugin::connected()
void VirtualMonitorPlugin::receivePacket(const NetworkPacket &received) void VirtualMonitorPlugin::receivePacket(const NetworkPacket &received)
{ {
if (received.type() == PACKET_TYPE_VIRTUALMONITOR_REQUEST && received.has(QS("url"))) { if (received.type() == PACKET_TYPE_VIRTUALMONITOR_REQUEST) {
QUrl url(received.get<QString>(QS("url"))); // At least a password is necessary, we have defaults for all other parameters
if (!received.has(QS("password"))) {
qCWarning(KDECONNECT_PLUGIN_VIRTUALMONITOR) << "Request invalid, missing password";
return;
}
// Try to get the IP address of the paired device
QHostAddress addr = device()->getLocalIpAddress();
if (addr == QHostAddress::Null) {
qCWarning(KDECONNECT_PLUGIN_VIRTUALMONITOR) << "Device doesn't have a LanDeviceLink, unable to get IP address";
return;
}
QUrl url;
url.setScheme(received.get<QString>(QS("protocol"), QS("vnc")));
url.setUserName(received.get<QString>(QS("username"), QS("user")));
url.setPassword(received.get<QString>(QS("password")));
url.setPort(received.get<int>(QS("port"), DEFAULT_PORT));
url.setHost(addr.toString());
qCInfo(KDECONNECT_PLUGIN_VIRTUALMONITOR) << "Received request, try connecting to" << url.toDisplayString();
if (!QDesktopServices::openUrl(url)) { if (!QDesktopServices::openUrl(url)) {
qCWarning(KDECONNECT_PLUGIN_VIRTUALMONITOR) << "Failed to open" << url.toDisplayString(); qCWarning(KDECONNECT_PLUGIN_VIRTUALMONITOR) << "Failed to open" << url.toDisplayString();
NetworkPacket np(PACKET_TYPE_VIRTUALMONITOR, {{QS("failed"), 0}}); NetworkPacket np(PACKET_TYPE_VIRTUALMONITOR, {{QS("failed"), 0}});
@ -93,7 +115,7 @@ bool VirtualMonitorPlugin::requestVirtualMonitor()
qCDebug(KDECONNECT_PLUGIN_VIRTUALMONITOR) << "Requesting virtual display " << device()->name(); qCDebug(KDECONNECT_PLUGIN_VIRTUALMONITOR) << "Requesting virtual display " << device()->name();
QUuid uuid = QUuid::createUuid(); QUuid uuid = QUuid::createUuid();
static int s_port = 5901; static int s_port = DEFAULT_PORT;
const QString port = QString::number(s_port++); const QString port = QString::number(s_port++);
m_process = new QProcess(this); m_process = new QProcess(this);
@ -128,13 +150,11 @@ bool VirtualMonitorPlugin::requestVirtualMonitor()
return false; return false;
} }
QUrl url; NetworkPacket np(PACKET_TYPE_VIRTUALMONITOR_REQUEST);
url.setScheme(QS("vnc")); np.set(QS("protocol"), QS("vnc"));
url.setUserName(QS("user")); np.set(QS("username"), QS("user"));
url.setPassword(uuid.toString()); np.set(QS("password"), uuid.toString());
url.setHost(device()->getLocalIpAddress().toString()); np.set(QS("port"), port);
NetworkPacket np(PACKET_TYPE_VIRTUALMONITOR_REQUEST, {{QS("url"), url.toEncoded()}});
sendPacket(np); sendPacket(np);
return true; return true;
} }