Commit graph

675 commits

Author SHA1 Message Date
Alexander Lohnau
83888412a9 Simplify and optimize some string usages
- Using QLatin1String when concatinating strings is faster, because they
  are more lightweight. For the resulting string, we need to allocate
  new memory anyway
- Use QLatin1String overloads where they are provided by Qt APIs
- Just use const char* for log messages, the quoting of QStrings is not
  needed
- Make sure to reuse string results when possible
2023-08-05 20:22:18 +00:00
Albert Vaca Cintora
21b245cd71 Avoid starting more than 1 connection to the same device
Since we close old connections when a new connection is received, due to
race conditions we could end up without a valid connection in this case.

Equivalent to https://invent.kde.org/network/kdeconnect-android/-/merge_requests/382
2023-08-04 08:25:45 +00:00
Albert Vaca Cintora
abb6dfcc6e plugins: Add context-aware logging in case of errors
Also clean up some unneeded statements
2023-08-03 20:54:38 +02:00
Alexander Lohnau
1631ada5b3 Simplify KDEConnectPlugin::recievePacket
- We do not need the return type. If a plugin declares it can handle the
  packet it should do so. We don't have any fallback logic in place and
  the packet types are namespaced with the plugin IDs anyway.

- Provide a default implementation with a warning, not all plugins need
  to overwrite this
2023-08-03 20:49:44 +02:00
Alexander Lohnau
6300e9d0c6 Enable Qt6 CI 2023-07-31 06:39:08 +00:00
Alexander Lohnau
6fbecf28da Remove trailing / for KPluginMetaData::findPlugins
This is not needed and pretty much all usages of this method don't do it too
2023-07-31 06:39:08 +00:00
Alexander Lohnau
399d279e83 KDEConnectPluginConfig: Remove unneeded check for delete
Deleting a nullptr is a noop
2023-07-31 06:39:08 +00:00
Alexander Lohnau
b54f0e2467 Modernize plugin loading code
Use the new utility-methods and improve the logging.
2023-07-31 06:39:08 +00:00
Albert Vaca Cintora
b454a6f880 Fix memory leak due to m_receivedIdentityPackets growing
We didn't always remove entries from m_receivedIdentityPackets indexed
by sockets that got deleted.
2023-07-30 07:29:52 +00:00
Alexander Lohnau
2e67f95017 Add explicit moc includes to cpp files
The rationale is explained in https://planet.kde.org/friedrich-kossebau-2023-06-28-include-also-moc-files-of-headers/

In case of KDEConnect, it impressively speeds up compilation. Before it
took 390 seconds on a clean build and with this change it took 330 seconds.
This is due to the mocs_compilation having to include the header files
and thus all their headers. Due to the lots of small plugins we have,
this means that the same headers must be compiled plenty of times.
When we include the moc files directly in the C++ file, they are already
available.
2023-07-30 07:27:45 +00:00
Albert Vaca Cintora
70f6ebf6d5 Check for errors in KdeConnectConfig 2023-07-29 10:36:12 +02:00
Albert Vaca Cintora
675d1c1262 Make it compile and don't use .data() on temporary QByteArray 2023-07-29 10:36:12 +02:00
Edward Kigwana
20e7790773 core: sslhelper: Check return of openssl functions
Use unique_ptr to manage object lifetime and also avoid use of deprecated
MACROS and functions.
2023-07-29 10:36:09 +02:00
Edward Kigwana
1bbd9ff6e3 core: sslhelper: Extern openssl headers and add getSslError helper
openssl headers include C headers prior to #ifdef __cplusplus.

