Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/impl/networkmanager/accesspointproxynm.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -18,6 +18,7 @@ AccessPointProxyNM::AccessPointProxyNM(NetworkManager::WirelessDevice::Ptr devic
, m_strength(0)
, m_secured(false)
{
updateSsid();
initState();
initConnection();
updateInfo();
Expand All @@ -40,6 +41,7 @@ void AccessPointProxyNM::updateStatus(ConnectionStatus status)
void AccessPointProxyNM::updateNetwork(NetworkManager::WirelessNetwork::Ptr network)
{
m_network = network;
updateSsid();
}

bool AccessPointProxyNM::contains(const QString &uni) const
Expand All @@ -57,7 +59,7 @@ bool AccessPointProxyNM::contains(const QString &uni) const

QString AccessPointProxyNM::ssid() const
{
return m_network->ssid();
return m_ssid;
}

int AccessPointProxyNM::strength() const
Expand Down Expand Up @@ -134,7 +136,7 @@ void AccessPointProxyNM::initState()
if (wirelessSetting.isNull())
return;

if (wirelessSetting->ssid() != m_network->ssid())
if (wirelessSetting->ssid() != ssid())
return;

updateStatus(convertStateFromNetworkManager(activeConnection->state()));
Expand Down Expand Up @@ -181,7 +183,7 @@ void AccessPointProxyNM::updateHiddenInfo()
if (wirelessSetting.isNull())
return false;

return wirelessSetting->ssid() == m_network->ssid();
return wirelessSetting->ssid() == ssid();
});
// 如果没有找到连接,就是非隐藏网络
if (itConnection == connections.end())
Expand All @@ -195,6 +197,11 @@ void AccessPointProxyNM::updateHiddenInfo()
qCDebug(DNC) << "update accesspoint hidden info, ssid:" << m_isHidden << ", hidden:" << m_isHidden;
}

void AccessPointProxyNM::updateSsid()
{
m_ssid = (m_network && m_network->referenceAccessPoint()) ? decodeByteArray(m_network->referenceAccessPoint()->rawSsid()) : QString();
}

