From 6205e7fb32473390b3461c7512b32f6cbad739b9 Mon Sep 17 00:00:00 2001 From: Hartmnt Date: Thu, 6 Oct 2022 15:08:49 +0000 Subject: [PATCH] FIX(client): Fixes link context menu creation for channels The commit 902fe5841ca03f59b introduced links in the log for users and channels. This either never worked correctly, or regressed due to an undocumented behavior change in Qt. The 'channelid' stored in the host part of a QUrl is automatically converted to an IP address (e.g. '1' -> '0.0.0.1') which lets the channel lookup fail. A different code path for clients was present, so the issue was not observed often (or at all) there. This commit changes the host part composition to contain a string (e.g. '1' -> 'id.1') and makes sure this new string is parsed correctly. Fixes #2961 --- src/mumble/Log.cpp | 4 ++-- src/mumble/MainWindow.cpp | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/mumble/Log.cpp b/src/mumble/Log.cpp index 161d0492a..330dba748 100644 --- a/src/mumble/Log.cpp +++ b/src/mumble/Log.cpp @@ -509,7 +509,7 @@ QString Log::msgColor(const QString &text, LogColorType t) { } QString Log::formatChannel(::Channel *c) { - return QString::fromLatin1("%2") + return QString::fromLatin1("%2") .arg(c->iId) .arg(c->qsName.toHtmlEscaped()) .arg(QString::fromLatin1(Global::get().sh->qbaDigest.toBase64())); @@ -539,7 +539,7 @@ QString Log::formatClientUser(ClientUser *cu, LogColorType t, const QString &dis if (cu) { QString name = (displayName.isNull() ? cu->qsName : displayName).toHtmlEscaped(); if (cu->qsHash.isEmpty()) { - return QString::fromLatin1("%3") + return QString::fromLatin1("%3") .arg(className) .arg(cu->uiSession) .arg(name) diff --git a/src/mumble/MainWindow.cpp b/src/mumble/MainWindow.cpp index 93fd921dd..47be29e12 100644 --- a/src/mumble/MainWindow.cpp +++ b/src/mumble/MainWindow.cpp @@ -829,6 +829,10 @@ ContextMenuTarget MainWindow::getContextMenuTargets() { } bool MainWindow::handleSpecialContextMenu(const QUrl &url, const QPoint &pos_, bool focus) { + // This method abuses QUrls for internal data serialization + // The protocol, host and path parts of the URL may contain + // special values which are only parsable by this method. + if (url.scheme() == QString::fromLatin1("clientid")) { bool ok = false; QString maybeUserHash(url.host()); @@ -839,8 +843,13 @@ bool MainWindow::handleSpecialContextMenu(const QUrl &url, const QPoint &pos_, b ok = true; } } else { + // We expect the host part of the URL to contain the user id in the format + // id. + // where is the user id as integer. This is necessary, because QUrl parses + // plain integers in the host field as IP addresses QByteArray qbaServerDigest = QByteArray::fromBase64(url.path().remove(0, 1).toLatin1()); - cuContextUser = ClientUser::get(url.host().toInt(&ok, 10)); + QString id = url.host().split(".").value(1, "-1"); + cuContextUser = ClientUser::get(id.toInt(&ok, 10)); ServerHandlerPtr sh = Global::get().sh; ok = ok && sh && (qbaServerDigest == sh->qbaDigest); } @@ -855,9 +864,14 @@ bool MainWindow::handleSpecialContextMenu(const QUrl &url, const QPoint &pos_, b } cuContextUser.clear(); } else if (url.scheme() == QString::fromLatin1("channelid")) { + // We expect the host part of the URL to contain the channel id in the format + // id. + // where is the channel id as integer. This is necessary, because QUrl parses + // plain integers in the host field as IP addresses bool ok; QByteArray qbaServerDigest = QByteArray::fromBase64(url.path().remove(0, 1).toLatin1()); - cContextChannel = Channel::get(url.host().toInt(&ok, 10)); + QString id = url.host().split(".").value(1, "-1"); + cContextChannel = Channel::get(id.toInt(&ok, 10)); ServerHandlerPtr sh = Global::get().sh; ok = ok && sh && (qbaServerDigest == sh->qbaDigest); if (ok) {