aboutsummaryrefslogtreecommitdiff
path: root/jobs
diff options
context:
space:
mode:
Diffstat (limited to 'jobs')
-rw-r--r--jobs/basejob.cpp18
-rw-r--r--jobs/converters.h121
-rw-r--r--jobs/generated/banning.cpp2
-rw-r--r--jobs/generated/inviting.cpp2
-rw-r--r--jobs/generated/kicking.cpp2
-rw-r--r--jobs/generated/leaving.cpp2
-rw-r--r--jobs/generated/login.cpp2
-rw-r--r--jobs/generated/logout.cpp2
-rw-r--r--jobs/generated/profile.cpp2
-rw-r--r--jobs/joinroomjob.cpp2
-rw-r--r--jobs/roommessagesjob.cpp6
-rw-r--r--jobs/syncjob.h5
12 files changed, 24 insertions, 142 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 7794337e..2f5c381a 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -81,9 +81,9 @@ inline QDebug operator<<(QDebug dbg, const BaseJob* j)
QDebug QMatrixClient::operator<<(QDebug dbg, const BaseJob::Status& s)
{
- QRegularExpression filter { "(access_token)=[-_A-Za-z0-9]+" };
+ QRegularExpression filter { "(access_token)(=|: )[-_A-Za-z0-9]+" };
return dbg << s.code << ':'
- << QString(s.message).replace(filter, "\1=HIDDEN");
+ << QString(s.message).replace(filter, "\\1 HIDDEN");
}
BaseJob::BaseJob(HttpVerb verb, const QString& name, const QString& endpoint,
@@ -136,14 +136,17 @@ void BaseJob::setRequestData(const BaseJob::Data& data)
void BaseJob::Private::sendRequest()
{
QUrl url = connection->baseUrl();
- url.setPath( url.path() + "/" + apiEndpoint );
- QUrlQuery q = requestQuery;
- if (needsToken)
- q.addQueryItem("access_token", connection->accessToken());
- url.setQuery(q);
+ QString path = url.path();
+ if (!path.endsWith('/') && !apiEndpoint.startsWith('/'))
+ path.push_back('/');
+
+ url.setPath( path + apiEndpoint );
+ url.setQuery(requestQuery);
QNetworkRequest req {url};
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
+ req.setRawHeader(QByteArray("Authorization"),
+ QByteArray("Bearer ") + connection->accessToken());
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
req.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
req.setMaximumRedirectsAllowed(10);
@@ -207,6 +210,7 @@ void BaseJob::gotReply()
BaseJob::Status BaseJob::checkReply(QNetworkReply* reply) const
{
+ qCDebug(d->logCat) << this << "returned from" << reply->url().toDisplayString();
if (reply->error() != QNetworkReply::NoError)
qCDebug(d->logCat) << this << "returned" << reply->error();
switch( reply->error() )
diff --git a/jobs/converters.h b/jobs/converters.h
deleted file mode 100644
index f6e850c6..00000000
--- a/jobs/converters.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/******************************************************************************
-* Copyright (C) 2017 Kitsune Ral <kitsune-ral@users.sf.net>
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation; either
-* version 2.1 of the License, or (at your option) any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this library; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*/
-
-#pragma once
-
-#include <QtCore/QJsonObject>
-#include <QtCore/QJsonArray> // Includes <QtCore/QJsonValue>
-#include <QtCore/QDate>
-
-namespace QMatrixClient
-{
- template <typename T>
- inline QJsonValue toJson(T val)
- {
- return QJsonValue(val);
- }
-
- template <typename T>
- inline QJsonValue toJson(const QVector<T>& vals)
- {
- QJsonArray ar;
- for (const auto& v: vals)
- ar.push_back(toJson(v));
- return ar;
- }
-
- inline QJsonValue toJson(const QStringList& strings)
- {
- return QJsonArray::fromStringList(strings);
- }
-
- template <typename T>
- struct FromJson
- {
- T operator()(QJsonValue jv) const { return static_cast<T>(jv); }
- };
-
- template <typename T>
- inline T fromJson(const QJsonValue& jv)
- {
- return FromJson<T>()(jv);
- }
-
- template <> struct FromJson<bool>
- {
- bool operator()(QJsonValue jv) const { return jv.toBool(); }
- };
-
- template <> struct FromJson<int>
- {
- int operator()(QJsonValue jv) const { return jv.toInt(); }
- };
-
- template <> struct FromJson<double>
- {
- double operator()(QJsonValue jv) const { return jv.toDouble(); }
- };
-
- template <> struct FromJson<qint64>
- {
- qint64 operator()(QJsonValue jv) const { return qint64(jv.toDouble()); }
- };
-
- template <> struct FromJson<QString>
- {
- QString operator()(QJsonValue jv) const { return jv.toString(); }
- };
-
- template <> struct FromJson<QDateTime>
- {
- QDateTime operator()(QJsonValue jv) const
- {
- return QDateTime::fromMSecsSinceEpoch(fromJson<qint64>(jv), Qt::UTC);
- }
- };
-
- template <> struct FromJson<QDate>
- {
- QDate operator()(QJsonValue jv) const
- {
- return fromJson<QDateTime>(jv).date();
- }
- };
-
- template <> struct FromJson<QJsonObject>
- {
- QJsonObject operator()(QJsonValue jv) const { return jv.toObject(); }
- };
-
- template <> struct FromJson<QJsonArray>
- {
- QJsonArray operator()(QJsonValue jv) const { return jv.toArray(); }
- };
-
- template <typename T> struct FromJson<QVector<T>>
- {
- QVector<T> operator()(QJsonValue jv) const
- {
- const auto jsonArray = jv.toArray();
- QVector<T> vect; vect.resize(jsonArray.size());
- std::transform(jsonArray.begin(), jsonArray.end(),
- vect.begin(), FromJson<T>());
- return vect;
- }
- };
-} // namespace QMatrixClient
diff --git a/jobs/generated/banning.cpp b/jobs/generated/banning.cpp
index 7efc2a85..ebb4c96c 100644
--- a/jobs/generated/banning.cpp
+++ b/jobs/generated/banning.cpp
@@ -5,7 +5,7 @@
#include "banning.h"
-#include "jobs/converters.h"
+#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
diff --git a/jobs/generated/inviting.cpp b/jobs/generated/inviting.cpp
index 91760e57..73c73076 100644
--- a/jobs/generated/inviting.cpp
+++ b/jobs/generated/inviting.cpp
@@ -5,7 +5,7 @@
#include "inviting.h"
-#include "jobs/converters.h"
+#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
diff --git a/jobs/generated/kicking.cpp b/jobs/generated/kicking.cpp
index 1a544c39..28d51d05 100644
--- a/jobs/generated/kicking.cpp
+++ b/jobs/generated/kicking.cpp
@@ -5,7 +5,7 @@
#include "kicking.h"
-#include "jobs/converters.h"
+#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
diff --git a/jobs/generated/leaving.cpp b/jobs/generated/leaving.cpp
index a86714ac..392f1ca8 100644
--- a/jobs/generated/leaving.cpp
+++ b/jobs/generated/leaving.cpp
@@ -5,7 +5,7 @@
#include "leaving.h"
-#include "jobs/converters.h"
+#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
diff --git a/jobs/generated/login.cpp b/jobs/generated/login.cpp
index 6e8294e7..0c57c684 100644
--- a/jobs/generated/login.cpp
+++ b/jobs/generated/login.cpp
@@ -5,7 +5,7 @@
#include "login.h"
-#include "jobs/converters.h"
+#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
diff --git a/jobs/generated/logout.cpp b/jobs/generated/logout.cpp
index b807012a..c2480ff9 100644
--- a/jobs/generated/logout.cpp
+++ b/jobs/generated/logout.cpp
@@ -5,7 +5,7 @@
#include "logout.h"
-#include "jobs/converters.h"
+#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
diff --git a/jobs/generated/profile.cpp b/jobs/generated/profile.cpp
index 7ef0577b..f24db15a 100644
--- a/jobs/generated/profile.cpp
+++ b/jobs/generated/profile.cpp
@@ -5,7 +5,7 @@
#include "profile.h"
-#include "jobs/converters.h"
+#include "converters.h"
#include <QtCore/QStringBuilder>
using namespace QMatrixClient;
diff --git a/jobs/joinroomjob.cpp b/jobs/joinroomjob.cpp
index d465dd42..66a75089 100644
--- a/jobs/joinroomjob.cpp
+++ b/jobs/joinroomjob.cpp
@@ -29,7 +29,7 @@ class JoinRoomJob::Private
JoinRoomJob::JoinRoomJob(const QString& roomAlias)
: BaseJob(HttpVerb::Post, "JoinRoomJob",
- QString("_matrix/client/r0/join/%1").arg(roomAlias))
+ QStringLiteral("_matrix/client/r0/join/%1").arg(roomAlias))
, d(new Private)
{
}
diff --git a/jobs/roommessagesjob.cpp b/jobs/roommessagesjob.cpp
index 078c692a..9af1b3a6 100644
--- a/jobs/roommessagesjob.cpp
+++ b/jobs/roommessagesjob.cpp
@@ -30,7 +30,7 @@ class RoomMessagesJob::Private
RoomMessagesJob::RoomMessagesJob(const QString& roomId, const QString& from,
int limit, FetchDirection dir)
: BaseJob(HttpVerb::Get, "RoomMessagesJob",
- QString("/_matrix/client/r0/rooms/%1/messages").arg(roomId),
+ QStringLiteral("/_matrix/client/r0/rooms/%1/messages").arg(roomId),
Query(
{ { "from", from }
, { "dir", dir == FetchDirection::Backward ? "b" : "f" }
@@ -58,8 +58,8 @@ QString RoomMessagesJob::end() const
BaseJob::Status RoomMessagesJob::parseJson(const QJsonDocument& data)
{
- QJsonObject obj = data.object();
- d->events.assign(makeEvents<RoomEvent>(obj.value("chunk").toArray()));
+ const auto obj = data.object();
+ d->events.fromJson(obj, "chunk");
d->end = obj.value("end").toString();
return Success;
}
diff --git a/jobs/syncjob.h b/jobs/syncjob.h
index b1db914d..08bd773e 100644
--- a/jobs/syncjob.h
+++ b/jobs/syncjob.h
@@ -36,11 +36,10 @@ namespace QMatrixClient
explicit Batch(QString k) : jsonKey(std::move(k)) { }
void fromJson(const QJsonObject& roomContents)
{
- this->assign(makeEvents<EventT>(
- roomContents[jsonKey].toObject()["events"].toArray()));
+ EventsBatch<EventT>::fromJson(
+ roomContents[jsonKey].toObject(), "events");
}
-
private:
QString jsonKey;
};