Signed-off-by: Edward Kigwana <ekigwana@gmail.com>
2023-07-29 10:35:37 +02:00
Albert Vaca Cintora
d0786d1b62 Simplify using QSslKey 2023-07-29 10:35:37 +02:00
Albert Vaca Cintora
d948d882aa Replace QCA with a simple OpenSSL wrapper 2023-07-29 08:19:17 +00:00
Albert Vaca Cintora
74e9cdbf12 Do not get deviceId by reference 2023-07-26 21:40:52 +02:00
Alexander Lohnau
a3fc5eaf9f Make optional bluetooth and MDNS build against KF6 too 2023-07-25 18:29:38 +02:00
Alexander Lohnau
e00ffbb4f6 Use versionless cmake variable for KF requirements
Also, adjust find_package calls that are hidden behind a feature flag
2023-07-25 18:29:38 +02:00
Alexander Lohnau
a1195a72a3 Use versionless Qt targets where possible
We depend on 5.15 which allows us to use those
2023-07-25 18:29:38 +02:00
Alexander Lohnau
98040c3ffe GIT_SILENT Re-run clang-format 2023-07-22 20:51:19 +00:00
Alexander Lohnau
f740a8bda8 Use target-centric CMake approach for declaring debug category
This makes it easier to read, because we do not have to handle a list of
files that get added to the targets. In other KDE projects, we also
prefer the target centric approach.

In case one wants to reuse the same category in multiple places, it
would be best to create a small static lib. But for now, this is not
needed.
2023-07-22 20:51:19 +00:00
Albert Vaca Cintora
dd4831f823 Add missing NOTIFY to properties 2023-07-22 20:09:46 +02:00
Alexander Lohnau
ac3d439a2a Clean up unneeded version checks
With the min. version bumped, those can be safely removed
2023-07-22 16:17:24 +02:00
Alexander Lohnau
1ee75463e0 Get rid of QOverload/static_cast for overloaded signals
By exclusing deprecated API in the KF5 build, the deprecated signal no
longer cause an ambiguity
2023-07-22 16:17:24 +02:00
Alexander Lohnau
e97af9dc15 Provide default implementation for KdeConnectPlugin::connected
In most plugins, we just provided a dummy implementation
2023-07-22 16:06:21 +02:00
Albert Vaca Cintora
32abeb8ed0 Fix typo causing us to intersect with the wrong set 2023-07-22 15:21:26 +02:00
Albert Vaca Cintora
6c1b81a384 Use nullptr instead of 0 2023-07-20 18:26:24 +02:00
Albert Vaca Cintora
382ace9c69 Remove check for Qt > 5.14 when minimum is 5.15 2023-07-20 18:23:45 +02:00
Albert Vaca Cintora
8c97e56f23 Remove duplicated target_link_libraries 2023-07-20 18:23:14 +02:00
Alexander Lohnau
e9063d168d LanLinkProvider: Restore previous network change behavior 2023-07-20 13:32:17 +03:00
Alexander Lohnau
1dadbd47b2 lanlinkprovider: Load backend explicitly to avoid nullptr warning
This is needed to make it work properly with Qt6 at runtime
2023-07-20 13:32:16 +03:00
Alexander Lohnau
5b5265f7a8 Port away from deprecated QtNetwork classes 2023-07-20 11:16:04 +03:00
Alexander Lohnau
b3163d8725 dbushelper: Use QRegularExpression instead of QRegExp
The pattern does not contain any wildcard specific text
2023-07-20 11:16:04 +03:00
Alexander Lohnau
042adebd0a Port to updeprecated KJob::processedAmountChanged signal 2023-07-20 11:16:04 +03:00
Alexander Lohnau
77f44ce943 Port away from deprecated QList::toSet and QSet::toList 2023-07-20 11:15:50 +03:00
Alexander Lohnau
52b6d57942 Qt6 build fixes in plugins and KCM 2023-07-20 11:15:46 +03:00
Alexander Lohnau
a9292f651f Port deprecated KPluginLoader usage 2023-07-20 11:15:46 +03:00
Alexander Lohnau
c5bfc4a5b0 Allow building against Qt6/KF6 2023-07-20 11:15:41 +03:00
Albert Vaca Cintora
495e3019e4 Reduce number of optional dependencies
Change some optional dependencies from being optional to being mandatory
or being mandatory but behind on-by-default cmake flags. Eg: instead of
only compiling Wayland support if we find the appropriate libraries, we
always require the libraries unless the user specifies WITH_WAYLAND=OFF.

