QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
NTRIPConfiguration.cc
Go to the documentation of this file.
2
3#include <algorithm>
4
5#include <QtCore/QCoreApplication>
6#include <QtCore/QRegularExpression>
7
9{
10 if (host.isEmpty()) {
11 return tr("No host address");
12 }
13 if (port <= 0 || port > 65535) {
14 return tr("Invalid port");
15 }
16
17 static const QRegularExpression controlChars(QStringLiteral("[\\x00-\\x1f\\x7f]"));
18 if (host.contains(controlChars)) {
19 return tr("Invalid host (contains control characters)");
20 }
21 if (host.contains(QLatin1Char(' '))) {
22 return tr("Invalid host (contains spaces)");
23 }
24 if (mountpoint.contains(controlChars)) {
25 return tr("Invalid mountpoint name (contains control characters)");
26 }
27 if (std::ranges::any_of(mountpoint, [](QChar c) { return c.isSpace(); })) {
28 return tr("Invalid mountpoint name (contains spaces)");
29 }
30 // RFC 7617 forbids colons in Basic-auth usernames.
31 if (username.contains(QLatin1Char(':'))) {
32 return tr("Invalid username (must not contain ':')");
33 }
34
35 return QString();
36}
37
39{
40 if (const QString error = validationError(); !error.isEmpty()) {
41 return error;
42 }
43 if (mountpoint.isEmpty()) {
44 return QCoreApplication::translate("NTRIPConnectionConfig", "Select a mountpoint before connecting");
45 }
46 return {};
47}
48
49QUrl NTRIPConnectionConfig::url(bool withMountpoint) const
50{
51 QUrl url;
52 url.setScheme(useTls ? QStringLiteral("https") : QStringLiteral("http"));
53 url.setHost(host);
54 url.setPort(port);
55 url.setPath(QLatin1Char('/') + (withMountpoint ? mountpoint : QString()));
56 return url;
57}
58
60{
61 return !useTls && (!username.isEmpty() || !password.isEmpty());
62}
63
65{
66 return sendsCredentialsInClear() ? QCoreApplication::translate("NTRIPConnectionConfig",
67 "Credentials are being sent without TLS encryption.")
68 : QString();
69}
QString streamValidationError() const
bool sendsCredentialsInClear() const
Credentials go to the caster without TLS.
QString credentialsInClearWarning() const
The user-visible warning when credentials go to the caster without TLS; empty otherwise.
QUrl url(bool withMountpoint=true) const
The caster's HTTP(S) URL, with the mountpoint as its path when withMountpoint is set,...
QString validationError() const