aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--connection.cpp5
-rw-r--r--connection.h3
-rw-r--r--connectiondata.cpp14
-rw-r--r--connectiondata.h6
-rw-r--r--connectionprivate.cpp29
-rw-r--r--connectionprivate.h4
-rw-r--r--jobs/basejob.cpp11
-rw-r--r--jobs/basejob.h1
8 files changed, 67 insertions, 6 deletions
diff --git a/connection.cpp b/connection.cpp
index 5127dea8..d9802f5f 100644
--- a/connection.cpp
+++ b/connection.cpp
@@ -54,6 +54,11 @@ Connection::~Connection()
delete d;
}
+void Connection::resolveServer(QString domain)
+{
+ d->resolveServer( domain );
+}
+
void Connection::connectToServer(QString user, QString password)
{
PasswordLogin* loginJob = new PasswordLogin(d->data, user, password);
diff --git a/connection.h b/connection.h
index 64d3d077..dc056fd8 100644
--- a/connection.h
+++ b/connection.h
@@ -44,6 +44,7 @@ namespace QMatrixClient
QHash<QString, Room*> roomMap() const;
Q_INVOKABLE virtual bool isConnected();
+ Q_INVOKABLE virtual void resolveServer( QString domain );
Q_INVOKABLE virtual void connectToServer( QString user, QString password );
Q_INVOKABLE virtual void reconnect();
Q_INVOKABLE virtual SyncJob* sync(int timeout=-1);
@@ -61,12 +62,14 @@ namespace QMatrixClient
signals:
void connected();
void reconnected();
+ void resolved();
void syncDone();
void newRoom(Room* room);
void joinedRoom(Room* room);
void loginError(QString error);
void connectionError(QString error);
+ void resolveError(QString error);
//void jobError(BaseJob* job);
protected:
diff --git a/connectiondata.cpp b/connectiondata.cpp
index 374484b0..4a3bd47f 100644
--- a/connectiondata.cpp
+++ b/connectiondata.cpp
@@ -72,6 +72,18 @@ void ConnectionData::setToken(QString token)
d->token = token;
}
+void ConnectionData::setHost(QString host)
+{
+ d->baseUrl.setHost(host);
+ qDebug() << "updated baseUrl to" << d->baseUrl;
+}
+
+void ConnectionData::setPort(int port)
+{
+ d->baseUrl.setPort(port);
+ qDebug() << "updated baseUrl to" << d->baseUrl;
+}
+
QString ConnectionData::lastEvent() const
{
return d->lastEvent;
@@ -80,4 +92,4 @@ QString ConnectionData::lastEvent() const
void ConnectionData::setLastEvent(QString identifier)
{
d->lastEvent = identifier;
-} \ No newline at end of file
+}
diff --git a/connectiondata.h b/connectiondata.h
index e11f54b5..6407780c 100644
--- a/connectiondata.h
+++ b/connectiondata.h
@@ -34,9 +34,11 @@ namespace QMatrixClient
//bool isConnected() const;
QString token() const;
QUrl baseUrl() const;
-
+
QNetworkAccessManager* nam() const;
void setToken( QString token );
+ void setHost( QString host );
+ void setPort( int port );
QString lastEvent() const;
void setLastEvent( QString identifier );
@@ -47,4 +49,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_CONNECTIONDATA_H \ No newline at end of file
+#endif // QMATRIXCLIENT_CONNECTIONDATA_H
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
+}
diff --git a/connectionprivate.h b/connectionprivate.h
index 2aeeaf0b..1fccc759 100644
--- a/connectionprivate.h
+++ b/connectionprivate.h
@@ -43,6 +43,8 @@ namespace QMatrixClient
ConnectionPrivate(Connection* parent);
~ConnectionPrivate();
+ void resolveServer( QString domain );
+
void processState( State* state );
void processRooms( const QList<SyncRoomData>& data );
@@ -64,4 +66,4 @@ namespace QMatrixClient
};
}
-#endif // QMATRIXCLIENT_CONNECTIONPRIVATE_H \ No newline at end of file
+#endif // QMATRIXCLIENT_CONNECTIONPRIVATE_H
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index b7e1b718..86109feb 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -97,6 +97,7 @@ void BaseJob::start()
d->reply = d->connection->nam()->put(req, data.toJson());
break;
}
+ connect( d->reply, &QNetworkReply::sslErrors, this, &BaseJob::sslErrors );
connect( d->reply, &QNetworkReply::finished, this, &BaseJob::gotReply );
QTimer::singleShot( 120*1000, this, SLOT(timeout()) );
// connect( d->reply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
@@ -124,7 +125,7 @@ void BaseJob::gotReply()
{
if( d->reply->error() != QNetworkReply::NoError )
{
- qDebug() << "NetworkError!!!";
+ qDebug() << "NetworkError:" << d->reply->errorString();
fail( NetworkError, d->reply->errorString() );
return;
}
@@ -144,3 +145,11 @@ void BaseJob::timeout()
if( d->reply->isRunning() )
d->reply->abort();
}
+
+void BaseJob::sslErrors(const QList<QSslError>& errors)
+{
+ foreach (const QSslError &error, errors) {
+ qWarning() << "SSL ERROR" << error.errorString();
+ }
+ d->reply->ignoreSslErrors(); // TODO: insecure! should prompt user first
+}
diff --git a/jobs/basejob.h b/jobs/basejob.h
index 88911ca1..95cf4232 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -63,6 +63,7 @@ namespace QMatrixClient
protected slots:
virtual void gotReply();
void timeout();
+ void sslErrors(const QList<QSslError>& errors);
//void networkError(QNetworkReply::NetworkError code);