Optional libraries are hard to discover by packagers (since they don't
see an error once we add them) and create lots of possible build flavors
with a different features that can confuse users.
2023-07-19 17:08:03 +00:00
Albert Vaca Cintora
22be63ae9e Remove compatibility with Qt < 5.15
In theory we support Qt 5.6 (because of SailfishOS) but in practice we are not checking that in the CI so probably we broke the compatibility long ago. Also, I don't think anyone is using this code in SailfishOS, so we can greatly simplify the code by requiring Qt 5.15 or later.
2023-07-18 20:13:27 +00:00
Albert Vaca Cintora
20750b7d99 Fixes from code review 2023-07-17 20:41:15 +00:00
Albert Vaca Cintora
bb8e67efc9 Add CMake flag to enable MDNS (off by default) 2023-07-17 20:41:15 +00:00
Albert Vaca Cintora
17dcf80f2d Send UDP identity packets without capabilities only if needed
Instead of always doing so on MacOS, do it only when we get a
DatagramTooLargeError. On MacOS, the size is limited only for
broadcast but not for unicast.
2023-07-17 20:41:15 +00:00
Albert Vaca Cintora
a04d9480a4 Add a way to disable UDP broadcasts for testing 2023-07-17 20:41:15 +00:00
Albert Vaca Cintora
34e0128fe9 Add MDNS discovery 2023-07-17 20:41:15 +00:00
Albert Vaca Cintora
f218c5f4e5 Fix windows build 2023-07-16 18:01:13 +02:00
Albert Vaca Cintora
9c87393b28 clang-format pass 2023-07-16 16:20:34 +02:00
Albert Vaca Cintora
af907cea83 Check for null devices in compositeuploadjob 2023-07-16 15:01:04 +02:00
Albert Vaca Cintora
12a1f33665 Fix crash when sending files 2023-07-16 14:44:31 +02:00
Albert Vaca Cintora
05f38b064d Fix Windows build when linking against current KF5
We need to link against WinSock2 because we use WSAIoctl to set keepalive
2023-07-12 23:10:24 +02:00
Albert Vaca Cintora
5796b561bf Simplify the code that reads from the socket line by line
Since sockets are buffered `QIODevices` we can use `canReadLine()` to check
if we have a full line, instead of using a custom `SocketLineReader` class
(and the copy-pasted `DeviceLineReader` in the Bluetooth backend). 

We can also loop through all the lines instead of queuing calls to `dataReceived`.

And we don't need transactions.
2023-07-10 15:58:56 +00:00
Albert Vaca Cintora
9fa07a2361 Call connected only once in the lifetime of a plugin 2023-06-29 09:01:31 +00:00
Albert Vaca Cintora
beb7e94cbb Cleanup 2023-06-27 13:15:11 +02:00
Albert Vaca Cintora
db546e7608 Add DeviceInfo class
Equivalent to this Android MR (see description there): https://invent.kde.org/network/kdeconnect-android/-/merge_requests/374
2023-06-27 11:10:59 +00:00
Albert Vaca Cintora
3018b3bf3d Connect to QUdpSocket's errorOcurred to make errors visible 2023-06-25 21:58:50 +02:00
Albert Vaca Cintora
3c36384078 Fix loopback link pairing timing out when already paired 2023-06-24 17:40:46 +02:00
Albert Vaca Cintora
46dd0c59da Remove unused priority() method 2023-06-22 23:46:44 +02:00
Albert Vaca Cintora
7ca8b7bf95 Fix infinite loop when already paired devices ask to pair 2023-06-16 19:49:50 +02:00
Albert Vaca Cintora
a56ff23770 Let Qt delete this when the parent is destroyed 2023-06-02 16:38:52 +00:00
Albert Vaca Cintora
fbaf5ade71 Remove unused name method 2023-06-02 16:38:52 +00:00
Albert Vaca Cintora
064ddfa3fe Refactor PairingHandler
We now have a single PairingHandler for all types of links.

