aboutsummaryrefslogtreecommitdiff
path: root/connection.cpp
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-28 16:41:43 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-28 16:41:43 +0900
commitefd37913fdb4223168a0bb0e7897d75be4606d1f (patch)
tree4d3c26979af651e8f8c54b6f2f7cf12781ea9432 /connection.cpp
parent164938cc1900afe94128e83c8c52bf04a8981ded (diff)
downloadlibquotient-efd37913fdb4223168a0bb0e7897d75be4606d1f.tar.gz
libquotient-efd37913fdb4223168a0bb0e7897d75be4606d1f.zip
Don't resolve the homeserver port from a user MXID
Closes #176. The right way (c) of server name resolution will be done in #178 (see also the Google Doc mentioned in it).
Diffstat (limited to 'connection.cpp')
-rw-r--r--connection.cpp24
1 files changed, 11 insertions, 13 deletions
diff --git a/connection.cpp b/connection.cpp
index 06da17e0..7914639e 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -98,12 +98,13 @@ void Connection::resolveServer(const QString& mxidOrDomain)
// Try to parse as an FQID; if there's no @ part, assume it's a domain name.
QRegularExpression parser(
"^(@.+?:)?" // Optional username (allow everything for compatibility)
- "((\\[[^]]+\\]|[^:@]+)" // Either IPv6 address or hostname/IPv4 address
- "(:\\d{1,5})?)$", // Optional port
+ "(\\[[^]]+\\]|[^:@]+)" // Either IPv6 address or hostname/IPv4 address
+ "(:\\d{1,5})?$", // Optional port
QRegularExpression::UseUnicodePropertiesOption); // Because asian digits
auto match = parser.match(mxidOrDomain);
QUrl maybeBaseUrl = QUrl::fromUserInput(match.captured(2));
+ maybeBaseUrl.setScheme("https"); // Instead of the Qt-default "http"
if (!match.hasMatch() || !maybeBaseUrl.isValid())
{
emit resolveError(
@@ -112,16 +113,14 @@ void Connection::resolveServer(const QString& mxidOrDomain)
return;
}
- maybeBaseUrl.setScheme("https"); // Instead of the Qt-default "http"
- if (maybeBaseUrl.port() != -1)
- {
- setHomeserver(maybeBaseUrl);
- emit resolved();
- return;
- }
+ setHomeserver(maybeBaseUrl);
+ emit resolved();
+ return;
+ // FIXME, #178: The below code is incorrect and is no more executed. The
+ // correct server resolution should be done from .well-known/matrix/client
auto domain = maybeBaseUrl.host();
- qCDebug(MAIN) << "Resolving server" << domain;
+ qCDebug(MAIN) << "Finding the server" << domain;
// Check if the Matrix server has a dedicated service record.
QDnsLookup* dns = new QDnsLookup();
dns->setType(QDnsLookup::SRV);
@@ -190,9 +189,8 @@ void Connection::Private::connectWithToken(const QString& user,
userId = user;
data->setToken(accessToken.toLatin1());
data->setDeviceId(deviceId);
- qCDebug(MAIN) << "Using server" << data->baseUrl() << "by user"
- << userId
- << "from device" << deviceId;
+ qCDebug(MAIN) << "Using server" << data->baseUrl().toDisplayString()
+ << "by user" << userId << "from device" << deviceId;
emit q->connected();
}