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 const auto tr = [](const char* s) { return QCoreApplication::translate("NTRIPConnectionConfig", s); };
11
12 if (host.isEmpty()) {
13 return tr("No host address");
14 }
15 if (port <= 0 || port > 65535) {
16 return tr("Invalid port");
17 }
18
19 static const QRegularExpression controlChars(QStringLiteral("[\\x00-\\x1f\\x7f]"));
20 if (host.contains(controlChars)) {
21 return tr("Invalid host (contains control characters)");
22 }
23 if (host.contains(QLatin1Char(' '))) {
24 return tr("Invalid host (contains spaces)");
25 }
26 if (mountpoint.contains(controlChars)) {
27 return tr("Invalid mountpoint name (contains control characters)");
28 }
29 if (std::ranges::any_of(mountpoint, [](QChar c) { return c.isSpace(); })) {
30 return tr("Invalid mountpoint name (contains spaces)");
31 }
32 // RFC 7617 forbids colons in Basic-auth usernames.
33 if (username.contains(QLatin1Char(':'))) {
34 return tr("Invalid username (must not contain ':')");
35 }
36
37 return QString();
38}
39
41{
42 if (const QString error = validationError(); !error.isEmpty()) {
43 return error;
44 }
45 if (mountpoint.isEmpty()) {
46 return QCoreApplication::translate("NTRIPConnectionConfig", "Select a mountpoint before connecting");
47 }
48 return {};
49}
50
51QUrl NTRIPConnectionConfig::url(bool withMountpoint) const
52{
53 QUrl url;
54 url.setScheme(useTls ? QStringLiteral("https") : QStringLiteral("http"));
55 url.setHost(host);
56 url.setPort(port);
57 url.setPath(QLatin1Char('/') + (withMountpoint ? mountpoint : QString()));
58 return url;
59}
60
62{
63 return !useTls && (!username.isEmpty() || !password.isEmpty());
64}
65
67{
68 return sendsCredentialsInClear() ? QCoreApplication::translate("NTRIPConnectionConfig",
69 "Credentials are being sent without TLS encryption.")
70 : QString();
71}
Error error
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