The implementation now is more aligned with the one for Android.
2023-06-02 16:38:52 +00:00
Albert Vaca Cintora
571575df28 When receiving files, delay de-duplicating filenames
When receiving two files with the same name, the first file might not be
saved to disk already when we have to decide the name for the second if
we do it too early.

BUG: 470078
2023-05-25 22:54:17 +00:00
Ali Abdel-Qader
bbac0aa085 Use explicit constructor for QSslCertificate with value initialized
argument

Previously the BluetoothDeviceLink::certificate() method was returning a
value initialized object which I believe default initializes the object.
However, Clang throws a build error at this because QSslCertificate has
explicit constructors. This change uses one of those constructors and
uses value intialization to default construct/initialize the argument
for it. It fixes the build and hopefully doesn't break anything since
this is a TODO anyways!

BUG: 469428

Signed-off-by: Ali Abdel-Qader <abdelqaderali@protonmail.com>
2023-05-06 15:51:53 -04:00
Albert Vaca Cintora
81d6a12dfa Do not load the BigScreen plugin unless on a TV 2023-04-11 22:05:24 +00:00
Albert Vaca Cintora
6e2f218b55 Follow-up to my previous commit (fixes build) 2023-04-10 10:52:29 +02:00
Albert Vaca Cintora
74caaface0 Further KIO::AccessManager cleanup 2023-04-10 08:29:48 +00:00
Nicolas Fella
2c2e883288 Don't use KIO::AccessManager
The main thing it provides over QNetworkAccessManager is integration
with the CookieJar and using kio-http, but since we jsut exchange bytes
from another local device that's not interesting for us
2023-04-10 08:29:48 +00:00
Albert Vaca Cintora
87a608136f Remove check for a legacy field
Introduced in ee5bf89071
2023-03-23 17:03:58 +00:00
Albert Vaca Cintora
107dfb9e3d Remove specific list of ciphers
We can let the system use the full list when negotiating since we no longer
support Android < 5.0
2023-03-05 14:25:05 +00:00
Albert Vaca Cintora
20ede97ec4 Fix format 2023-03-04 23:44:39 +01:00
ValdikSS ValdikSS
bd796836c5 Enable socket Keep-Alive on Windows
Windows does not use setsockopt for keep-alive configuration,
requiring WSAIoctl call.

https://learn.microsoft.com/en-us/windows/win32/winsock/sio-keepalive-vals

BUG: 442790
BUG: 451597
2023-03-04 13:06:55 +00:00
Aleix Pol
804d17b67c Ensure openconfig.h is only included once
Addresses a warning by the compiler
2023-02-17 07:48:45 +00:00
Willyanto Willyanto
29f56dcc29 Perform initialization in initialization list
Fixes variable is assigned in constructor body. Consider performing
initialization in initialization list. (CWE-398)
2022-12-22 23:24:31 +07:00
Volker Krause
002848efa8 Adapt build system to also support Qt 6
This is complicated by the Qt 5.6 requirement of SailfishOS, hopefully
that didn't get broken by this.
2022-10-29 16:51:41 +02:00
ValdikSS ValdikSS
390a44a901 Really set source IP for broadcast discovery packets on Windows/FreeBSD
This whole code was no-op: it enumerates network interfaces, enumerates
its IP addresses, but does not change the address of broadcast UDP
packet, sending it only via default route/interface.

Bind the socket to IP addresses of the interfaces to fix the issue.

BUG: 459171
2022-10-17 22:21:46 +00:00
Simon Redman
8cfa308140 Fix some Qt and KF5 deprecation warnings
## Summary

Fixes a few warnings about deprecated fields and methods.

## Test Plan

