aboutsummaryrefslogtreecommitdiff
path: root/lib/csapi
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-02-09 21:02:03 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-02-09 21:16:10 +0900
commit7337876aac42552da6d926b38d7466cf2e51b7d8 (patch)
tree203013022016192c314ef2abab73fb44d6a0a051 /lib/csapi
parentee1d26586572d4d74105a0713d0237dbc2d183f0 (diff)
downloadlibquotient-7337876aac42552da6d926b38d7466cf2e51b7d8.tar.gz
libquotient-7337876aac42552da6d926b38d7466cf2e51b7d8.zip
csapi: support redirect-after-login (MSC1730)
Diffstat (limited to 'lib/csapi')
-rw-r--r--lib/csapi/definitions/wellknown/full.cpp25
-rw-r--r--lib/csapi/definitions/wellknown/full.h38
-rw-r--r--lib/csapi/login.cpp7
-rw-r--r--lib/csapi/login.h6
-rw-r--r--lib/csapi/wellknown.cpp19
-rw-r--r--lib/csapi/wellknown.h9
6 files changed, 83 insertions, 21 deletions
diff --git a/lib/csapi/definitions/wellknown/full.cpp b/lib/csapi/definitions/wellknown/full.cpp
new file mode 100644
index 00000000..5ecef34f
--- /dev/null
+++ b/lib/csapi/definitions/wellknown/full.cpp
@@ -0,0 +1,25 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#include "full.h"
+
+using namespace QMatrixClient;
+
+void JsonObjectConverter<DiscoveryInformation>::dumpTo(
+ QJsonObject& jo, const DiscoveryInformation& pod)
+{
+ fillJson(jo, pod.additionalProperties);
+ addParam<>(jo, QStringLiteral("m.homeserver"), pod.homeserver);
+ addParam<IfNotEmpty>(jo, QStringLiteral("m.identity_server"), pod.identityServer);
+}
+
+void JsonObjectConverter<DiscoveryInformation>::fillFrom(
+ QJsonObject jo, DiscoveryInformation& result)
+{
+ fromJson(jo.take("m.homeserver"_ls), result.homeserver);
+ fromJson(jo.take("m.identity_server"_ls), result.identityServer);
+
+ fromJson(jo, result.additionalProperties);
+}
+
diff --git a/lib/csapi/definitions/wellknown/full.h b/lib/csapi/definitions/wellknown/full.h
new file mode 100644
index 00000000..d9346acb
--- /dev/null
+++ b/lib/csapi/definitions/wellknown/full.h
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
+ */
+
+#pragma once
+
+#include "converters.h"
+
+#include <QtCore/QJsonObject>
+#include "converters.h"
+#include "csapi/definitions/wellknown/homeserver.h"
+#include "csapi/definitions/wellknown/identity_server.h"
+#include <QtCore/QHash>
+
+namespace QMatrixClient
+{
+ // Data structures
+
+ /// Used by clients to determine the homeserver, identity server, and other
+ /// optional components they should be interacting with.
+ struct DiscoveryInformation
+ {
+ /// Used by clients to determine the homeserver, identity server, and other
+ /// optional components they should be interacting with.
+ HomeserverInformation homeserver;
+ /// Used by clients to determine the homeserver, identity server, and other
+ /// optional components they should be interacting with.
+ Omittable<IdentityServerInformation> identityServer;
+ /// Application-dependent keys using Java package naming convention.
+ QHash<QString, QJsonObject> additionalProperties;
+ };
+ template <> struct JsonObjectConverter<DiscoveryInformation>
+ {
+ static void dumpTo(QJsonObject& jo, const DiscoveryInformation& pod);
+ static void fillFrom(QJsonObject jo, DiscoveryInformation& pod);
+ };
+
+} // namespace QMatrixClient
diff --git a/lib/csapi/login.cpp b/lib/csapi/login.cpp
index ee33dac2..5e369b9a 100644
--- a/lib/csapi/login.cpp
+++ b/lib/csapi/login.cpp
@@ -67,6 +67,7 @@ class LoginJob::Private
QString accessToken;
QString homeServer;
QString deviceId;
+ Omittable<DiscoveryInformation> wellKnown;
};
static const auto LoginJobName = QStringLiteral("LoginJob");
@@ -111,6 +112,11 @@ const QString& LoginJob::deviceId() const
return d->deviceId;
}
+const Omittable<DiscoveryInformation>& LoginJob::wellKnown() const
+{
+ return d->wellKnown;
+}
+
BaseJob::Status LoginJob::parseJson(const QJsonDocument& data)
{
auto json = data.object();
@@ -118,6 +124,7 @@ BaseJob::Status LoginJob::parseJson(const QJsonDocument& data)
fromJson(json.value("access_token"_ls), d->accessToken);
fromJson(json.value("home_server"_ls), d->homeServer);
fromJson(json.value("device_id"_ls), d->deviceId);
+ fromJson(json.value("well_known"_ls), d->wellKnown);
return Success;
}
diff --git a/lib/csapi/login.h b/lib/csapi/login.h
index 957d8881..648316df 100644
--- a/lib/csapi/login.h
+++ b/lib/csapi/login.h
@@ -7,6 +7,7 @@
#include "jobs/basejob.h"
#include <QtCore/QVector>
+#include "csapi/definitions/wellknown/full.h"
#include "csapi/definitions/user_identifier.h"
#include "converters.h"
@@ -118,6 +119,11 @@ namespace QMatrixClient
/// ID of the logged-in device. Will be the same as the
/// corresponding parameter in the request, if one was specified.
const QString& deviceId() const;
+ /// Optional client configuration provided by the server. If present,
+ /// clients SHOULD use the provided object to reconfigure themselves,
+ /// optionally validating the URLs within. This object takes the same
+ /// form as the one returned from .well-known autodiscovery.
+ const Omittable<DiscoveryInformation>& wellKnown() const;
protected:
Status parseJson(const QJsonDocument& data) override;
diff --git a/lib/csapi/wellknown.cpp b/lib/csapi/wellknown.cpp
index 97505830..a6107f86 100644
--- a/lib/csapi/wellknown.cpp
+++ b/lib/csapi/wellknown.cpp
@@ -15,8 +15,7 @@ static const auto basePath = QStringLiteral("/.well-known");
class GetWellknownJob::Private
{
public:
- HomeserverInformation homeserver;
- Omittable<IdentityServerInformation> identityServer;
+ DiscoveryInformation data;
};
QUrl GetWellknownJob::makeRequestUrl(QUrl baseUrl)
@@ -36,24 +35,14 @@ GetWellknownJob::GetWellknownJob()
GetWellknownJob::~GetWellknownJob() = default;
-const HomeserverInformation& GetWellknownJob::homeserver() const
+const DiscoveryInformation& GetWellknownJob::data() const
{
- return d->homeserver;
-}
-
-const Omittable<IdentityServerInformation>& GetWellknownJob::identityServer() const
-{
- return d->identityServer;
+ return d->data;
}
BaseJob::Status GetWellknownJob::parseJson(const QJsonDocument& data)
{
- auto json = data.object();
- if (!json.contains("m.homeserver"_ls))
- return { JsonParseError,
- "The key 'm.homeserver' not found in the response" };
- fromJson(json.value("m.homeserver"_ls), d->homeserver);
- fromJson(json.value("m.identity_server"_ls), d->identityServer);
+ fromJson(data, d->data);
return Success;
}
diff --git a/lib/csapi/wellknown.h b/lib/csapi/wellknown.h
index df4c8c6e..8da9ce9f 100644
--- a/lib/csapi/wellknown.h
+++ b/lib/csapi/wellknown.h
@@ -6,9 +6,8 @@
#include "jobs/basejob.h"
+#include "csapi/definitions/wellknown/full.h"
#include "converters.h"
-#include "csapi/definitions/wellknown/identity_server.h"
-#include "csapi/definitions/wellknown/homeserver.h"
namespace QMatrixClient
{
@@ -41,10 +40,8 @@ namespace QMatrixClient
// Result properties
- /// Information about the homeserver to connect to.
- const HomeserverInformation& homeserver() const;
- /// Optional. Information about the identity server to connect to.
- const Omittable<IdentityServerInformation>& identityServer() const;
+ /// Server discovery information.
+ const DiscoveryInformation& data() const;
protected:
Status parseJson(const QJsonDocument& data) override;