void AccessPointProxyNM::onUpdateNetwork()
{
int strength = m_strength;
Expand Down
4 changes: 3 additions & 1 deletion src/impl/networkmanager/accesspointproxynm.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -47,14 +47,16 @@
void updateInfo();
void updateConnection();
void updateHiddenInfo();
void updateSsid();

private slots:

Check warning on line 52 in src/impl/networkmanager/accesspointproxynm.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void onUpdateNetwork();

private:
NetworkManager::WirelessDevice::Ptr m_device;
NetworkManager::WirelessNetwork::Ptr m_network;
ConnectionStatus m_status;
QString m_ssid;
bool m_isHidden;
int m_strength;
bool m_secured;
Expand Down
5 changes: 3 additions & 2 deletions src/impl/networkmanager/devicemanagerrealize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ QString WirelessDeviceManagerRealize::activeAp() const
NetworkManager::WirelessDevice::Ptr wirelessDevice = m_device.staticCast<NetworkManager::WirelessDevice>();
NetworkManager::AccessPoint::Ptr ap = wirelessDevice->activeAccessPoint();
if (ap)
return ap->ssid();
return decodeByteArray(ap->rawSsid());

return QString();
}
Expand Down Expand Up @@ -1081,7 +1081,8 @@ bool WirelessDeviceManagerRealize::hotspotEnabled()
void WirelessDeviceManagerRealize::addNetwork(const NetworkManager::WirelessNetwork::Ptr &network)
{
// 在当前的网络列表中查找同名SSID的网络,如果查找到了,就更新数据,没有查找到,就新增一条网络
QList<AccessPointInfo *>::iterator itApInfo = std::find_if(m_accessPointInfos.begin(), m_accessPointInfos.end(), [ network ](AccessPointInfo *accessPoint) { return accessPoint->accessPoint()->ssid() == network->ssid(); });
QString ssid = decodeByteArray(network->referenceAccessPoint()->rawSsid());
QList<AccessPointInfo *>::iterator itApInfo = std::find_if(m_accessPointInfos.begin(), m_accessPointInfos.end(), [ ssid ](AccessPointInfo *accessPoint) { return accessPoint->accessPoint()->ssid() == ssid; });
if (itApInfo == m_accessPointInfos.end()) {
// 新增的无线网络
AccessPointInfo *apInfo = new AccessPointInfo(m_device, network);
Expand Down
5 changes: 3 additions & 2 deletions src/impl/networkmanager/networkdetailnmrealize.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "networkdetailnmrealize.h"
#include "devicemanagerrealize.h"
#include "ipmanager.h"
#include "netutils.h"

Check warning on line 7 in src/impl/networkmanager/networkdetailnmrealize.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "netutils.h" not found.

#include <NetworkManagerQt/WirelessDevice>

Check warning on line 9 in src/impl/networkmanager/networkdetailnmrealize.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <NetworkManagerQt/WirelessDevice> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <NetworkManagerQt/WirelessSecuritySetting>

Check warning on line 10 in src/impl/networkmanager/networkdetailnmrealize.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <NetworkManagerQt/WirelessSecuritySetting> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <NetworkManagerQt/Security8021xSetting>
#include <NetworkManagerQt/VpnSetting>
#include <NetworkManagerQt/Utils>
Expand Down Expand Up @@ -61,7 +62,7 @@
QString frequencyBand = tr("automatic");
NetworkManager::AccessPoint::Ptr activeAccessPoint = wirelessDevice->activeAccessPoint();
if (activeAccessPoint) {
ssid = activeAccessPoint->ssid();
ssid = decodeByteArray(activeAccessPoint->rawSsid());
switch (NetworkManager::findFrequencyBand(static_cast<int>(activeAccessPoint->frequency()))) {
case NetworkManager::WirelessSetting::FrequencyBand::A:
frequencyBand = "5 GHz";
Expand Down
19 changes: 18 additions & 1 deletion src/netutils.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "netutils.h"

#include <QMetaType>

Check warning on line 7 in src/netutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMetaType> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDBusMetaType>

Check warning on line 8 in src/netutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDBusMetaType> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStringConverter>

Check warning on line 9 in src/netutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QStringConverter> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace dde {
namespace network {
Expand Down Expand Up @@ -75,5 +76,21 @@
return ConnectionStatus::Deactivated;
}

QString decodeByteArray(const QByteArray &data)
{
if (data.isEmpty()) {
return QString();
}

QStringDecoder utf8Decoder(QStringDecoder::Utf8);
QString utf8Result = utf8Decoder(data);
Comment on lines +85 to +86
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): UTF-8 validity check is done before decoding, which doesn’t reflect whether the input bytes are valid.

utf8Decoder.isValid() right after construction only reports that the codec exists, not that data is valid UTF‑8. To actually detect invalid input, you need to inspect the decoder after decoding (e.g., call isValid() after utf8Decoder(data) or use another Qt API for error reporting). As written, isValidUtf8 is effectively constant and doesn’t help detect bad input.

if (utf8Result.contains(QChar::ReplacementCharacter)) {
QStringDecoder gbkDecoder("GBK");
if (gbkDecoder.isValid()) {
return gbkDecoder.decode(data);
}
}
return utf8Result;
}
}
}
5 changes: 4 additions & 1 deletion src/netutils.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -36,6 +36,9 @@ Connectivity connectivityValue(uint sourceConnectivity);
DeviceStatus convertDeviceStatus(int sourceDeviceStatus);
ConnectionStatus convertConnectionStatus(int sourceConnectionStatus);
ConnectionStatus convertStateFromNetworkManager(NetworkManager::ActiveConnection::State state);

// 检测并转换 SSID 编码,处理 GBK 和 UTF-8 编码
QString decodeByteArray(const QByteArray &rawSsid);
}
}
#endif // NETUTILS_H
Loading