Things still seem to be basically working 🤷
2022-10-17 21:17:49 +00:00
Nicolas Fella
a918ffc0cb Add and make use of ECM's clang-format integration 2022-09-11 23:21:58 +00:00
Kai Uwe Broulik
9c78fa0fff compositeuploadjob: Set total and processed files
This is the proper way to communicate progress.
It has Plasma show the file name in case of single files
and "n of m files" as before for multiple files.
2022-08-09 12:53:10 +02:00
Weixuan Xiao
e468759df4 Send broadcast on each LAN interfaces on FreeBSD
On FreeBSD 12 or later, a new routing strategy is introduced, which
prevents broadcast using 255.255.255.255.
Thus, we need to explicitly send the broadcast to each network 
interfaces.
Here the commit can simply reuse the code for Windows.

Ref: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252596
2022-07-19 10:14:35 +00:00
Weixuan Xiao
fd8b8078de Detect MTU on macOS and FreeBSD to adaptively reduce discovery packet
Detect the MTU on macOS and FreeBSD (which share the network parts of FreeBSD) and adaptively remove the outgoing and incoming capabilities.
The incoming capabilities are usually shorter, fit the size and help initialize the plugin list on the peer. This should fix an empty plugin list when the identity packet is sent by the macOS app.

If the MTU is still too short, both the capabilities need to be removed, which is not likely to happen.
2022-07-11 20:51:18 +00:00
Nicolas Fella
ad01ef1695 Fix activating existing settings window on Wayland
Add the necessary bits for XDG activation to work

Move the code for launching the settings from the daemon to the respective processes so that we don't need to pass activation tokens over another process boundary
2022-07-06 12:55:39 +00:00
Nicolas Fella
f7f3c01ec8 Use undeprecated install dirs
Using kde-dev-scripts/kf5/cmakelists_install_vars.pl
2022-04-21 00:50:14 +02:00
Weixuan Xiao
f1843cb492 Improve D-Bus implementation on macOS
Better patch to replace !218.

- Auto and quick detection of previous D-Bus instance;
- Remove private D-Bus compile definition, only use it on macOS without an existing D-Bus instance;
- Safe reboot after crashes because the indicator is not relating on the kdeconnectd to run a D-Bus session;
- Safe exit after clicking on `Quit` in the systray.


More details in commit logs:

Only enable private D-Bus on macOS because the other platforms do not
need them.
The app should be able to easily detect the session bus from the env
DBUS_LAUNCHD_SESSION_BUS_SOCKET from launchd through launchctl.
Because https://gitlab.freedesktop.org/dbus/dbus/-/blob/master/dbus/dbus-sysdeps-unix.c#L4392
shows that it is the only probing method on macOS with launchd.

The D-Bus session bus can be easily found from launchd/launchctl
with DBUS_LAUNCHD_SESSION_BUS_SOCKET env. It can be an external one
(installed from HomeBrew) or an internal one (launched by a previous
instance followed by a crash).

The indicator helper on macOS can now automatically detect whether we can use a potentially
(with launchd/launchctl env set, or KDE Connect macOS
private_bus_address set) existed and usable session bus.
If previous bus is usable, just try to launch the kdeconnectd with us.
Otherwise, launch a private D-Bus daemon, export the launchd/launchctl
env, and run a kdeconnectd instance.

Everything works better and quicker now :)
2022-04-12 05:40:03 +00:00
Méven Car
4e424b1bd5 Fix build error: invalid user-defined conversion from ‘QByteArray’ to ‘const char*’
NO_CHANGELOG
2021-11-24 10:22:42 +00:00
Laurent Montel
6957b6aa39 GIT_SILENT: add missing override 2021-10-27 06:53:06 +02:00
Vladimir Panteleev
b706750af8
Use device ID from client SSL certificate, not UDP packet
Consider the following scenario:

