diff options
Diffstat (limited to 'connectionprivate.cpp')
-rw-r--r-- | connectionprivate.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/connectionprivate.cpp b/connectionprivate.cpp index 90733ed0..50fd1b0c 100644 --- a/connectionprivate.cpp +++ b/connectionprivate.cpp @@ -31,6 +31,7 @@ #include "events/roommemberevent.h" #include <QtCore/QDebug> +#include <QtNetwork/QDnsLookup> using namespace QMatrixClient; @@ -46,6 +47,32 @@ ConnectionPrivate::~ConnectionPrivate() delete data; } +void ConnectionPrivate::resolveServer(QString domain) +{ + // Find the Matrix server for the given domain. + QDnsLookup* dns = new QDnsLookup(); + dns->setType(QDnsLookup::SRV); + dns->setName("_matrix._tcp." + domain); + + connect(dns, &QDnsLookup::finished, [this,dns]() { + // Check the lookup succeeded. + if (dns->error() != QDnsLookup::NoError || + dns->serviceRecords().isEmpty()) { + emit q->resolveError("DNS lookup failed"); + dns->deleteLater(); + return; + } + + // Handle the results. + QDnsServiceRecord record = dns->serviceRecords().first(); + data->setHost(record.target()); + data->setPort(record.port()); + emit q->resolved(); + dns->deleteLater(); + }); + dns->lookup(); +} + void ConnectionPrivate::processState(State* state) { QString roomId = state->event()->roomId(); @@ -175,4 +202,4 @@ void ConnectionPrivate::gotRoomMembers(KJob* job) if( membersJob->error() == BaseJob::NetworkError ) emit q->connectionError( membersJob->errorString() ); } -}
\ No newline at end of file +} |