1. We send a UDP broadcast
2. We receive a reply from 192.168.0.1 with device ID "foo"
3. We connect to 192.168.0.1, and find that the device's certificate
   is actually for a different ID "bar". This could be because the
   packet did not actually originate from 192.168.0.1, or this host is
   malicious / malfunctioning.
4. We remember that device ID "foo" has certificate with common name "bar".
5. When we finally attempt to connect to the real device ID "foo", we
   reject their certificate (common name "foo"). We can now never
   successfully connect to "foo".

On some network (mis-)configurations, this completely prevents
kdeconnectd from connecting to any peers, because a reply which is
seen as originating from the local interface address will cause
kdeconnectd to immediately connect to itself and remember its own
certificate.

Address this by using the certificate display name of the peer, which
will match the real device ID.
2021-09-25 12:51:59 +00:00
Weixuan XIAO
664da445ee Empty capabilities in identity packet for UDP
To avoid incomplete UDP transmission on macOS
2021-07-04 19:13:21 +00:00
Aleix Pol
042fdd368a Fix warnings 2021-03-03 15:20:24 +01:00
Kai Uwe Broulik
8dae6772e0 Fix CompositeFileTransferJob speed calculation
The `QElapsedTimer` was never started. Clean it up somewhat and use a dedicated
250ms timer for reporting transferred bytes periodically (like KIO does it) and
1000ms for calculating speed so it's not as erratic.

Furthermore, report final numbers in `slotResult` rather than complicating
`slotProcessedAmount` for that.

Also, fix typo "send" -> "sent"
2021-01-31 23:50:14 +01:00
Kai Uwe Broulik
daa6f7fc14 Clean up FileTransferJob description
* Set magic `destUrl` property to let it know the job destination in case of
  multiple files being transferred
* Set a normal "Receiving File(s)" title like we do with "Copying" title
* Set device name and destination path as details
2021-01-31 22:22:36 +01:00
Nicolas Fella
9082ed4699 Fix build with bluetooth enabled
We need to implement this pure virtual method.

This is just a placeholder and lacks a proper implementation.
2020-11-30 20:11:47 +01:00
Albert Vaca Cintora
e7518493df Add a verification key that's displayed when pairing
The key is a sha256 of both devices' certificates. Both should generate the
same key, so hey user can check they are pairing against the right device.

Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
2020-11-26 11:28:49 +01:00
Nicolas Fella
1060c1a81a Add API for opening the KCM to daemon
We have a few places that open the KCM, with different arguments.

Centralize the implementation in one place.

This makes it easier to switch to invoking systemsettings5 in the future (once https://invent.kde.org/plasma/systemsettings/-/merge_requests/11 is in).

It also makes sure the relevant device is selected when clicking on a pairing notification.

The function is exposed to DBus for the Plasmoid and potential third-party users.

CCBUG: 425660
2020-10-18 18:40:48 +00:00
Albert Vaca Cintora
e05769e6de Fix initial set of devices not being emitted in dbus 2020-10-02 12:52:08 +02:00
Albert Vaca Cintora
bd27aec9d2 Do not replace connections for a given deviceId if the certs have changed
Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
2020-10-02 12:52:08 +02:00
Albert Vaca Cintora
ce0f00fc2d Limit the ports we try to connect to to the port range of KDE Connect
So we can't trigger connections to other services.

Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
2020-10-02 12:52:08 +02:00
Albert Vaca Cintora
613899be24 Do not remember more than a few identity packets at a time
To prevent the kdeconnect process from using too much memory.

Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
2020-10-02 12:52:08 +02:00
Albert Vaca Cintora
542d94a70c Limit number of connected sockets from unpaired devices
Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
2020-10-02 12:52:08 +02:00
Aleix Pol
8112729eb0 Don't brute-force reading the socket
The package will arrive eventually, and dataReceived will be emitted.
Otherwise we just end up calling dataReceived to no end.

Thanks Matthias Gerstner <mgerstner@suse.de> for reporting this.
2020-10-02 12:52:08 +02:00